generalized job checklist functionality & created deliver checklist. BOD-376
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { useQuery } from "@apollo/react-hooks";
|
||||
import React, { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import AlertComponent from "../../components/alert/alert.component";
|
||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||
import { QUERY_DELIVER_CHECKLIST } from "../../graphql/bodyshop.queries";
|
||||
import { setBreadcrumbs } from "../../redux/application/application.actions";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import JobchecklistComponent from "../../components/job-checklist/job-checklist.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||
});
|
||||
|
||||
export function JobsDeliverContainer({ bodyshop, setBreadcrumbs }) {
|
||||
const { t } = useTranslation();
|
||||
const { jobId } = useParams();
|
||||
const { loading, error, data } = useQuery(QUERY_DELIVER_CHECKLIST, {
|
||||
variables: { shopId: bodyshop.id, jobId: jobId },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
document.title = t("titles.jobs-deliver");
|
||||
setBreadcrumbs([
|
||||
{ link: "/manage/jobs", label: t("titles.bc.jobs") },
|
||||
{
|
||||
link: `/manage/jobs/${jobId}`,
|
||||
label: t("titles.bc.jobs-detail", {
|
||||
number: (data && data.jobs_by_pk && data.jobs_by_pk.ro_number) || "",
|
||||
}),
|
||||
},
|
||||
{
|
||||
link: `/manage/jobs/${jobId}/deliver`,
|
||||
label: t("titles.bc.jobs-deliver"),
|
||||
},
|
||||
]);
|
||||
}, [t, setBreadcrumbs, jobId, data]);
|
||||
|
||||
if (loading) return <LoadingSpinner />;
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
if (data && !!!data.bodyshops_by_pk.deliverchecklist)
|
||||
return (
|
||||
<AlertComponent message={t("deliver.errors.nochecklist")} type="error" />
|
||||
);
|
||||
return (
|
||||
<RbacWrapper action="jobs:deliver">
|
||||
<div>
|
||||
<JobchecklistComponent
|
||||
type="deliver"
|
||||
checklistConfig={
|
||||
(data && data.bodyshops_by_pk.deliverchecklist) || {}
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</RbacWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(JobsDeliverContainer);
|
||||
Reference in New Issue
Block a user