lml-main
Version:
This is now a mono repository published into many standalone packages.
59 lines • 3.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const lodash_1 = require("lodash");
const react_redux_1 = require("react-redux");
const cosmo_ui_auth_1 = require("@lml/cosmo-ui-auth");
const constants_1 = require("../../../jobs/constants");
const cosmo_redux_api_1 = require("@lml/cosmo-redux-api");
const cosmoui_1 = require("cosmoui");
const styles = require('./job-number-form.scss');
class JobNumberFormComponent extends cosmoui_1.StylableComponent {
constructor() {
super(...arguments);
// massive hack - 100% julien's fault
// feel free to send him hate mail
this.partners = [
'justeat',
'matches',
'citytrak'
];
this.onSubmit = (formData) => {
// console.log('SUBMIT JOB NUMBER FORM', this.props, formData)
const { partner } = this.props;
this.props.fetchJobsByJobNumber(lodash_1.get(formData, `${constants_1.SEARCH_JOB_NUMBER_INPUT_KEY}.value`, ''), lodash_1.get(formData, `${constants_1.SEARCH_JOB_NUMBER_PARTNER_KEY}.value`, '') || partner, 'jobs,jobStatuses', { type: constants_1.JOB_NUMBER_FORM_KEY });
};
this.renderIcon = () => !this.props.searchValue
? React.createElement(cosmoui_1.Icon, { icon: "Search", size: 16, primary: true, className: styles.inputIcon })
: React.createElement(cosmoui_1.Icon, { icon: "NoCancel", size: 16, onClick: this.destroyForm, primary: true, className: styles.inputIcon });
// todo - remove this function
// this is only here because we are covering for the backend team
// when the backend have implemented permissions correctly
// then there will be no need to pass in the namespace as a query param
this.renderPartnerSelector = () => (React.createElement(cosmo_ui_auth_1.RequireNamespace, { namespace: "*" },
React.createElement(cosmoui_1.Select, { style: { marginLeft: this.margin() }, name: constants_1.SEARCH_JOB_NUMBER_PARTNER_KEY, options: this.partners, value: this.partners[0] })));
this.destroyForm = () => this.props.destroyForm(constants_1.JOB_NUMBER_FORM_KEY);
this.formStyles = () => ({ width: '100%' });
}
render() {
// console.log('RENDER JOB NUMBER FORM', this.props)
return (React.createElement(cosmoui_1.Form, { name: constants_1.JOB_NUMBER_FORM_KEY, onSubmit: this.onSubmit },
React.createElement(cosmoui_1.Row, { justify: "space-between", align: "flex-start", fullWidth: true },
React.createElement(cosmoui_1.Row, null,
React.createElement(cosmoui_1.TextInput, { name: constants_1.SEARCH_JOB_NUMBER_INPUT_KEY, placeholder: 'Search Job By No.', autofocus: true, className: styles.inputWithIcon, required: true }),
this.renderIcon(),
this.renderPartnerSelector()),
React.createElement(cosmoui_1.Row, null,
React.createElement(cosmoui_1.Button, { id: "find-job-search-button", primary: true, type: "submit" }, "Search")))));
}
}
const mapStateToProps = (state, ownProps) => ({
searchValue: cosmoui_1.getFormFieldValue(state, constants_1.JOB_NUMBER_FORM_KEY, constants_1.SEARCH_JOB_NUMBER_INPUT_KEY),
partner: cosmo_ui_auth_1.getPartner(state),
});
const mapDispatchToProps = {
destroyForm: cosmoui_1.destroyForm,
fetchJobsByJobNumber: cosmo_redux_api_1.fetchJobsByJobNumber,
};
exports.JobNumberForm = react_redux_1.connect(mapStateToProps, mapDispatchToProps)(JobNumberFormComponent);
//# sourceMappingURL=job-number-form.js.map