lml-main
Version:
This is now a mono repository published into many standalone packages.
88 lines • 4.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const react_redux_1 = require("react-redux");
const cosmo_redux_api_1 = require("@lml/cosmo-redux-api");
const actions_1 = require("../../../allocation/actions");
const constants_1 = require("../../../allocation/constants");
const selectors_1 = require("../../../jobs/selectors");
const cosmoui_1 = require("cosmoui");
const styles = require('./allocation-modals.scss');
const CALLSIGN_FIELD_KEY = 'callsignField';
const REASON_FIELD_KEY = 'reasonField';
class DeallocationModalComponent extends React.Component {
constructor() {
super(...arguments);
this.onSubmit = (formData) => {
const { callsign, selectedCourierId, job, allocate } = this.props;
if (callsign) {
allocate('REALLOCATION', job.refId, selectedCourierId);
}
else {
allocate('DEALLOCATION', job.refId, job.currentAllocation.courier.refId);
}
this.handleClose();
};
this.handleClose = () => {
const { closeModal, currentModal } = this.props;
closeModal(currentModal.modalType);
};
}
componentWillMount() {
const { job } = this.props;
if (!job || !job.currentAllocation) {
const msg = `Failed to find valid allocation for job ${job.jobNumber}`;
this.props.notificationError(msg);
this.handleClose();
}
}
render() {
// console.log('RENDER DEALLOCATE MODAL', this.props)
const { job, currentModal } = this.props;
if (!job || !job.currentAllocation)
return null;
return (React.createElement(cosmoui_1.Modal, { closeButton: true },
React.createElement(cosmoui_1.Form, { name: constants_1.REALLOCATION_FORM_KEY, onSubmit: this.onSubmit },
React.createElement(cosmoui_1.ModalContent, { className: styles.container },
React.createElement(cosmoui_1.Row, { align: "flex-start" },
React.createElement(cosmoui_1.Icon, { icon: "Info", className: styles.icon, fill: "primary", size: 32 }),
React.createElement(cosmoui_1.Column, null,
React.createElement(cosmoui_1.Column, { className: styles.messageContainer },
React.createElement("p", { className: styles.text }, "To Deallocate this job Click OK."),
React.createElement("p", { className: styles.primary }, "OR"),
React.createElement("p", { className: styles.text }, "To Reallocate, enter a callsign and click OK.")),
React.createElement(cosmoui_1.TextInput, { name: CALLSIGN_FIELD_KEY, required: false, placeholder: "Enter CallSign (optional)", autofocus: true, validate: this.props.validateCourier })))),
React.createElement(cosmoui_1.ButtonBar, null,
React.createElement(cosmoui_1.Button, { id: "job-deallocate-popup-ok", type: "submit" }, "OK"),
React.createElement(cosmoui_1.Button, { id: "job-deallocate-popup-cancel", onClick: this.handleClose }, "CANCEL")))));
}
}
const validateCourier = (state) => (callsign) => {
// if there's no callsign that's fine
if (!callsign)
return [];
//otherwise it has to be valid
if (callsign.length < 2) {
return ['* Min 2 chars'];
}
const selectedCourierId = cosmo_redux_api_1.getIdByCallsign(state, callsign);
if (!selectedCourierId) {
return ['* Not a valid courier'];
}
return [];
};
const mapStateToProps = (state, ownProps) => {
const callsign = cosmoui_1.getFormFieldValue(state, constants_1.REALLOCATION_FORM_KEY, CALLSIGN_FIELD_KEY, null);
return {
job: ownProps.currentModal.modalProps.job || selectors_1.getActiveJob(state),
callsign: callsign || '',
selectedCourierId: callsign ? cosmo_redux_api_1.getIdByCallsign(state, callsign) : '',
validateCourier: validateCourier(state),
};
};
const mapActionsToProps = {
allocate: actions_1.allocate,
notificationError: cosmoui_1.notificationError,
};
exports.DeallocationModal = react_redux_1.connect(mapStateToProps, mapActionsToProps)(DeallocationModalComponent);
//# sourceMappingURL=deallocation-modal.js.map