diff --git a/client/src/components/form-date-time-picker/form-date-time-picker.component.jsx b/client/src/components/form-date-time-picker/form-date-time-picker.component.jsx index 453a935ff..0add659d9 100644 --- a/client/src/components/form-date-time-picker/form-date-time-picker.component.jsx +++ b/client/src/components/form-date-time-picker/form-date-time-picker.component.jsx @@ -1,6 +1,6 @@ import { DatePicker, Space, TimePicker } from "antd"; import PropTypes from "prop-types"; -import React, { useCallback, useState } from "react"; +import { useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; @@ -94,7 +94,24 @@ const DateTimePicker = ({ showTime={false} format="MM/DD/YYYY" value={value ? dayjs(value) : null} - onChange={handleChange} + onChange={(dateValue) => { + if (dateValue) { + // When date changes, preserve the existing time if it exists + if (value && dayjs(value).isValid()) { + const existingTime = dayjs(value); + const newDateTime = dayjs(dateValue) + .hour(existingTime.hour()) + .minute(existingTime.minute()) + .second(existingTime.second()); + handleChange(newDateTime); + } else { + // If no existing time, just set the date without time + handleChange(dateValue); + } + } else { + handleChange(dateValue); + } + }} placeholder={t("general.labels.date")} onBlur={handleBlur} disabledDate={handleDisabledDate} @@ -105,13 +122,25 @@ const DateTimePicker = ({ { - handleChange(value); - onBlur(); + onChange={(timeValue) => { + if (timeValue) { + // When time changes, combine it with the existing date + const existingDate = dayjs(value); + const newDateTime = existingDate + .hour(timeValue.hour()) + .minute(timeValue.minute()) + .second(0); + handleChange(newDateTime); + } else { + // If time is cleared, just update with null time but keep date + handleChange(timeValue); + } + if (onBlur) onBlur(); }} placeholder={t("general.labels.time")} {...restProps} diff --git a/client/src/components/job-at-change/schedule-event.component.jsx b/client/src/components/job-at-change/schedule-event.component.jsx index 6438308da..9bdacfe26 100644 --- a/client/src/components/job-at-change/schedule-event.component.jsx +++ b/client/src/components/job-at-change/schedule-event.component.jsx @@ -385,7 +385,9 @@ export function ScheduleEventComponent({ previousEvent: event.id, color: event.color, alt_transport: event.job && event.job.alt_transport, - note: event.note + note: event.note, + scheduled_in: event.job && event.job.scheduled_in, + scheduled_completion: event.job && event.job.scheduled_completion } }); }} diff --git a/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx b/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx index ec1ec32b6..2dc1c18e6 100644 --- a/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx +++ b/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx @@ -673,7 +673,9 @@ export function JobsDetailHeaderActions({ context: { jobId: job.id, job: job, - alt_transport: job.alt_transport + alt_transport: job.alt_transport, + scheduled_in: job.scheduled_in, + scheduled_completion: job.scheduled_completion } }); } @@ -1090,11 +1092,7 @@ export function JobsDetailHeaderActions({ {t("menus.jobsactions.deletejob")} ) : ( - e.stopPropagation()} - showCancel={false} - > + e.stopPropagation()} showCancel={false}> {t("menus.jobsactions.deletejob")} ) 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 23ff4340d..18c5a3cec 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 @@ -1,10 +1,10 @@ import { useMutation, useQuery } from "@apollo/client"; import { Form, Modal } from "antd"; -import dayjs from "../../utils/day"; -import React, { useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; +import { useNotification } from "../../contexts/Notifications/notificationContext.jsx"; import { logImEXEvent } from "../../firebase/firebase.utils"; import { CANCEL_APPOINTMENT_BY_ID, @@ -19,9 +19,9 @@ import { selectSchedule } from "../../redux/modals/modals.selectors"; import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors"; import AuditTrailMapping from "../../utils/AuditTrailMappings"; import { DateTimeFormat } from "../../utils/DateFormatter"; +import dayjs from "../../utils/day"; import { TemplateList } from "../../utils/TemplateConstants"; import ScheduleJobModalComponent from "./schedule-job-modal.component"; -import { useNotification } from "../../contexts/Notifications/notificationContext.jsx"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -72,7 +72,7 @@ export function ScheduleJobModalContainer({ variables: { jobid: jobId }, fetchPolicy: "network-only", nextFetchPolicy: "network-only", - skip: !open || !!!jobId + skip: !open || !jobId }); useEffect(() => { @@ -93,12 +93,12 @@ export function ScheduleJobModalContainer({ logImEXEvent("schedule_new_appointment"); setLoading(true); - if (!!previousEvent) { + if (previousEvent) { const cancelAppt = await cancelAppointment({ variables: { appid: previousEvent } }); - if (!!cancelAppt.errors) { + if (cancelAppt.errors) { notification["error"]({ message: t("appointments.errors.canceling", { message: JSON.stringify(cancelAppt.errors) @@ -146,7 +146,7 @@ export function ScheduleJobModalContainer({ }); } - if (!!appt.errors) { + if (appt.errors) { notification["error"]({ message: t("appointments.errors.saving", { message: JSON.stringify(appt.errors) @@ -172,7 +172,7 @@ export function ScheduleJobModalContainer({ } }); - if (!!jobUpdate.errors) { + if (jobUpdate.errors) { notification["error"]({ message: t("appointments.errors.saving", { message: JSON.stringify(jobUpdate.errors) @@ -222,9 +222,9 @@ export function ScheduleJobModalContainer({ initialValues={{ notifyCustomer: !!(job && job.ownr_ea), email: (job && job.ownr_ea) || "", - start: null, // smartDates: [], - scheduled_completion: null, + start: context.scheduled_in, + scheduled_completion: context.scheduled_completion , color: context.color, alt_transport: context.alt_transport, note: context.note diff --git a/client/src/graphql/appointments.queries.js b/client/src/graphql/appointments.queries.js index 863e9ce8b..c13c6a374 100644 --- a/client/src/graphql/appointments.queries.js +++ b/client/src/graphql/appointments.queries.js @@ -31,6 +31,8 @@ export const QUERY_ALL_ACTIVE_APPOINTMENTS = gql` color note job { + scheduled_in + scheduled_completion alt_transport ro_number ownr_ln