IO-2051 Mark appointment as arrived from checklist.

This commit is contained in:
Patrick Fic
2022-09-28 11:55:46 -07:00
parent f6b72ab428
commit 1c222db5a3
2 changed files with 108 additions and 74 deletions

View File

@@ -7,7 +7,10 @@ import { connect } from "react-redux";
import { useHistory, useLocation, useParams } from "react-router-dom"; import { useHistory, useLocation, useParams } from "react-router-dom";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { logImEXEvent } from "../../../../firebase/firebase.utils"; import { logImEXEvent } from "../../../../firebase/firebase.utils";
import { MARK_LATEST_APPOINTMENT_AS_ARRIVED } from "../../../../graphql/appointments.queries"; import {
MARK_APPOINTMENT_ARRIVED,
MARK_LATEST_APPOINTMENT_ARRIVED,
} from "../../../../graphql/appointments.queries";
import { UPDATE_JOB } from "../../../../graphql/jobs.queries"; import { UPDATE_JOB } from "../../../../graphql/jobs.queries";
import { import {
selectBodyshop, selectBodyshop,
@@ -41,7 +44,8 @@ export function JobChecklistForm({
const { t } = useTranslation(); const { t } = useTranslation();
const [intakeJob] = useMutation(UPDATE_JOB); const [intakeJob] = useMutation(UPDATE_JOB);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [markAptArrived] = useMutation(MARK_LATEST_APPOINTMENT_AS_ARRIVED); const [markAptArrived] = useMutation(MARK_APPOINTMENT_ARRIVED);
const [markLatestAptArrived] = useMutation(MARK_LATEST_APPOINTMENT_ARRIVED);
const [updateOwner] = useMutation(UPDATE_OWNER); const [updateOwner] = useMutation(UPDATE_OWNER);
const { jobId } = useParams(); const { jobId } = useParams();
@@ -125,6 +129,18 @@ export function JobChecklistForm({
variables: { appointmentId: search.appointmentId }, variables: { appointmentId: search.appointmentId },
}); });
if (!!appUpdate.errors) {
notification["error"]({
message: t("checklist.errors.complete", {
error: JSON.stringify(result.errors),
}),
});
}
} else if (type === "intake" && !search.appointmentId) {
const appUpdate = await markLatestAptArrived({
variables: { jobId: jobId },
});
if (!!appUpdate.errors) { if (!!appUpdate.errors) {
notification["error"]({ notification["error"]({
message: t("checklist.errors.complete", { message: t("checklist.errors.complete", {
@@ -133,6 +149,7 @@ export function JobChecklistForm({
}); });
} }
} }
if (type === "intake" && job.owner && job.owner.id) { if (type === "intake" && job.owner && job.owner.id) {
//Updae Owner Allow to Text //Updae Owner Allow to Text
const updateOwnerResult = await updateOwner({ const updateOwnerResult = await updateOwner({
@@ -175,12 +192,7 @@ export function JobChecklistForm({
}); });
} }
}; };
console.log(job, {
removeFromProduction: true,
actual_completion:
job && job.actual_completion && moment(job.actual_completion),
actual_delivery: job && job.actual_delivery && moment(job.actual_delivery),
});
return ( return (
<Card <Card
title={t("checklist.labels.checklist")} title={t("checklist.labels.checklist")}

View File

@@ -1,77 +1,81 @@
import { gql } from "@apollo/client"; import { gql } from "@apollo/client";
export const QUERY_ALL_ACTIVE_APPOINTMENTS = gql` export const QUERY_ALL_ACTIVE_APPOINTMENTS = gql`
query QUERY_ALL_ACTIVE_APPOINTMENTS( query QUERY_ALL_ACTIVE_APPOINTMENTS(
$start: timestamptz! $start: timestamptz!
$end: timestamptz! $end: timestamptz!
$startd: date! $startd: date!
$endd: date! $endd: date!
) {
employee_vacation(
where: { _or: [{ start: { _gte: $startd } },
{ end: { _lte: $endd } },
{_and:[{start:{_lte: $startd}},{end:{_gte:$endd}}]}] }
) { ) {
id employee_vacation(
start where: {
end _or: [
employee { { start: { _gte: $startd } }
{ end: { _lte: $endd } }
{ _and: [{ start: { _lte: $startd } }, { end: { _gte: $endd } }] }
]
}
) {
id id
last_name start
first_name end
employee {
id
last_name
first_name
}
} }
} appointments(
appointments( where: {
where: { canceled: { _eq: false }
canceled: { _eq: false } end: { _lte: $end }
end: { _lte: $end } start: { _gte: $start }
start: { _gte: $start } }
} ) {
) { start
start
id
end
arrived
title
isintake
block
color
note
job {
alt_transport
ro_number
ownr_ln
ownr_co_nm
ownr_fn
ownr_ph1
ownr_ph2
ownr_ea
clm_total
id id
clm_no end
ins_co_nm arrived
v_model_yr title
v_make_desc isintake
v_model_desc block
labhrs: joblines_aggregate( color
where: { mod_lbr_ty: { _neq: "LAR" }, removed: { _eq: false } } note
) { job {
aggregate { alt_transport
sum { ro_number
mod_lb_hrs ownr_ln
ownr_co_nm
ownr_fn
ownr_ph1
ownr_ph2
ownr_ea
clm_total
id
clm_no
ins_co_nm
v_model_yr
v_make_desc
v_model_desc
labhrs: joblines_aggregate(
where: { mod_lbr_ty: { _neq: "LAR" }, removed: { _eq: false } }
) {
aggregate {
sum {
mod_lb_hrs
}
}
}
larhrs: joblines_aggregate(
where: { mod_lbr_ty: { _eq: "LAR" }, removed: { _eq: false } }
) {
aggregate {
sum {
mod_lb_hrs
}
} }
} }
} }
larhrs: joblines_aggregate(
where: { mod_lbr_ty: { _eq: "LAR" }, removed: { _eq: false } }
) {
aggregate {
sum {
mod_lb_hrs
}
}
}
}
} }
} }
`; `;
@@ -382,8 +386,8 @@ export const QUERY_SCHEDULE_LOAD_DATA = gql`
} }
`; `;
export const MARK_LATEST_APPOINTMENT_AS_ARRIVED = gql` export const MARK_APPOINTMENT_ARRIVED = gql`
mutation MARK_LATEST_APPOINTMENT_AS_ARRIVED($appointmentId: uuid!) { mutation MARK_APPOINTMENT_ARRIVED($appointmentId: uuid!) {
update_appointments( update_appointments(
where: { id: { _eq: $appointmentId } } where: { id: { _eq: $appointmentId } }
_set: { arrived: true } _set: { arrived: true }
@@ -396,3 +400,21 @@ export const MARK_LATEST_APPOINTMENT_AS_ARRIVED = gql`
} }
} }
`; `;
export const MARK_LATEST_APPOINTMENT_ARRIVED = gql`
mutation MARK_LATEST_APPOINTMENT_ARRIVED($jobId: uuid!) {
update_appointments(
where: {
jobid: { _eq: $jobId }
canceled: { _eq: false }
isintake: { _eq: true }
}
_set: { arrived: true }
) {
affected_rows
returning {
id
arrived
}
}
}
`;