bug fixes on intake BOD-114

This commit is contained in:
Patrick Fic
2020-05-13 13:45:06 -07:00
parent c470e0ba18
commit 7aff42537c
5 changed files with 77 additions and 63 deletions

View File

@@ -4,11 +4,14 @@ import CheckboxFormItem from "../job-intake-form-checkbox/job-itnake-form-checkb
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useMutation } from "@apollo/react-hooks"; import { useMutation } from "@apollo/react-hooks";
import { UPDATE_JOB } from "../../../../graphql/jobs.queries"; import { UPDATE_JOB } from "../../../../graphql/jobs.queries";
import { MARK_LATEST_APPOINTMENT_AS_ARRIVED } from "../../../../graphql/appointments.queries";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { selectBodyshop } from "../../../../redux/user/user.selectors"; import { selectBodyshop } from "../../../../redux/user/user.selectors";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import queryString from "query-string";
import { useLocation } from "react-router-dom";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
@@ -20,8 +23,11 @@ const mapDispatchToProps = (dispatch) => ({
export function JobIntakeForm({ formItems, bodyshop }) { export function JobIntakeForm({ formItems, bodyshop }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [intakeJob] = useMutation(UPDATE_JOB); const [intakeJob] = useMutation(UPDATE_JOB);
const [markAptArrived] = useMutation(MARK_LATEST_APPOINTMENT_AS_ARRIVED);
const { jobId } = useParams(); const { jobId } = useParams();
const history = useHistory(); const history = useHistory();
const search = queryString.parse(useLocation().search);
const handleFinish = async (values) => { const handleFinish = async (values) => {
console.log("values", values); console.log("values", values);
@@ -38,6 +44,20 @@ export function JobIntakeForm({ formItems, bodyshop }) {
}, },
}, },
}); });
if (!!search.appointmentId) {
const appUpdate = await markAptArrived({
variables: { appointmentId: search.appointmentId },
});
if (!!appUpdate.errors) {
notification["error"]({
message: t("intake.errors.intake", {
error: JSON.stringify(result.errors),
}),
});
}
}
if (!!!result.errors) { if (!!!result.errors) {
notification["success"]({ message: t("intake.successes.intake") }); notification["success"]({ message: t("intake.successes.intake") });
history.push(`/manage/jobs/${jobId}`); history.push(`/manage/jobs/${jobId}`);

View File

@@ -1,13 +1,18 @@
import React from "react"; import React from "react";
import JobIntakeTemplateList from "./components/job-intake-template-list/job-intake-template-list.component"; import JobIntakeTemplateList from "./components/job-intake-template-list/job-intake-template-list.component";
import JobIntakeForm from "./components/job-intake-form/job-intake-form.component"; import JobIntakeForm from "./components/job-intake-form/job-intake-form.component";
import { Row, Col } from "antd";
export default function JobIntakeComponent({ intakeChecklistConfig }) { export default function JobIntakeComponent({ intakeChecklistConfig }) {
const { form, templates } = intakeChecklistConfig; const { form, templates } = intakeChecklistConfig;
return ( return (
<div> <Row>
<JobIntakeTemplateList templates={templates} /> <Col span={12}>
<JobIntakeForm formItems={form} /> <JobIntakeTemplateList templates={templates} />
</div> </Col>
<Col span={12}>
<JobIntakeForm formItems={form} />
</Col>
</Row>
); );
} }

View File

@@ -56,36 +56,39 @@ export default function ScheduleEventComponent({ event, handleCancel }) {
<Button>{t("appointments.actions.viewjob")}</Button> <Button>{t("appointments.actions.viewjob")}</Button>
</Link> </Link>
) : null} ) : null}
<Button onClick={() => handleCancel(event.id)}> <Button onClick={() => handleCancel(event.id)} disabled={event.arrived}>
{t("appointments.actions.cancel")} {t("appointments.actions.cancel")}
</Button> </Button>
<Button> <Button disabled={event.arrived}>
{ {
//TODO Add reschedule Func. //TODO Add reschedule Func.
} }
{t("appointments.actions.reschedule")} {t("appointments.actions.reschedule")}
</Button> </Button>
{event.isintake ? ( {event.isintake ? (
<Button> <Link
{ to={{
//TODO Add intake func. pathname: `/manage/jobs/${event.job && event.job.id}/intake`,
} search: `?appointmentId=${event.id}`,
{t("appointments.actions.intake")} }}>
</Button> <Button disabled={event.arrived}>
{t("appointments.actions.intake")}
</Button>
</Link>
) : null} ) : null}
</div> </div>
); );
const RegularEvent = event.isintake ? ( const RegularEvent = event.isintake ? (
<div> <div>
<strong>{`${(event.job && event.job.ownr_fn) || ""} ${ <strong style={{ color: event.arrived ? "green" : "" }}>{`${
(event.job && event.job.ownr_ln) || "" (event.job && event.job.ownr_fn) || ""
}`}</strong> } ${(event.job && event.job.ownr_ln) || ""}`}</strong>
<span style={{ margin: 4 }}> <div style={{ margin: 4 }}>
{`${(event.job && event.job.v_model_yr) || ""} ${ {`${(event.job && event.job.v_model_yr) || ""} ${
(event.job && event.job.v_make_desc) || "" (event.job && event.job.v_make_desc) || ""
} ${(event.job && event.job.v_model_desc) || ""}`} } ${(event.job && event.job.v_model_desc) || ""}`}
</span> </div>
</div> </div>
) : ( ) : (
<div> <div>
@@ -94,7 +97,7 @@ export default function ScheduleEventComponent({ event, handleCancel }) {
); );
const Load = ( const Load = (
<div className="load"> <div className='load'>
<Progress percent={77} showInfo={false} /> <Progress percent={77} showInfo={false} />
</div> </div>
); );

View File

@@ -15,6 +15,7 @@ export const QUERY_ALL_ACTIVE_APPOINTMENTS = gql`
start start
id id
end end
arrived
title title
isintake isintake
job { job {
@@ -151,3 +152,14 @@ export const QUERY_SCHEDULE_LOAD_DATA = gql`
} }
} }
`; `;
export const MARK_LATEST_APPOINTMENT_AS_ARRIVED = gql`
mutation MARK_LATEST_APPOINTMENT_AS_ARRIVED($appointmentId: uuid!) {
update_appointments(
where: { id: { _eq: $appointmentId } }
_set: { arrived: true }
) {
affected_rows
}
}
`;

View File

@@ -1,16 +1,15 @@
import React, { useEffect } from "react";
import { useQuery } from "@apollo/react-hooks"; import { useQuery } from "@apollo/react-hooks";
import { QUERY_INTAKE_CHECKLIST } from "../../graphql/bodyshop.queries"; import React, { useEffect } from "react";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { useParams } from "react-router-dom";
import AlertComponent from "../../components/alert/alert.component";
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { setBreadcrumbs } from "../../redux/application/application.actions"; import { connect } from "react-redux";
import { useParams } from "react-router-dom";
import { createStructuredSelector } from "reselect";
import AlertComponent from "../../components/alert/alert.component";
import JobIntakeComponent from "../../components/job-intake/job-intake.component"; import JobIntakeComponent from "../../components/job-intake/job-intake.component";
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
import { QUERY_INTAKE_CHECKLIST } from "../../graphql/bodyshop.queries";
import { setBreadcrumbs } from "../../redux/application/application.actions";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser //currentUser: selectCurrentUser
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
@@ -21,6 +20,7 @@ const mapDispatchToProps = (dispatch) => ({
export function JobsIntakeContainer({ bodyshop, setBreadcrumbs }) { export function JobsIntakeContainer({ bodyshop, setBreadcrumbs }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { loading, error, data } = useQuery(QUERY_INTAKE_CHECKLIST, { const { loading, error, data } = useQuery(QUERY_INTAKE_CHECKLIST, {
variables: { shopId: bodyshop.id }, variables: { shopId: bodyshop.id },
}); });
@@ -43,13 +43,17 @@ export function JobsIntakeContainer({ bodyshop, setBreadcrumbs }) {
if (loading) return <LoadingSpinner />; if (loading) return <LoadingSpinner />;
if (error) return <AlertComponent message={error.message} type='error' />; if (error) return <AlertComponent message={error.message} type='error' />;
// if (data && !!!data.bodyshops_by_pk.intakechecklist) if (data && !!!data.bodyshops_by_pk.intakechecklist)
// return ( return (
// <AlertComponent message={t("intake.errors.nochecklist")} type='error' /> <AlertComponent message={t("intake.errors.nochecklist")} type='error' />
// ); );
return ( return (
<div> <div>
<JobIntakeComponent intakeChecklistConfig={testConfig} /> <JobIntakeComponent
intakeChecklistConfig={
(data && data.bodyshops_by_pk.intakechecklist) || {}
}
/>
</div> </div>
); );
} }
@@ -58,33 +62,3 @@ export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(JobsIntakeContainer); )(JobsIntakeContainer);
const testConfig = {
form: [
{
name: "item1",
label: "Checklist Item 1",
required: true,
type: "checkbox",
},
{
name: "item2",
label: "Checklist Item 2",
required: true,
type: "checkbox",
},
{
name: "item3",
label: "Checklist Item 3",
required: true,
type: "checkbox",
},
{
name: "item4",
label: "Checklist Item 4",
required: true,
type: "checkbox",
},
],
templates: ["estimate_detail", "estimate_detail2"],
};