feature/IO-3477-Set-Parts-Location: Done
This commit is contained in:
@@ -9,10 +9,10 @@ import {
|
|||||||
WarningFilled
|
WarningFilled
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import { PageHeader } from "@ant-design/pro-layout";
|
import { PageHeader } from "@ant-design/pro-layout";
|
||||||
import { useMutation } from "@apollo/client";
|
import { gql, useMutation } from "@apollo/client";
|
||||||
import { Button, Dropdown, Input, Space, Table, Tag } from "antd";
|
import { Button, Dropdown, Input, Modal, Select, Space, Table, Tag, Typography } from "antd";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useState } from "react";
|
import { useMemo, 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";
|
||||||
@@ -47,6 +47,19 @@ import JobLinesExpander from "./job-lines-expander.component";
|
|||||||
import JobLinesPartPriceChange from "./job-lines-part-price-change.component";
|
import JobLinesPartPriceChange from "./job-lines-part-price-change.component";
|
||||||
import JobLinesExpanderSimple from "./jobs-lines-expander-simple.component";
|
import JobLinesExpanderSimple from "./jobs-lines-expander-simple.component";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
|
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||||
|
|
||||||
|
const UPDATE_JOB_LINES_LOCATION_BULK = gql`
|
||||||
|
mutation UPDATE_JOB_LINES_LOCATION_BULK($ids: [uuid!]!, $location: String!) {
|
||||||
|
update_joblines(where: { id: { _in: $ids } }, _set: { location: $location }) {
|
||||||
|
affected_rows
|
||||||
|
returning {
|
||||||
|
id
|
||||||
|
location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -83,6 +96,9 @@ export function JobLinesComponent({
|
|||||||
isPartsEntry
|
isPartsEntry
|
||||||
}) {
|
}) {
|
||||||
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
|
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
|
||||||
|
const [bulkUpdateLocations] = useMutation(UPDATE_JOB_LINES_LOCATION_BULK);
|
||||||
|
const notification = useNotification();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
treatments: { Enhanced_Payroll }
|
treatments: { Enhanced_Payroll }
|
||||||
} = useSplitTreatments({
|
} = useSplitTreatments({
|
||||||
@@ -103,9 +119,83 @@ export function JobLinesComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Bulk location modal state
|
||||||
|
const [bulkLocationOpen, setBulkLocationOpen] = useState(false);
|
||||||
|
const [bulkLocation, setBulkLocation] = useState(null);
|
||||||
|
const [bulkLocationSaving, setBulkLocationSaving] = useState(false);
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const jobIsPrivate = bodyshop.md_ins_cos.find((c) => c.name === job.ins_co_nm)?.private;
|
const jobIsPrivate = bodyshop.md_ins_cos.find((c) => c.name === job.ins_co_nm)?.private;
|
||||||
|
|
||||||
|
const selectedLineIds = useMemo(() => selectedLines.map((l) => l?.id).filter(Boolean), [selectedLines]);
|
||||||
|
|
||||||
|
const commonSelectedLocation = useMemo(() => {
|
||||||
|
const locs = selectedLines
|
||||||
|
.map((l) => (typeof l?.location === "string" ? l.location : ""))
|
||||||
|
.map((x) => x.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
if (locs.length === 0) return null;
|
||||||
|
|
||||||
|
const uniq = _.uniq(locs);
|
||||||
|
return uniq.length === 1 ? uniq[0] : null;
|
||||||
|
}, [selectedLines]);
|
||||||
|
|
||||||
|
const openBulkLocationModal = () => {
|
||||||
|
setBulkLocation(commonSelectedLocation);
|
||||||
|
setBulkLocationOpen(true);
|
||||||
|
logImEXEvent("joblines_bulk_location_open", { count: selectedLineIds.length });
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeBulkLocationModal = () => {
|
||||||
|
setBulkLocationOpen(false);
|
||||||
|
setBulkLocation(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveBulkLocation = async () => {
|
||||||
|
if (selectedLineIds.length === 0) return;
|
||||||
|
|
||||||
|
setBulkLocationSaving(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const locationToSave = (bulkLocation ?? "").toString();
|
||||||
|
|
||||||
|
const result = await bulkUpdateLocations({
|
||||||
|
variables: {
|
||||||
|
ids: selectedLineIds,
|
||||||
|
location: locationToSave
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result?.errors) {
|
||||||
|
// Keep UI selection consistent without waiting for refetch
|
||||||
|
setSelectedLines((prev) =>
|
||||||
|
prev.map((l) => (l && selectedLineIds.includes(l.id) ? { ...l, location: locationToSave } : l))
|
||||||
|
);
|
||||||
|
|
||||||
|
notification["success"]({ message: t("joblines.successes.saved") });
|
||||||
|
|
||||||
|
logImEXEvent("joblines_bulk_location_saved", {
|
||||||
|
count: selectedLineIds.length,
|
||||||
|
location: locationToSave
|
||||||
|
});
|
||||||
|
|
||||||
|
closeBulkLocationModal();
|
||||||
|
if (refetch) refetch();
|
||||||
|
} else {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("joblines.errors.saving", { error: JSON.stringify(result.errors) })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("joblines.errors.saving", { error: error?.message || String(error) })
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setBulkLocationSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: "#",
|
title: "#",
|
||||||
@@ -171,46 +261,16 @@ export function JobLinesComponent({
|
|||||||
? ["PAN", "PAC", "PAR", "PAL", "PAA", "PAM", "PAP", "PAS", "PASL", "PAG", "PAO"]
|
? ["PAN", "PAC", "PAR", "PAL", "PAA", "PAM", "PAP", "PAS", "PASL", "PAG", "PAO"]
|
||||||
: ["PAN", "PAC", "PAR", "PAL", "PAA", "PAM", "PAP", "PAS", "PASL", "PAG"]
|
: ["PAN", "PAC", "PAR", "PAL", "PAA", "PAM", "PAP", "PAS", "PASL", "PAG"]
|
||||||
},
|
},
|
||||||
{
|
{ text: t("joblines.fields.part_types.PAN"), value: ["PAN"] },
|
||||||
text: t("joblines.fields.part_types.PAN"),
|
{ text: t("joblines.fields.part_types.PAP"), value: ["PAP"] },
|
||||||
value: ["PAN"]
|
{ text: t("joblines.fields.part_types.PAL"), value: ["PAL"] },
|
||||||
},
|
{ text: t("joblines.fields.part_types.PAA"), value: ["PAA"] },
|
||||||
{
|
{ text: t("joblines.fields.part_types.PAG"), value: ["PAG"] },
|
||||||
text: t("joblines.fields.part_types.PAP"),
|
{ text: t("joblines.fields.part_types.PAS"), value: ["PAS"] },
|
||||||
value: ["PAP"]
|
{ text: t("joblines.fields.part_types.PASL"), value: ["PASL"] },
|
||||||
},
|
{ text: t("joblines.fields.part_types.PAC"), value: ["PAC"] },
|
||||||
{
|
{ text: t("joblines.fields.part_types.PAR"), value: ["PAR"] },
|
||||||
text: t("joblines.fields.part_types.PAL"),
|
{ text: t("joblines.fields.part_types.PAM"), value: ["PAM"] },
|
||||||
value: ["PAL"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PAA"),
|
|
||||||
value: ["PAA"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PAG"),
|
|
||||||
value: ["PAG"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PAS"),
|
|
||||||
value: ["PAS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PASL"),
|
|
||||||
value: ["PASL"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PAC"),
|
|
||||||
value: ["PAC"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PAR"),
|
|
||||||
value: ["PAR"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t("joblines.fields.part_types.PAM"),
|
|
||||||
value: ["PAM"]
|
|
||||||
},
|
|
||||||
...(isPartsEntry
|
...(isPartsEntry
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
@@ -220,7 +280,6 @@ export function JobLinesComponent({
|
|||||||
]
|
]
|
||||||
: [])
|
: [])
|
||||||
],
|
],
|
||||||
|
|
||||||
onFilter: (value, record) => value.includes(record.part_type),
|
onFilter: (value, record) => value.includes(record.part_type),
|
||||||
render: (text, record) => (record.part_type ? t(`joblines.fields.part_types.${record.part_type}`) : null)
|
render: (text, record) => (record.part_type ? t(`joblines.fields.part_types.${record.part_type}`) : null)
|
||||||
},
|
},
|
||||||
@@ -246,7 +305,6 @@ export function JobLinesComponent({
|
|||||||
title: t("joblines.fields.mod_lbr_ty"),
|
title: t("joblines.fields.mod_lbr_ty"),
|
||||||
dataIndex: "mod_lbr_ty",
|
dataIndex: "mod_lbr_ty",
|
||||||
key: "mod_lbr_ty",
|
key: "mod_lbr_ty",
|
||||||
|
|
||||||
sorter: (a, b) => alphaSort(a.mod_lbr_ty, b.mod_lbr_ty),
|
sorter: (a, b) => alphaSort(a.mod_lbr_ty, b.mod_lbr_ty),
|
||||||
sortOrder: state.sortedInfo.columnKey === "mod_lbr_ty" && state.sortedInfo.order,
|
sortOrder: state.sortedInfo.columnKey === "mod_lbr_ty" && state.sortedInfo.order,
|
||||||
render: (text, record) => (record.mod_lbr_ty ? t(`joblines.fields.lbr_types.${record.mod_lbr_ty}`) : null)
|
render: (text, record) => (record.mod_lbr_ty ? t(`joblines.fields.lbr_types.${record.mod_lbr_ty}`) : null)
|
||||||
@@ -255,7 +313,6 @@ export function JobLinesComponent({
|
|||||||
title: t("joblines.fields.mod_lb_hrs"),
|
title: t("joblines.fields.mod_lb_hrs"),
|
||||||
dataIndex: "mod_lb_hrs",
|
dataIndex: "mod_lb_hrs",
|
||||||
key: "mod_lb_hrs",
|
key: "mod_lb_hrs",
|
||||||
|
|
||||||
sorter: (a, b) => a.mod_lb_hrs - b.mod_lb_hrs,
|
sorter: (a, b) => a.mod_lb_hrs - b.mod_lb_hrs,
|
||||||
sortOrder: state.sortedInfo.columnKey === "mod_lb_hrs" && state.sortedInfo.order
|
sortOrder: state.sortedInfo.columnKey === "mod_lb_hrs" && state.sortedInfo.order
|
||||||
},
|
},
|
||||||
@@ -310,18 +367,12 @@ export function JobLinesComponent({
|
|||||||
sorter: (a, b) => alphaSort(a.status, b.status),
|
sorter: (a, b) => alphaSort(a.status, b.status),
|
||||||
sortOrder: state.sortedInfo.columnKey === "status" && state.sortedInfo.order,
|
sortOrder: state.sortedInfo.columnKey === "status" && state.sortedInfo.order,
|
||||||
filteredValue: state.filteredInfo.status || null,
|
filteredValue: state.filteredInfo.status || null,
|
||||||
|
|
||||||
filters:
|
filters:
|
||||||
(jobLines &&
|
(jobLines &&
|
||||||
jobLines
|
jobLines
|
||||||
.map((l) => l.status)
|
.map((l) => l.status)
|
||||||
.filter(onlyUnique)
|
.filter(onlyUnique)
|
||||||
.map((s) => {
|
.map((s) => ({ text: s || t("dashboard.errors.status"), value: [s] }))) ||
|
||||||
return {
|
|
||||||
text: s || t("dashboard.errors.status"),
|
|
||||||
value: [s]
|
|
||||||
};
|
|
||||||
})) ||
|
|
||||||
[],
|
[],
|
||||||
onFilter: (value, record) => value.includes(record.status),
|
onFilter: (value, record) => value.includes(record.status),
|
||||||
render: (text, record) => <JobLineStatusPopup jobline={record} disabled={jobRO} />
|
render: (text, record) => <JobLineStatusPopup jobline={record} disabled={jobRO} />
|
||||||
@@ -376,9 +427,7 @@ export function JobLinesComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await axios.post("/job/totalsssu", {
|
await axios.post("/job/totalsssu", { id: job.id });
|
||||||
id: job.id
|
|
||||||
});
|
|
||||||
if (refetch) refetch();
|
if (refetch) refetch();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -448,6 +497,36 @@ export function JobLinesComponent({
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<PartsOrderModalContainer />
|
<PartsOrderModalContainer />
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
open={bulkLocationOpen}
|
||||||
|
title={t("joblines.actions.updatelocation")}
|
||||||
|
onCancel={closeBulkLocationModal}
|
||||||
|
onOk={saveBulkLocation}
|
||||||
|
okButtonProps={{
|
||||||
|
disabled: jobRO || technician || selectedLineIds.length === 0,
|
||||||
|
loading: bulkLocationSaving
|
||||||
|
}}
|
||||||
|
destroyOnHidden
|
||||||
|
>
|
||||||
|
<Space direction="vertical" style={{ width: "100%" }}>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
{t("general.labels.selected")}: {selectedLineIds.length}
|
||||||
|
</Typography.Text>
|
||||||
|
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder={t("joblines.fields.location")}
|
||||||
|
value={bulkLocation}
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
popupMatchSelectWidth={false}
|
||||||
|
onChange={(val) => setBulkLocation(val ?? null)}
|
||||||
|
options={(bodyshop?.md_parts_locations || []).map((loc) => ({ label: loc, value: loc }))}
|
||||||
|
/>
|
||||||
|
<Typography.Text type="secondary">{t("joblines.labels.bulk_location_help")}</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
{!technician && (
|
{!technician && (
|
||||||
<PartsOrderDrawer
|
<PartsOrderDrawer
|
||||||
job={job}
|
job={job}
|
||||||
@@ -457,6 +536,7 @@ export function JobLinesComponent({
|
|||||||
setTaskUpsertContext={setTaskUpsertContext}
|
setTaskUpsertContext={setTaskUpsertContext}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={t("jobs.labels.estimatelines")}
|
title={t("jobs.labels.estimatelines")}
|
||||||
extra={
|
extra={
|
||||||
@@ -465,6 +545,16 @@ export function JobLinesComponent({
|
|||||||
<SyncOutlined />
|
<SyncOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
{/* Bulk Update Location */}
|
||||||
|
<Button
|
||||||
|
id="job-lines-bulk-update-location-button"
|
||||||
|
disabled={jobRO || technician || selectedLineIds.length === 0}
|
||||||
|
onClick={openBulkLocationModal}
|
||||||
|
>
|
||||||
|
{t("joblines.actions.updatelocation")}
|
||||||
|
{selectedLineIds.length > 0 && ` (${selectedLineIds.length})`}
|
||||||
|
</Button>
|
||||||
|
|
||||||
{job.special_coverage_policy && (
|
{job.special_coverage_policy && (
|
||||||
<Tag color="tomato">
|
<Tag color="tomato">
|
||||||
<Space>
|
<Space>
|
||||||
@@ -473,6 +563,7 @@ export function JobLinesComponent({
|
|||||||
</Space>
|
</Space>
|
||||||
</Tag>
|
</Tag>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isPartsEntry && (
|
{!isPartsEntry && (
|
||||||
<JobLineDispatchButton
|
<JobLineDispatchButton
|
||||||
selectedLines={selectedLines}
|
selectedLines={selectedLines}
|
||||||
@@ -481,9 +572,11 @@ export function JobLinesComponent({
|
|||||||
disabled={technician}
|
disabled={technician}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{Enhanced_Payroll.treatment === "on" && (
|
{Enhanced_Payroll.treatment === "on" && (
|
||||||
<JobLineBulkAssignComponent selectedLines={selectedLines} setSelectedLines={setSelectedLines} job={job} />
|
<JobLineBulkAssignComponent selectedLines={selectedLines} setSelectedLines={setSelectedLines} job={job} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isPartsEntry && (
|
{!isPartsEntry && (
|
||||||
<Button
|
<Button
|
||||||
disabled={(job && !job.converted) || (selectedLines.length > 0 ? false : true) || jobRO || technician}
|
disabled={(job && !job.converted) || (selectedLines.length > 0 ? false : true) || jobRO || technician}
|
||||||
@@ -499,27 +592,20 @@ export function JobLinesComponent({
|
|||||||
isinhouse: true,
|
isinhouse: true,
|
||||||
date: dayjs(),
|
date: dayjs(),
|
||||||
total: 0,
|
total: 0,
|
||||||
billlines: selectedLines.map((p) => {
|
billlines: selectedLines.map((p) => ({
|
||||||
return {
|
joblineid: p.id,
|
||||||
joblineid: p.id,
|
actual_price: p.act_price,
|
||||||
actual_price: p.act_price,
|
actual_cost: 0,
|
||||||
actual_cost: 0, //p.act_price,
|
line_desc: p.line_desc,
|
||||||
line_desc: p.line_desc,
|
line_remarks: p.line_remarks,
|
||||||
line_remarks: p.line_remarks,
|
part_type: p.part_type,
|
||||||
part_type: p.part_type,
|
quantity: p.quantity || 1,
|
||||||
quantity: p.quantity || 1,
|
applicable_taxes: { local: false, state: false, federal: false }
|
||||||
applicable_taxes: {
|
}))
|
||||||
local: false,
|
|
||||||
state: false,
|
|
||||||
federal: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Clear out the selected lines. IO-785
|
|
||||||
setSelectedLines([]);
|
setSelectedLines([]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -528,6 +614,7 @@ export function JobLinesComponent({
|
|||||||
{selectedLines.length > 0 && ` (${selectedLines.length})`}
|
{selectedLines.length > 0 && ` (${selectedLines.length})`}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
id="job-lines-order-parts-button"
|
id="job-lines-order-parts-button"
|
||||||
disabled={(job && !job.converted) || (selectedLines.length > 0 ? false : true) || jobRO || technician}
|
disabled={(job && !job.converted) || (selectedLines.length > 0 ? false : true) || jobRO || technician}
|
||||||
@@ -544,13 +631,13 @@ export function JobLinesComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Clear out the selected lines. IO-785
|
|
||||||
setSelectedLines([]);
|
setSelectedLines([]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("parts.actions.order")}
|
{t("parts.actions.order")}
|
||||||
{selectedLines.length > 0 && ` (${selectedLines.length})`}
|
{selectedLines.length > 0 && ` (${selectedLines.length})`}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{!isPartsEntry && (
|
{!isPartsEntry && (
|
||||||
<Button
|
<Button
|
||||||
id="job-lines-filter-parts-only-button"
|
id="job-lines-filter-parts-only-button"
|
||||||
@@ -567,9 +654,11 @@ export function JobLinesComponent({
|
|||||||
<FilterFilled /> {t("jobs.actions.filterpartsonly")}
|
<FilterFilled /> {t("jobs.actions.filterpartsonly")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Dropdown menu={markMenu} trigger={["click"]}>
|
<Dropdown menu={markMenu} trigger={["click"]}>
|
||||||
<Button id="repair-data-mark-button">{t("jobs.actions.mark")}</Button>
|
<Button id="repair-data-mark-button">{t("jobs.actions.mark")}</Button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|
||||||
{!isPartsEntry && (
|
{!isPartsEntry && (
|
||||||
<Button
|
<Button
|
||||||
disabled={jobRO || technician}
|
disabled={jobRO || technician}
|
||||||
@@ -583,9 +672,12 @@ export function JobLinesComponent({
|
|||||||
{t("joblines.actions.new")}
|
{t("joblines.actions.new")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isPartsEntry &&
|
{!isPartsEntry &&
|
||||||
InstanceRenderManager({ rome: <JobSendPartPriceChangeComponent job={job} disabled={technician} /> })}
|
InstanceRenderManager({ rome: <JobSendPartPriceChangeComponent job={job} disabled={technician} /> })}
|
||||||
|
|
||||||
<JobCreateIOU job={job} selectedJobLines={selectedLines} />
|
<JobCreateIOU job={job} selectedJobLines={selectedLines} />
|
||||||
|
|
||||||
<Input.Search
|
<Input.Search
|
||||||
placeholder={t("general.labels.search")}
|
placeholder={t("general.labels.search")}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
@@ -596,6 +688,7 @@ export function JobLinesComponent({
|
|||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
columns={columns}
|
columns={columns}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
@@ -603,9 +696,7 @@ export function JobLinesComponent({
|
|||||||
pagination={false}
|
pagination={false}
|
||||||
dataSource={jobLines}
|
dataSource={jobLines}
|
||||||
onChange={handleTableChange}
|
onChange={handleTableChange}
|
||||||
scroll={{
|
scroll={{ x: true }}
|
||||||
x: true
|
|
||||||
}}
|
|
||||||
expandable={{
|
expandable={{
|
||||||
expandedRowRender: (record) =>
|
expandedRowRender: (record) =>
|
||||||
isPartsEntry ? (
|
isPartsEntry ? (
|
||||||
@@ -614,7 +705,6 @@ export function JobLinesComponent({
|
|||||||
<JobLinesExpander jobline={record} jobid={job.id} />
|
<JobLinesExpander jobline={record} jobid={job.id} />
|
||||||
),
|
),
|
||||||
rowExpandable: () => true,
|
rowExpandable: () => true,
|
||||||
//expandRowByClick: true,
|
|
||||||
expandIcon: ({ expanded, onExpand, record }) =>
|
expandIcon: ({ expanded, onExpand, record }) =>
|
||||||
expanded ? (
|
expanded ? (
|
||||||
<MinusCircleTwoTone onClick={(e) => onExpand(record, e)} />
|
<MinusCircleTwoTone onClick={(e) => onExpand(record, e)} />
|
||||||
@@ -627,17 +717,15 @@ export function JobLinesComponent({
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
onRow={(record) => {
|
onRow={(record) => ({
|
||||||
return {
|
onDoubleClick: () => {
|
||||||
onDoubleClick: () => {
|
logImEXEvent("joblines_double_click_select", {});
|
||||||
logImEXEvent("joblines_double_click_select", {});
|
const notMatchingLines = selectedLines.filter((i) => i.id !== record.id);
|
||||||
const notMatchingLines = selectedLines.filter((i) => i.id !== record.id);
|
notMatchingLines.length !== selectedLines.length
|
||||||
notMatchingLines.length !== selectedLines.length
|
? setSelectedLines(notMatchingLines)
|
||||||
? setSelectedLines(notMatchingLines)
|
: setSelectedLines([...selectedLines, record]);
|
||||||
: setSelectedLines([...selectedLines, record]);
|
}
|
||||||
} // double click row
|
})}
|
||||||
};
|
|
||||||
}}
|
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
selectedRowKeys: selectedLines.map((item) => item && item.id),
|
selectedRowKeys: selectedLines.map((item) => item && item.id),
|
||||||
onSelectAll: (selected, selectedRows) => {
|
onSelectAll: (selected, selectedRows) => {
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
import { useMutation } from "@apollo/client";
|
import { useMutation } from "@apollo/client";
|
||||||
import { Select, Space } from "antd";
|
import { Select, Space, Tag } from "antd";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, 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_JOB_LINE } from "../../graphql/jobs-lines.queries";
|
import { UPDATE_JOB_LINE } from "../../graphql/jobs-lines.queries";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
|
||||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser
|
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = () => ({
|
const mapDispatchToProps = () => ({});
|
||||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
|
||||||
});
|
const CLEAR_VALUE = "__CLEAR_LOCATION__";
|
||||||
|
|
||||||
export function JobLineLocationPopup({ bodyshop, jobline, disabled }) {
|
export function JobLineLocationPopup({ bodyshop, jobline, disabled }) {
|
||||||
const [editing, setEditing] = useState(false);
|
const [editing, setEditing] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [location, setLocation] = useState(jobline.location);
|
const [location, setLocation] = useState(jobline.location);
|
||||||
const [updateJob] = useMutation(UPDATE_JOB_LINE);
|
const [updateJob] = useMutation(UPDATE_JOB_LINE);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -29,55 +27,78 @@ export function JobLineLocationPopup({ bodyshop, jobline, disabled }) {
|
|||||||
if (editing) setLocation(jobline.location);
|
if (editing) setLocation(jobline.location);
|
||||||
}, [editing, jobline.location]);
|
}, [editing, jobline.location]);
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const options = useMemo(() => {
|
||||||
setLocation(e);
|
const locs = bodyshop?.md_parts_locations || [];
|
||||||
};
|
return [
|
||||||
|
{ label: t("general.labels.none", "No location"), value: CLEAR_VALUE },
|
||||||
|
...locs.map((loc) => ({ label: loc, value: loc }))
|
||||||
|
];
|
||||||
|
}, [bodyshop?.md_parts_locations, t]);
|
||||||
|
|
||||||
const handleSave = async () => {
|
const saveLocation = async (nextLocation) => {
|
||||||
setLoading(true);
|
setSaving(true);
|
||||||
const result = await updateJob({
|
|
||||||
variables: { lineId: jobline.id, line: { location: location || "" } }
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.errors) {
|
try {
|
||||||
notification["success"]({ message: t("joblines.successes.saved") });
|
const result = await updateJob({
|
||||||
} else {
|
variables: { lineId: jobline.id, line: { location: nextLocation || "" } }
|
||||||
notification["error"]({
|
|
||||||
message: t("joblines.errors.saving", {
|
|
||||||
error: JSON.stringify(result.errors)
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!result.errors) {
|
||||||
|
notification["success"]({ message: t("joblines.successes.saved") });
|
||||||
|
} else {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("joblines.errors.saving", {
|
||||||
|
error: JSON.stringify(result.errors)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("joblines.errors.saving", { error: error?.message || String(error) })
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
setEditing(false);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
|
||||||
setEditing(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (editing)
|
const handleChange = async (value) => {
|
||||||
|
const next = value === CLEAR_VALUE ? null : value;
|
||||||
|
setLocation(next);
|
||||||
|
await saveLocation(next);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (editing) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div style={{ width: "100%", display: "flex", alignItems: "center" }}>
|
||||||
<LoadingSpinner loading={loading}>
|
<Select
|
||||||
<Select
|
autoFocus
|
||||||
autoFocus
|
size="small"
|
||||||
allowClear
|
value={location ?? undefined}
|
||||||
popupMatchSelectWidth={100}
|
loading={saving}
|
||||||
value={location}
|
disabled={saving}
|
||||||
onClear={() => setLocation(null)}
|
style={{ flex: 1, minWidth: 0 }}
|
||||||
onSelect={handleChange}
|
popupMatchSelectWidth={false}
|
||||||
onBlur={handleSave}
|
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
||||||
>
|
onChange={handleChange}
|
||||||
{bodyshop.md_parts_locations.map((loc, idx) => (
|
onBlur={() => !saving && setEditing(false)}
|
||||||
<Select.Option key={idx} value={loc}>
|
options={options}
|
||||||
{loc}
|
/>
|
||||||
</Select.Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</LoadingSpinner>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ width: "100%", minHeight: "2rem", cursor: "pointer" }} onClick={() => !disabled && setEditing(true)}>
|
<div
|
||||||
|
style={{ width: "100%", minHeight: "2rem", cursor: disabled ? "default" : "pointer" }}
|
||||||
|
onClick={() => !disabled && setEditing(true)}
|
||||||
|
>
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
{jobline.location}
|
{jobline.location ? (
|
||||||
|
<Tag>{jobline.location}</Tag>
|
||||||
|
) : (
|
||||||
|
<span style={{ opacity: 0.6 }}>{t("general.labels.none")}</span>
|
||||||
|
)}
|
||||||
{jobline.parts_dispatch_lines?.length > 0 && "-Disp"}
|
{jobline.parts_dispatch_lines?.length > 0 && "-Disp"}
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1270,6 +1270,7 @@
|
|||||||
"vehicle": "Vehicle"
|
"vehicle": "Vehicle"
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"selected": "Selected",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"actions": "Actions",
|
"actions": "Actions",
|
||||||
"areyousure": "Are you sure?",
|
"areyousure": "Are you sure?",
|
||||||
@@ -1491,7 +1492,8 @@
|
|||||||
"assign_team": "Assign Team",
|
"assign_team": "Assign Team",
|
||||||
"converttolabor": "Convert amount to Labor.",
|
"converttolabor": "Convert amount to Labor.",
|
||||||
"dispatchparts": "Dispatch Parts ({{count}})",
|
"dispatchparts": "Dispatch Parts ({{count}})",
|
||||||
"new": "New Line"
|
"new": "New Line",
|
||||||
|
"updatelocation": "Update Location"
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"creating": "Error encountered while creating job line. {{message}}",
|
"creating": "Error encountered while creating job line. {{message}}",
|
||||||
@@ -1572,7 +1574,8 @@
|
|||||||
"ioucreated": "IOU",
|
"ioucreated": "IOU",
|
||||||
"new": "New Line",
|
"new": "New Line",
|
||||||
"nostatus": "No Status",
|
"nostatus": "No Status",
|
||||||
"presets": "Jobline Presets"
|
"presets": "Jobline Presets",
|
||||||
|
"bulk_location_help": "This will set the same location on all selected lines."
|
||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"created": "Job line created successfully.",
|
"created": "Job line created successfully.",
|
||||||
|
|||||||
@@ -1270,6 +1270,7 @@
|
|||||||
"vehicle": ""
|
"vehicle": ""
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"selected": "",
|
||||||
"actions": "Comportamiento",
|
"actions": "Comportamiento",
|
||||||
"settings": "",
|
"settings": "",
|
||||||
"areyousure": "",
|
"areyousure": "",
|
||||||
@@ -1491,7 +1492,8 @@
|
|||||||
"assign_team": "",
|
"assign_team": "",
|
||||||
"converttolabor": "",
|
"converttolabor": "",
|
||||||
"dispatchparts": "",
|
"dispatchparts": "",
|
||||||
"new": ""
|
"new": "",
|
||||||
|
"updatelocation": ""
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"creating": "",
|
"creating": "",
|
||||||
@@ -1572,7 +1574,8 @@
|
|||||||
"ioucreated": "",
|
"ioucreated": "",
|
||||||
"new": "Nueva línea",
|
"new": "Nueva línea",
|
||||||
"nostatus": "",
|
"nostatus": "",
|
||||||
"presets": ""
|
"presets": "",
|
||||||
|
"bulk_location_help": ""
|
||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"created": "",
|
"created": "",
|
||||||
|
|||||||
@@ -1270,6 +1270,7 @@
|
|||||||
"vehicle": ""
|
"vehicle": ""
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"selected": "",
|
||||||
"settings": "",
|
"settings": "",
|
||||||
"actions": "actes",
|
"actions": "actes",
|
||||||
"areyousure": "",
|
"areyousure": "",
|
||||||
@@ -1491,7 +1492,8 @@
|
|||||||
"assign_team": "",
|
"assign_team": "",
|
||||||
"converttolabor": "",
|
"converttolabor": "",
|
||||||
"dispatchparts": "",
|
"dispatchparts": "",
|
||||||
"new": ""
|
"new": "",
|
||||||
|
"updatelocation": ""
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"creating": "",
|
"creating": "",
|
||||||
@@ -1572,7 +1574,8 @@
|
|||||||
"ioucreated": "",
|
"ioucreated": "",
|
||||||
"new": "Nouvelle ligne",
|
"new": "Nouvelle ligne",
|
||||||
"nostatus": "",
|
"nostatus": "",
|
||||||
"presets": ""
|
"presets": "",
|
||||||
|
"bulk_location_help": ""
|
||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"created": "",
|
"created": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user