IO-2543 Move queries to jobs.queries.js and correct layout

This commit is contained in:
Allan Carr
2024-01-24 18:37:41 -08:00
parent 36dd97394f
commit eb8519dc1d
6 changed files with 230 additions and 187 deletions

View File

@@ -53,12 +53,14 @@ export function JobsAdminStatus({ insertAuditTrail, bodyshop, job }) {
); );
return ( return (
<Dropdown overlay={statusmenu} trigger={["click"]} key="changestatus"> <>
<Button shape="round"> <Dropdown overlay={statusmenu} trigger={["click"]} key="changestatus">
<span>{job.status}</span> <Button shape="round">
<span>{job.status}</span>
<DownCircleFilled /> <DownCircleFilled />
</Button> </Button>
</Dropdown> </Dropdown>
</>
); );
} }

View File

@@ -1,34 +1,18 @@
import { useMutation } from "@apollo/client"; import { useMutation } from "@apollo/client";
import { Button, notification } from "antd"; import { Button, Space, notification } from "antd";
import { gql } from "@apollo/client";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import {
DELETE_DELIVERY_CHECKLIST,
DELETE_INTAKE_CHECKLIST,
} from "../../graphql/jobs.queries";
export default function JobAdminDeleteIntake({ job }) { export default function JobAdminDeleteIntake({ job }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [deleteIntake] = useMutation(gql`
mutation DELETE_INTAKE($jobId: uuid!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { intakechecklist: null }
) {
id
intakechecklist
}
}
`);
const [DELETE_DELIVERY] = useMutation(gql` const [deleteIntake] = useMutation(DELETE_INTAKE_CHECKLIST);
mutation DELETE_DELIVERY($jobId: uuid!) { const [deleteDelivery] = useMutation(DELETE_DELIVERY_CHECKLIST);
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { deliverchecklist: null }
) {
id
deliverchecklist
}
}
`);
const handleDelete = async (values) => { const handleDelete = async (values) => {
setLoading(true); setLoading(true);
@@ -50,7 +34,7 @@ export default function JobAdminDeleteIntake({ job }) {
const handleDeleteDelivery = async (values) => { const handleDeleteDelivery = async (values) => {
setLoading(true); setLoading(true);
const result = await DELETE_DELIVERY({ const result = await deleteDelivery({
variables: { jobId: job.id }, variables: { jobId: job.id },
}); });
@@ -68,12 +52,22 @@ export default function JobAdminDeleteIntake({ job }) {
return ( return (
<> <>
<Button loading={loading} onClick={handleDelete}> <Space>
{t("jobs.labels.deleteintake")} <Button
</Button> loading={loading}
<Button loading={loading} onClick={handleDeleteDelivery}> onClick={handleDelete}
{t("jobs.labels.deletedelivery")} disabled={!job.intakechecklist}
</Button> >
{t("jobs.labels.deleteintake")}
</Button>
<Button
loading={loading}
onClick={handleDeleteDelivery}
disabled={!job.deliverychecklist}
>
{t("jobs.labels.deletedelivery")}
</Button>
</Space>
</> </>
); );
} }

View File

@@ -1,5 +1,5 @@
import { gql, useMutation } from "@apollo/client"; import { useMutation } from "@apollo/client";
import { Button, notification } from "antd"; import { Button, Space, notification } from "antd";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -7,6 +7,11 @@ import moment from "moment";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
import {
MARK_JOB_AS_EXPORTED,
MARK_JOB_AS_UNINVOICED,
MARK_JOB_FOR_REEXPORT,
} from "../../graphql/jobs.queries";
import { insertAuditTrail } from "../../redux/application/application.actions"; import { insertAuditTrail } from "../../redux/application/application.actions";
import { import {
selectBodyshop, selectBodyshop,
@@ -35,58 +40,18 @@ export function JobAdminMarkReexport({
const { t } = useTranslation(); const { t } = useTranslation();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG); const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const [markJobForReexport] = useMutation(gql`
mutation MARK_JOB_FOR_REEXPORT($jobId: uuid!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { date_exported: null
status: "${bodyshop.md_ro_statuses.default_invoiced}"
}
) {
id
date_exported
status
date_invoiced
}
}
`);
const [markJobExported] = useMutation(gql` const [markJobForReexport] = useMutation(MARK_JOB_FOR_REEXPORT);
mutation MARK_JOB_AS_EXPORTED($jobId: uuid!, $date_exported: timestamptz!) { const [markJobExported] = useMutation(MARK_JOB_AS_EXPORTED);
update_jobs_by_pk( const [markJobUninvoiced] = useMutation(MARK_JOB_AS_UNINVOICED);
pk_columns: { id: $jobId }
_set: { date_exported: $date_exported
status: "${bodyshop.md_ro_statuses.default_exported}"
}
) {
id
date_exported
date_invoiced
status
}
}
`);
const [markJobUninvoiced] = useMutation(gql`
mutation MARK_JOB_AS_UNINVOICED($jobId: uuid!, ) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { date_exported: null
date_invoiced: null
status: "${bodyshop.md_ro_statuses.default_delivered}"
}
) {
id
date_exported
date_invoiced
status
}
}
`);
const handleMarkForExport = async () => { const handleMarkForExport = async () => {
setLoading(true); setLoading(true);
const result = await markJobForReexport({ const result = await markJobForReexport({
variables: { jobId: job.id }, variables: {
jobId: job.id,
default_invoiced: bodyshop.md_ro_statuses.default_invoiced,
},
}); });
if (!result.errors) { if (!result.errors) {
@@ -108,7 +73,11 @@ export function JobAdminMarkReexport({
const handleMarkExported = async () => { const handleMarkExported = async () => {
setLoading(true); setLoading(true);
const result = await markJobExported({ const result = await markJobExported({
variables: { jobId: job.id, date_exported: moment() }, variables: {
jobId: job.id,
date_exported: moment(),
default_exported: bodyshop.md_ro_statuses.default_exported,
},
}); });
await insertExportLog({ await insertExportLog({
@@ -144,7 +113,10 @@ export function JobAdminMarkReexport({
const handleUninvoice = async () => { const handleUninvoice = async () => {
setLoading(true); setLoading(true);
const result = await markJobUninvoiced({ const result = await markJobUninvoiced({
variables: { jobId: job.id }, variables: {
jobId: job.id,
default_delivered: bodyshop.md_ro_statuses.default_delivered,
},
}); });
if (!result.errors) { if (!result.errors) {
@@ -165,27 +137,29 @@ export function JobAdminMarkReexport({
return ( return (
<> <>
<Button <Space>
loading={loading} <Button
disabled={!job.date_exported} loading={loading}
onClick={handleMarkForExport} disabled={!job.date_exported}
> onClick={handleMarkForExport}
{t("jobs.labels.markforreexport")} >
</Button> {t("jobs.labels.markforreexport")}
<Button </Button>
loading={loading} <Button
disabled={job.date_exported} loading={loading}
onClick={handleMarkExported} disabled={job.date_exported}
> onClick={handleMarkExported}
{t("jobs.actions.markasexported")} >
</Button> {t("jobs.actions.markasexported")}
<Button </Button>
loading={loading} <Button
disabled={!job.date_invoiced || job.date_exported} loading={loading}
onClick={handleUninvoice} disabled={!job.date_invoiced || job.date_exported}
> onClick={handleUninvoice}
{t("jobs.actions.uninvoice")} >
</Button> {t("jobs.actions.uninvoice")}
</Button>
</Space>
</> </>
); );
} }

View File

@@ -1,9 +1,10 @@
import { gql, useMutation } from "@apollo/client"; import { useMutation } from "@apollo/client";
import { Form, Switch, notification } from "antd"; import { Switch, notification } from "antd";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { UPDATE_REMOVE_FROM_AR } from "../../graphql/jobs.queries";
import { insertAuditTrail } from "../../redux/application/application.actions"; import { insertAuditTrail } from "../../redux/application/application.actions";
import AuditTrailMapping from "../../utils/AuditTrailMappings"; import AuditTrailMapping from "../../utils/AuditTrailMappings";
@@ -20,21 +21,11 @@ export function JobsAdminRemoveAR({ insertAuditTrail, job }) {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [switchValue, setSwitchValue] = useState(job.remove_from_ar); const [switchValue, setSwitchValue] = useState(job.remove_from_ar);
const [updateJob] = useMutation(gql` const [mutationUpdateRemoveFromAR] = useMutation(UPDATE_REMOVE_FROM_AR);
mutation REMOVE_FROM_AR_JOB($jobId: uuid!, $remove_from_ar: Boolean!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { remove_from_ar: $remove_from_ar }
) {
id
remove_from_ar
}
}
`);
const handleChange = async (value) => { const handleChange = async (value) => {
setLoading(true); setLoading(true);
const result = await updateJob({ const result = await mutationUpdateRemoveFromAR({
variables: { jobId: job.id, remove_from_ar: value }, variables: { jobId: job.id, remove_from_ar: value },
}); });
@@ -56,8 +47,19 @@ export function JobsAdminRemoveAR({ insertAuditTrail, job }) {
}; };
return ( return (
<Form.Item name="remove_from_ar" label={t("jobs.labels.remove_from_ar")}> <>
<Switch checked={switchValue} loading={loading} onChange={handleChange} /> <div style={{ display: "flex", alignItems: "center" }}>
</Form.Item> <div style={{ marginRight: "10px" }}>
{t("jobs.labels.remove_from_ar")}:
</div>
<div>
<Switch
checked={switchValue}
loading={loading}
onChange={handleChange}
/>
</div>
</div>
</>
); );
} }

View File

@@ -1,9 +1,10 @@
import { gql, useMutation } from "@apollo/client"; import { useMutation } from "@apollo/client";
import { Button, notification } from "antd"; import { Button, notification } from "antd";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { UNVOID_JOB } from "../../graphql/jobs.queries";
import { insertAuditTrail } from "../../redux/application/application.actions"; import { insertAuditTrail } from "../../redux/application/application.actions";
import { import {
selectBodyshop, selectBodyshop,
@@ -29,66 +30,17 @@ export function JobsAdminUnvoid({
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [updateJob] = useMutation(gql` const [mutationUnvoidJob] = useMutation(UNVOID_JOB);
mutation UNVOID_JOB($jobId: uuid!) {
update_jobs_by_pk(pk_columns: {id: $jobId}, _set: {voided: false, status: "${
bodyshop.md_ro_statuses.default_imported
}", date_void: null}) {
id
date_void
voided
status
}
insert_notes(objects: {jobid: $jobId, audit: true, created_by: "${
currentUser.email
}", text: "${t("jobs.labels.unvoidnote")}"}) {
returning {
id
}
}
}
`);
// const result = await voidJob({
// variables: {
// jobId: job.id,
// job: {
// status: bodyshop.md_ro_statuses.default_void,
// voided: true,
// },
// note: [
// {
// jobid: job.id,
// created_by: currentUser.email,
// audit: true,
// text: t("jobs.labels.voidnote", {
// date: moment().format("MM/DD/yyy"),
// time: moment().format("hh:mm a"),
// }),
// },
// ],
// },
// });
// if (!!!result.errors) {
// notification["success"]({
// message: t("jobs.successes.voided"),
// });
// //go back to jobs list.
// history.push(`/manage/`);
// } else {
// notification["error"]({
// message: t("jobs.errors.voiding", {
// error: JSON.stringify(result.errors),
// }),
// });
// }
const handleUpdate = async (values) => { const handleUpdate = async (values) => {
setLoading(true); setLoading(true);
const result = await updateJob({ const result = await mutationUnvoidJob({
variables: { jobId: job.id }, variables: {
jobId: job.id,
default_imported: bodyshop.md_ro_statuses.default_imported,
currentUserEmail: currentUser.email,
text: t("jobs.labels.unvoidnote"),
},
}); });
if (!result.errors) { if (!result.errors) {
@@ -110,8 +62,10 @@ mutation UNVOID_JOB($jobId: uuid!) {
}; };
return ( return (
<Button loading={loading} disabled={!job.voided} onClick={handleUpdate}> <>
{t("jobs.actions.unvoid")} <Button loading={loading} disabled={!job.voided} onClick={handleUpdate}>
</Button> {t("jobs.actions.unvoid")}
</Button>
</>
); );
} }

View File

@@ -2221,3 +2221,120 @@ export const GET_JOB_LINE_ORDERS = gql`
} }
} }
`; `;
export const UPDATE_REMOVE_FROM_AR = gql`
mutation UPDATE_REMOVE_FROM_AR($jobId: uuid!, $remove_from_ar: Boolean!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { remove_from_ar: $remove_from_ar }
) {
id
remove_from_ar
}
}
`;
export const UNVOID_JOB = gql`
mutation UNVOID_JOB(
$jobId: uuid!
$default_imported: String!
$currentUserEmail: String!
$text: String!
) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { voided: false, status: $default_imported, date_void: null }
) {
id
date_void
voided
status
}
insert_notes(
objects: {
jobid: $jobId
audit: true
created_by: $currentUserEmail
text: $text
}
) {
returning {
id
}
}
}
`;
export const DELETE_INTAKE_CHECKLIST = gql`
mutation DELETE_INTAKE($jobId: uuid!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { intakechecklist: null }
) {
id
intakechecklist
}
}
`;
export const DELETE_DELIVERY_CHECKLIST = gql`
mutation DELETE_DELIVERY($jobId: uuid!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { deliverchecklist: null }
) {
id
deliverchecklist
}
}
`;
export const MARK_JOB_FOR_REEXPORT = gql`
mutation MARK_JOB_FOR_REEXPORT($jobId: uuid!, $default_invoiced: String!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { date_exported: null, status: $default_invoiced }
) {
id
date_exported
status
date_invoiced
}
}
`;
export const MARK_JOB_AS_EXPORTED = gql`
mutation MARK_JOB_AS_EXPORTED(
$jobId: uuid!
$date_exported: timestamptz!
$default_exported: String!
) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: { date_exported: $date_exported, status: $default_exported }
) {
id
date_exported
date_invoiced
status
}
}
`;
export const MARK_JOB_AS_UNINVOICED = gql`
mutation MARK_JOB_AS_UNINVOICED($jobId: uuid!, $default_delivered: String!) {
update_jobs_by_pk(
pk_columns: { id: $jobId }
_set: {
date_exported: null
date_invoiced: null
status: $default_delivered
}
) {
id
date_exported
date_invoiced
status
}
}
`;