UNPKG

lml-main

Version:

This is now a mono repository published into many standalone packages.

63 lines 3.22 kB
"use strict"; 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 cosmoui_1 = require("cosmoui"); const styles = require('./allocation-modals.scss'); const CALLSIGN_FIELD_KEY = 'callsign'; class AllocationModalComponent extends React.Component { constructor() { super(...arguments); this.onSubmit = (formData) => { const { selectedCourierId, allocate, closeModal, currentModal } = this.props; // console.log('SUBMIT ALLOCATION MODAL', state.modalProps.jobRefId, selectedCourierId) allocate('ACTUAL', currentModal.modalProps.jobRefId, selectedCourierId); this.handleClose(); }; this.handleClose = () => { const { closeModal, currentModal } = this.props; closeModal(currentModal.modalType); }; } render() { return (React.createElement(cosmoui_1.Modal, { closeButton: true }, React.createElement(cosmoui_1.Form, { name: constants_1.ALLOCATION_FORM_KEY, onSubmit: this.onSubmit }, React.createElement(cosmoui_1.ModalContent, { className: styles.container }, React.createElement(cosmoui_1.Column, null, React.createElement(cosmoui_1.Row, null, React.createElement(cosmoui_1.Icon, { icon: "Info", className: styles.icon, fill: "primary", size: 32 }), React.createElement(cosmoui_1.Header, { size: "sm" }, "Please enter a Courier Callsign to allocate this job to")), React.createElement(cosmoui_1.TextInput, { name: CALLSIGN_FIELD_KEY, placeholder: "Enter CallSign", autofocus: true, validate: this.props.validateCourier }))), React.createElement(cosmoui_1.ButtonBar, null, React.createElement(cosmoui_1.Button, { id: "job-allocate-popup-ok", type: "submit" }, "ALLOCATE"), React.createElement(cosmoui_1.Button, { id: "job-allocate-popup-cancel", onClick: this.handleClose }, "CANCEL"))))); } } const validateCourier = (state) => (callsign) => { if (!callsign) return ['* required']; 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.ALLOCATION_FORM_KEY, CALLSIGN_FIELD_KEY, null); return { callsign, selectedCourierId: callsign ? cosmo_redux_api_1.getIdByCallsign(state, callsign) : '', validateCourier: validateCourier(state), }; }; const mapActionsToProps = { allocate: actions_1.allocate, }; exports.AllocationModal = react_redux_1.connect(mapStateToProps, mapActionsToProps)(AllocationModalComponent); //# sourceMappingURL=allocation-modal.js.map