From acdc17e91b9360dfe6b55fd9457f499d645bff3c Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 6 Feb 2020 16:33:40 -0800 Subject: [PATCH] Change status on scheduling. --- .../jobs-detail-header.component.jsx | 4 +- .../schedule-job-modal.component.jsx | 88 ++++++++++--------- .../schedule-job-modal.container.jsx | 49 ++++++++--- .../jobs-detail.page.component.jsx | 1 + .../jobs-detail.page.container.jsx | 17 +++- client/src/translations/en_us/common.json | 2 +- client/src/translations/es/common.json | 2 +- client/src/translations/fr/common.json | 2 +- 8 files changed, 103 insertions(+), 62 deletions(-) diff --git a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx index aeae31c8b..8a4760732 100644 --- a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx +++ b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx @@ -78,9 +78,7 @@ export default connect( const statusmenu = ( { - updateJobStatus({ - variables: { jobId: job.id, status: e.key } - }).then(r => refetch()); + updateJobStatus(e.key); }} > {bodyshop.md_ro_statuses.statuses.map(item => ( diff --git a/client/src/components/schedule-job-modal/schedule-job-modal.component.jsx b/client/src/components/schedule-job-modal/schedule-job-modal.component.jsx index 22bfbb84b..0cb4633e6 100644 --- a/client/src/components/schedule-job-modal/schedule-job-modal.component.jsx +++ b/client/src/components/schedule-job-modal/schedule-job-modal.component.jsx @@ -22,49 +22,51 @@ export default function ScheduleJobModalComponent({ destroyOnClose={true} okButtonProps={{ disabled: appData.start ? false : true }} > - - - - Automatic Job Selection. - - - - - Manual Job Selection Scheduled Time - { - setAppData({ ...appData, start: e }); - }} - /> - { - setAppData({ ...appData, start: e }); - }} - /> - - - - - - - - { - //TODO: Build out notifications. - } - - setFormData({ ...formData, notifyCustomer: e.target.checked }) - } - > - {t("jobs.labels.appointmentconfirmation")} - + + + + + Automatic Job Selection. + + + + Manual Job Selection Scheduled Time + { + setAppData({ ...appData, start: e }); + }} + /> + { + setAppData({ ...appData, start: e }); + }} + /> + + + + + { + //TODO: Build out notifications. + } + + setFormData({ ...formData, notifyCustomer: e.target.checked }) + } + > + {t("jobs.labels.appointmentconfirmation")} + + + + + + ); } diff --git a/client/src/components/schedule-job-modal/schedule-job-modal.container.jsx b/client/src/components/schedule-job-modal/schedule-job-modal.container.jsx index f018ea806..a3780e621 100644 --- a/client/src/components/schedule-job-modal/schedule-job-modal.container.jsx +++ b/client/src/components/schedule-job-modal/schedule-job-modal.container.jsx @@ -8,17 +8,39 @@ import { import moment from "moment"; import { notification } from "antd"; import { useTranslation } from "react-i18next"; -export default function ScheduleJobModalContainer({ +import { UPDATE_JOB_STATUS } from "../../graphql/jobs.queries"; + +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { selectBodyshop } from "../../redux/user/user.selectors"; + +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop +}); + +export default connect( + mapStateToProps, + null +)(function ScheduleJobModalContainer({ scheduleModalState, - jobId + jobId, + bodyshop, + refetch }) { const existingAppointments = useQuery(QUERY_APPOINTMENTS_BY_JOBID, { variables: { jobid: jobId }, - fetchPolicy: "network-only" + fetchPolicy: "network-only", + skip: !jobId }); const [scheduleModalVisible, setscheduleModalVisible] = scheduleModalState; const [appData, setAppData] = useState({ jobid: jobId, start: null }); const [insertAppointment] = useMutation(INSERT_APPOINTMENT); + const [updateJobStatus] = useMutation(UPDATE_JOB_STATUS, { + variables: { + jobId: jobId, + status: bodyshop.md_ro_statuses.default_scheduled + } + }); const [formData, setFormData] = useState({ notifyCustomer: false }); const { t } = useTranslation(); @@ -40,15 +62,18 @@ export default function ScheduleJobModalContainer({ } }) .then(r => { - notification["success"]({ - message: t("appointments.successes.created") - }); + updateJobStatus().then(r => { + notification["success"]({ + message: t("appointments.successes.created") + }); - if (formData.notifyCustomer) { - //TODO: Implement customer reminder on scheduling. - alert("Chosed to notify the customer somehow!"); - } - setscheduleModalVisible(false); + if (formData.notifyCustomer) { + //TODO: Implement customer reminder on scheduling. + alert("Chosed to notify the customer somehow!"); + } + setscheduleModalVisible(false); + if (refetch) refetch(); + }); }) .catch(error => { notification["error"]({ @@ -60,4 +85,4 @@ export default function ScheduleJobModalContainer({ }} /> ); -} +}); diff --git a/client/src/pages/jobs-detail/jobs-detail.page.component.jsx b/client/src/pages/jobs-detail/jobs-detail.page.component.jsx index 1da4d55ff..f64230b64 100644 --- a/client/src/pages/jobs-detail/jobs-detail.page.component.jsx +++ b/client/src/pages/jobs-detail/jobs-detail.page.component.jsx @@ -47,6 +47,7 @@ export default function JobsDetailPage({
diff --git a/client/src/pages/jobs-detail/jobs-detail.page.container.jsx b/client/src/pages/jobs-detail/jobs-detail.page.container.jsx index ed068f20a..0a5319ff6 100644 --- a/client/src/pages/jobs-detail/jobs-detail.page.container.jsx +++ b/client/src/pages/jobs-detail/jobs-detail.page.container.jsx @@ -25,7 +25,22 @@ function JobsDetailPageContainer({ match, form }) { }); const [mutationUpdateJob] = useMutation(UPDATE_JOB); const [mutationConvertJob] = useMutation(CONVERT_JOB_TO_RO); - const [updateJobStatus] = useMutation(UPDATE_JOB_STATUS); + const [mutationUpdateJobstatus] = useMutation(UPDATE_JOB_STATUS); + + const updateJobStatus = status => { + mutationUpdateJobstatus({ + variables: { jobId: jobId, status: status } + }) + .then(r => { + notification["success"]({ message: t("jobs.successes.save") }); + refetch(); + }) + .catch(error => { + //TODO Error handling. + console.log("error", error); + }); + }; + useEffect(() => { document.title = loading ? t("titles.app") diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 5a107a03a..85bf5e6ca 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -234,7 +234,7 @@ "converted": "Job converted successfully.", "created": "Job created successfully. Click to view.", "deleted": "Job deleted successfully.", - "save": "Record Saved", + "save": "Job saved successfully.", "savetitle": "Record saved successfully." } }, diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index ab20932a9..38f891c71 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -234,7 +234,7 @@ "converted": "Trabajo convertido con éxito.", "created": "Trabajo creado con éxito. Click para ver.", "deleted": "Trabajo eliminado con éxito.", - "save": "Registro guardado", + "save": "Trabajo guardado con éxito.", "savetitle": "Registro guardado con éxito." } }, diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index b47c17380..513006861 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -234,7 +234,7 @@ "converted": "Travail converti avec succès.", "created": "Le travail a été créé avec succès. Clique pour voir.", "deleted": "Le travail a bien été supprimé.", - "save": "Enregistrement enregistré", + "save": "Le travail a été enregistré avec succès.", "savetitle": "Enregistrement enregistré avec succès." } },