import React, {Component} from 'react'; import {connect} from 'react-redux'; import moment from 'moment'; import {Container, Row, Col} from 'reactstrap'; import TermsContainer from '../../terms/TermsContainer.jsx'; import {orderTexts} from '../../../constants/ordersConstants'; class OrderInfo extends Component { constructor(props){ super(props); this.state = { acceptedDate: {}, proposedDate: {}, isPreliminaryInstallationDate: true }; } componentDidMount() { this.setInstallationData(this.props); } componentWillReceiveProps(nextProps) { this.setInstallationData(nextProps); } setInstallationData(props) { const acceptedDate = {}; const proposedDate = {}; const idOrder = props.orderDetails.id; const {isInstallationInPackage} = props.installationData; const {confirmationDates, areAllShippingDatesConfirmed} = props; const isPreliminaryInstallationDate = areAllShippingDatesConfirmed && idOrder in areAllShippingDatesConfirmed ? !areAllShippingDatesConfirmed[idOrder] : true; const isInstallationInOrder = Object.keys(isInstallationInPackage).some(idOrderPackage => {return isInstallationInPackage[idOrderPackage] === true;}); props.orderDetails.packages.forEach(orderPackage => { const idOrderPackagePair = idOrder + '-' + orderPackage.idPackage; if(confirmationDates && confirmationDates[idOrderPackagePair]) { const packageDates = confirmationDates[idOrderPackagePair]; const accepted = Object.keys(packageDates).find(installDate => {return packageDates[installDate].lastStatus === 'accepted'}); acceptedDate[idOrderPackagePair] = accepted ? moment(accepted).format('Do MMM, YYYY') : ''; const proposed = Object.keys(packageDates).find(installDate => {return packageDates[installDate].lastStatus === 'proposed'}); proposedDate[idOrderPackagePair] = proposed ? moment(proposed).format('Do MMM, YYYY') : ''; } }); this.setState({acceptedDate, proposedDate, isPreliminaryInstallationDate, isInstallationInOrder}); } render() { const {totalPrice, installationData} = this.props; const {acceptedDate, proposedDate, isPreliminaryInstallationDate, isInstallationInOrder} = this.state; const orderPackages = installationData.packages; const isInstallationInPackage = installationData.isInstallationInPackage; const orderInfo = this.props.orderInfo; return (
{orderTexts.labels.ORDER_DATE}:
{orderInfo.dateCreated}
{orderTexts.labels.SOLD_BY}:
{orderInfo.commercialLead.name}
{orderTexts.labels.BILLING_FIRST_NAME}:
{orderInfo.billing.firstName || '-'}
{orderTexts.labels.BILLING_LAST_NAME}:
{orderInfo.billing.lastName || '-'}
{orderTexts.labels.BILLING_MAIL}:
{orderInfo.billing.email || '-'}
{orderTexts.labels.BILLING_ADDRESS}:
{orderInfo.billing.address || '-'}
{orderTexts.labels.REFERENCE}:
{orderInfo.reference || '-'}
{orderTexts.labels.BID}:
{orderInfo.tender || '-'}
{ isInstallationInOrder &&
{ isPreliminaryInstallationDate ?
{orderTexts.labels.PRELIMINARY_INSTALLATION_DATE_LABEL}:
:
{orderTexts.labels.INSTALLATION_DATE}:
}
{ orderPackages && orderPackages.map(orderPackage =>
{ isInstallationInPackage[orderPackage.idOrderPackagePair] &&
{ orderPackages.length > 1 && {orderPackage.packageName}: } { acceptedDate && acceptedDate[orderPackage.idOrderPackagePair] ? acceptedDate[orderPackage.idOrderPackagePair] : proposedDate && proposedDate[orderPackage.idOrderPackagePair] ? proposedDate[orderPackage.idOrderPackagePair] : orderTexts.labels.NOT_SET }
}
) }
}
{orderTexts.labels.TOTAL_DELVIERY_PRICE}:
{totalPrice.fixedPrice.toLocaleString()} {totalPrice.currency} { totalPrice.recurrentPrice > 0 &&
{orderTexts.labels.TOTAL_RECURRENT_PRICE}:
{totalPrice.recurrentPrice.toLocaleString() + ' ' + totalPrice.currency}
}
{orderTexts.labels.PROJECT}:
{orderInfo.projectName || '-'}
); } } const mapStateToProps = (state) => ({ orderInfo: state.processReducer.orderInfo, confirmationDates: state.processReducer.confirmationDates, areAllShippingDatesConfirmed: state.processReducer.areAllShippingDatesConfirmed }); export default connect(mapStateToProps)(OrderInfo);