I trying to get data from API and it's work fine but when no data or one data is different when have 2 and higher data.
I trying to use map method but have a undefined error.
I need to display data from API in three way:
- when no data to display
- when have a data that does not exist array
- when have array
This is my code :
class ForsatView extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [
{
id: this.props.auth.FormInfoList.FormInfo.CrmId,
name: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[2],
repairsReport: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[4],
serialNumber: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[8],
model: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[17],
face: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[7],
situation: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[1],
fistly: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[0],
transport: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[16],
reciveDate: this.props.auth.FormInfoList.FormInfo.ExtendedProperties.BaseCrmObjectExtendedPropertyInfo[15],
},
],
}
}
componentDidMount() {
store.dispatch(allForsat())
}
static propTypes = {
isAuthenticated: PropTypes.bool,
auth: PropTypes.object.isRequired,
}
render() {
return (
<Container>
<div className="panel-content">
{this.state ? <div className="mt-5">No service</div>
:
<div className="mt-4 tab-profile-collaps text-right">
{this.state.data.map((details, index) =>
<Collapsible key={index}
trigger={details.name.Value}>
<div className="row">
<div className={"col-lg-6 col-12"}>
<div className="forsat-detial-wrapper">
<div className={"title-tech-advice"}>
<h5>
Report
</h5>
<p>
{details.name.Value}
</p>
</div>
</div>
</div>
<div className={"col-lg-6 col-12"}>
<div className="forsat-detial-wrapper">
<div className="forsat-detial-wrapper-boxes">
<p>Date</p><span
className="d-flex">{details.name.Value}</span>
<p className="mt-3">Nameر</p><span
className="d-flex">{details.name.Value}</span>
<p className="mt-3">SerialNymber</p><span
className="d-flex">{details.name.Value}</span>
<p className="mt-3">Model</p><span
className="d-flex">{details.name.Value}</span>
<p className="mt-3">Details</p><span
className="d-flex">{details.name.Value}</span>
</div>
</div>
</div>
</div>
</Collapsible>
)}
</div>
}
</div>
</Container>
);
}
}
export default withRouter(ForsatView)