UNPKG

lml-main

Version:

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

56 lines 4.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const React = require("react"); const lodash_1 = require("lodash"); const moment = require("moment"); const ts_utils_1 = require("@lml/ts-utils"); const cosmo_redux_api_1 = require("@lml/cosmo-redux-api"); const cosmoui_1 = require("cosmoui"); class StopForm extends React.Component { render() { const { stop, stopName, stopTitle, disabled, } = this.props; // we have to reformat the address from the old format to the new one // before we can use it as the 'current' value of the input field const address = cosmo_redux_api_1.formatAddressOldToNew(stop.location); const addressInputProps = {}; // sometimes the latlong is randomly missing from the address const { latitude, longitude } = address.position.coordinates; // if that's the case then the address input props // won't have a current value if (latitude && longitude) { addressInputProps.current = address; } const earliestTime = this.props.earliestTime || lodash_1.get(stop, 'stopTime.earliestTime', undefined); const latestTime = this.props.latestTime || lodash_1.get(stop, 'stopTime.latestTime', undefined); const phone = lodash_1.get(stop, 'contact.phone') || lodash_1.get(stop, 'contact.mobile', ''); const spacedColumnStyle = { flex: '1', marginRight: stopName === 'collect' ? '1em' : '0', }; return (React.createElement(cosmoui_1.Column, { style: spacedColumnStyle }, React.createElement(cosmoui_1.Header, { primary: true, size: "sm" }, stopTitle), React.createElement(cosmoui_1.Row, { fullWidth: true }, React.createElement(cosmoui_1.FormGroup, { label: "Company name" }, React.createElement(cosmoui_1.TextInput, { name: `${stopName}CompanyName`, value: lodash_1.get(stop, 'metadata.company', ''), disabled: disabled, required: false })), React.createElement(cosmoui_1.FormGroup, { label: "Person name" }, React.createElement(cosmoui_1.TextInput, { name: `${stopName}Name`, value: lodash_1.get(stop, 'contact.name', ''), disabled: disabled, required: false }))), React.createElement(cosmoui_1.FormGroup, { label: "Address" }, React.createElement(cosmoui_1.AddressInput, Object.assign({ name: `${stopName}Address`, placeholder: `${stopName} address`, disabled: disabled }, addressInputProps))), React.createElement(cosmoui_1.Row, { fullWidth: true }, React.createElement(cosmoui_1.FormGroup, { label: `${ts_utils_1.ucfirst(stopName)} between` }, React.createElement(cosmoui_1.Row, null, React.createElement(cosmoui_1.TimeInput, { name: `${stopName}EarliestTime`, value: moment.utc(earliestTime).format(ts_utils_1.TIME_FILTER_FORMAT), disabled: disabled, saveAsUtc: true }), React.createElement(cosmoui_1.TimeInput, { name: `${stopName}LatestTime`, value: moment.utc(latestTime).format(ts_utils_1.TIME_FILTER_FORMAT), disabled: disabled, saveAsUtc: true }))), React.createElement(cosmoui_1.FormGroup, { label: `${ts_utils_1.ucfirst(stopName)} date` }, React.createElement(cosmoui_1.DateInput, { name: `${stopName}Date`, value: moment.utc(earliestTime).format(ts_utils_1.DATE_FORMAT_API), disabled: disabled, saveAsUtc: true }))), React.createElement(cosmoui_1.Row, { fullWidth: true }, React.createElement(cosmoui_1.FormGroup, { label: "Contact number" }, React.createElement(cosmoui_1.PhoneInput, { name: `${stopName}Phone`, disabled: disabled, value: phone, required: false }))), React.createElement(cosmoui_1.FormGroup, { label: "Useful tips" }, React.createElement(cosmoui_1.TextInput, { name: `${stopName}Instructions`, value: lodash_1.get(stop, 'instructions', ''), disabled: disabled, required: false })))); } } exports.StopForm = StopForm; //# sourceMappingURL=stop-form.js.map