diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index c4ef6e2fa..e3ebd5530 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -43102,6 +43102,27 @@ + + shiftalreadyclockedon + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + diff --git a/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx b/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx index c2180ee8a..3234039f9 100644 --- a/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx +++ b/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx @@ -27,6 +27,7 @@ export function TimeTicektShiftContainer({ technician, currentUser, isTechConsole, + checkIfAlreadyClocked, }) { const [form] = Form.useForm(); const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET); @@ -43,36 +44,47 @@ export function TimeTicektShiftContainer({ const handleFinish = async (values) => { setLoading(true); - const theTime = moment((await axios.post("/utils/time")).data); - const result = await insertTimeTicket({ - variables: { - timeTicketInput: [ - { - bodyshopid: bodyshop.id, - employeeid: isTechConsole ? technician.id : employeeId, - cost_center: "timetickets.labels.shift", - clockon: theTime, - date: theTime, - memo: values.memo, - }, - ], - }, - awaitRefetchQueries: true, - refetchQueries: ["QUERY_ACTIVE_SHIFT_TIME_TICKETS"], - }); + const alreadyClocked = await checkIfAlreadyClocked(); - if (!!result.errors) { + if (alreadyClocked) { + //Show the error. notification["error"]({ - message: t("timetickets.errors.clockingin", { - message: JSON.stringify(result.errors), - }), + message: t("timetickets.errors.shiftalreadyclockedon"), }); } else { - notification["success"]({ - message: t("timetickets.successes.clockedin"), + const theTime = moment((await axios.post("/utils/time")).data); + + const result = await insertTimeTicket({ + variables: { + timeTicketInput: [ + { + bodyshopid: bodyshop.id, + employeeid: isTechConsole ? technician.id : employeeId, + cost_center: "timetickets.labels.shift", + clockon: theTime, + date: theTime, + memo: values.memo, + }, + ], + }, + awaitRefetchQueries: true, + refetchQueries: ["QUERY_ACTIVE_SHIFT_TIME_TICKETS"], }); + + if (!!result.errors) { + notification["error"]({ + message: t("timetickets.errors.clockingin", { + message: JSON.stringify(result.errors), + }), + }); + } else { + notification["success"]({ + message: t("timetickets.successes.clockedin"), + }); + } } + setLoading(false); }; diff --git a/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx b/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx index a91dd4004..9f0fec612 100644 --- a/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx +++ b/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx @@ -64,6 +64,12 @@ export function TimeTicketShiftContainer({ ); + const checkIfAlreadyClocked = async () => { + const { data } = await refetch(); + + return data.timetickets.length > 0; + }; + return (
{data.timetickets.length > 0 ? ( @@ -72,7 +78,10 @@ export function TimeTicketShiftContainer({ refetch={refetch} /> ) : ( - + )}
); diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index fb0b5535c..f4c464986 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2558,7 +2558,8 @@ "creating": "Error creating time ticket. {{message}}", "deleting": "Error deleting time ticket. {{message}}", "noemployeeforuser": "Unable to use Shift Clock", - "noemployeeforuser_sub": "An employee record has not been created for this user. Please create one before using the shift clock. " + "noemployeeforuser_sub": "An employee record has not been created for this user. Please create one before using the shift clock. ", + "shiftalreadyclockedon": "You are already clocked onto a shift. Unable to create shift entry." }, "fields": { "actualhrs": "Actual Hours", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 9f93cc0e8..1ab9f658c 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -2558,7 +2558,8 @@ "creating": "", "deleting": "", "noemployeeforuser": "", - "noemployeeforuser_sub": "" + "noemployeeforuser_sub": "", + "shiftalreadyclockedon": "" }, "fields": { "actualhrs": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 35cec2c41..ffe4f8505 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -2558,7 +2558,8 @@ "creating": "", "deleting": "", "noemployeeforuser": "", - "noemployeeforuser_sub": "" + "noemployeeforuser_sub": "", + "shiftalreadyclockedon": "" }, "fields": { "actualhrs": "",