Compare commits

..

1 Commits

Author SHA1 Message Date
Dave
155d0af509 feature/IO-1710-prevent-duplicate-ins-companies 2025-12-30 12:54:27 -05:00
15 changed files with 59 additions and 85 deletions

View File

@@ -253,10 +253,6 @@ export function ContractConvertToRo({ bodyshop, currentUser, contract, disabled
}
};
if (currentUser?.email) {
newJob.created_user_email = currentUser.email;
}
//Calcualte the new job totals.
const newTotals = (

View File

@@ -43,18 +43,16 @@ export function JobCreateIOU({ bodyshop, currentUser, job, selectedJobLines, tec
const handleCreateIou = async () => {
setLoading(true);
//Query all of the job details to recreate.
const iouId = await CreateIouForJob({
apolloClient: client,
jobLinesToKeep: selectedJobLines,
jobId: job.id,
config: {
const iouId = await CreateIouForJob(
client,
job.id,
{
status: bodyshop.md_ro_statuses.default_open,
bodyshopid: bodyshop.id,
useremail: currentUser.email
},
currentUser
});
selectedJobLines
);
notification.open({
type: "success",
message: t("jobs.successes.ioucreated"),

View File

@@ -154,10 +154,6 @@ export function JobsAvailableContainer({ bodyshop, currentUser, insertAuditTrail
: {})
};
if (currentUser?.email) {
newJob.created_user_email = currentUser.email;
}
if (selectedOwner) {
newJob.ownerid = selectedOwner;
delete newJob.owner;

View File

@@ -175,33 +175,25 @@ export function JobsDetailHeaderActions({
};
const handleDuplicate = () =>
DuplicateJob({
apolloClient: client,
jobId: job.id,
config: { defaultOpenStatus: bodyshop.md_ro_statuses.default_imported },
completionCallback: (newJobId) => {
DuplicateJob(
client,
job.id,
{ defaultOpenStatus: bodyshop.md_ro_statuses.default_imported },
(newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification.success({
message: t("jobs.successes.duplicated")
});
},
keepJobLines: true,
currentUser
});
true
);
const handleDuplicateConfirm = () =>
DuplicateJob({
apolloClient: client,
jobId: job.id,
config: { defaultOpenStatus: bodyshop.md_ro_statuses.default_imported },
completionCallback: (newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification.success({
message: t("jobs.successes.duplicated")
});
},
keepJobLines: false,
currentUser
DuplicateJob(client, job.id, { defaultOpenStatus: bodyshop.md_ro_statuses.default_imported }, (newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification.success({
message: t("jobs.successes.duplicated")
});
});
const handleFinish = async (values) => {

View File

@@ -5,14 +5,7 @@ import { INSERT_NEW_JOB, QUERY_JOB_FOR_DUPE } from "../../graphql/jobs.queries";
import dayjs from "../../utils/day";
import i18n from "i18next";
export default async function DuplicateJob({
apolloClient,
jobId,
config,
completionCallback,
keepJobLines = false,
currentUser
}) {
export default async function DuplicateJob(apolloClient, jobId, config, completionCallback, keepJobLines = false) {
logImEXEvent("job_duplicate");
const { defaultOpenStatus } = config;
@@ -26,7 +19,6 @@ export default async function DuplicateJob({
const existingJob = _.cloneDeep(jobs_by_pk);
delete existingJob.__typename;
delete existingJob.id;
delete existingJob.created_user_email;
delete existingJob.createdat;
delete existingJob.updatedat;
delete existingJob.cieca_stl;
@@ -37,10 +29,6 @@ export default async function DuplicateJob({
status: defaultOpenStatus
};
if (currentUser?.email) {
newJob.created_user_email = currentUser.email;
}
const _tempLines = _.cloneDeep(existingJob.joblines);
_tempLines.forEach((line) => {
delete line.id;
@@ -67,7 +55,7 @@ export default async function DuplicateJob({
return;
}
export async function CreateIouForJob({ apolloClient, jobId, config, jobLinesToKeep, currentUser }) {
export async function CreateIouForJob(apolloClient, jobId, config, jobLinesToKeep) {
logImEXEvent("job_create_iou");
const { status } = config;
@@ -121,9 +109,6 @@ export async function CreateIouForJob({ apolloClient, jobId, config, jobLinesToK
delete newJob.joblines;
newJob.joblines = { data: _tempLines };
if (currentUser?.email) {
newJob.created_user_email = currentUser.email;
}
const res2 = await apolloClient.mutate({
mutation: INSERT_NEW_JOB,
variables: { job: [newJob] }

View File

@@ -934,6 +934,8 @@ export function ShopInfoGeneral({ form, bodyshop }) {
}}
</Form.List>
</LayoutFormRow>
{/*Start Insurance Provider Row */}
<LayoutFormRow
grow
header={<span id="insurancecos-header">{t("bodyshop.labels.insurancecos")}</span>}
@@ -950,11 +952,31 @@ export function ShopInfoGeneral({ form, bodyshop }) {
label={t("bodyshop.fields.md_ins_co.name")}
key={`${index}name`}
name={[field.name, "name"]}
dependencies={[["md_ins_cos"]]}
rules={[
{
required: true
//message: t("general.validation.required"),
}
},
({ getFieldValue }) => ({
validator: async (_, value) => {
const normalizedValue = (value ?? "").toString().trim().toLowerCase();
if (!normalizedValue) return Promise.resolve(); // handled by required
const list = getFieldValue(["md_ins_cos"]) || [];
const normalizedNames = list
.map((c) => (c?.name ?? "").toString().trim().toLowerCase())
.filter(Boolean);
const count = normalizedNames.filter((n) => n === normalizedValue).length;
if (count > 1) {
throw new Error(t("bodyshop.errors.duplicate_insurance_company"));
}
return Promise.resolve();
}
})
]}
>
<Input />
@@ -1031,6 +1053,8 @@ export function ShopInfoGeneral({ form, bodyshop }) {
}}
</Form.List>
</LayoutFormRow>
{/*End Insurance Provider Row */}
<LayoutFormRow grow header={t("bodyshop.labels.estimators")} id="estimators">
<Form.List name={["md_estimators"]}>
{(fields, { add, remove, move }) => {

View File

@@ -9,23 +9,21 @@ import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
import { QUERY_OWNER_FOR_JOB_CREATION } from "../../graphql/owners.queries";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import InstanceRenderManager from "../../utils/instanceRenderMgr";
import JobsCreateComponent from "./jobs-create.component";
import JobCreateContext from "./jobs-create.context";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
import { logImEXEvent } from "../../firebase/firebase.utils";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser
bodyshop: selectBodyshop
});
const mapDispatchToProps = (dispatch) => ({
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
});
function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, currentUser }) {
function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
const { t } = useTranslation();
const notification = useNotification();
@@ -76,7 +74,7 @@ function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, curr
}, [t, setBreadcrumbs, setSelectedHeader]);
const runInsertJob = (job) => {
insertJob({ variables: { job } })
insertJob({ variables: { job: job } })
.then((resp) => {
setState({
...state,
@@ -152,11 +150,6 @@ function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, curr
if (job.owner === null) delete job.owner;
if (job.vehicle === null) delete job.vehicle;
// Associate to the current user if one exists
if (currentUser?.email) {
job.created_user_email = currentUser.email;
}
runInsertJob(job);
};

View File

@@ -277,7 +277,8 @@
"errors": {
"creatingdefaultview": "Error creating default view.",
"loading": "Unable to load shop details. Please call technical support.",
"saving": "Error encountered while saving. {{message}}"
"saving": "Error encountered while saving. {{message}}",
"duplicate_insurance_company": "Duplicate insurance company name. Each insurance company name must be unique"
},
"fields": {
"ReceivableCustomField": "QBO Receivable Custom Field {{number}}",

View File

@@ -277,7 +277,8 @@
"errors": {
"creatingdefaultview": "",
"loading": "No se pueden cargar los detalles de la tienda. Por favor llame al soporte técnico.",
"saving": ""
"saving": "",
"duplicate_insurance_company": ""
},
"fields": {
"ReceivableCustomField": "",

View File

@@ -277,7 +277,8 @@
"errors": {
"creatingdefaultview": "",
"loading": "Impossible de charger les détails de la boutique. Veuillez appeler le support technique.",
"saving": ""
"saving": "",
"duplicate_insurance_company": ""
},
"fields": {
"ReceivableCustomField": "",

View File

@@ -3684,7 +3684,6 @@
- completed_tasks
- converted
- created_at
- created_user_email
- cust_pr
- date_estimated
- date_exported
@@ -3962,7 +3961,6 @@
- completed_tasks
- converted
- created_at
- created_user_email
- cust_pr
- date_estimated
- date_exported
@@ -4253,7 +4251,6 @@
- completed_tasks
- converted
- created_at
- created_user_email
- cust_pr
- date_estimated
- date_exported
@@ -4644,7 +4641,7 @@
request_transform:
body:
action: transform
template: "{\r\n \"event\": {\r\n \"session_variables\": {\r\n \"x-hasura-user-id\": {{$body?.event?.session_variables?.x-hasura-user-id ?? \"Internal\"}},\r\n \"x-hasura-role\": {{$body?.event?.session_variables?.x-hasura-role ?? \"Internal\"}}\r\n }, \r\n \"op\": {{$body.event.op}},\r\n \"data\": {\r\n \"new\": {\r\n \"id\": {{$body.event.data.new.id}},\r\n \"shopid\": {{$body.event.data.new?.shopid}},\r\n \"ro_number\": {{$body.event.data.new?.ro_number}},\r\n \"created_user_email\": {{$body.event.data.new?.created_user_email}}\r\n }\r\n }\r\n },\r\n \"trigger\": {\r\n \"name\": \"notifications_jobs_autoadd\"\r\n },\r\n \"table\": {\r\n \"schema\": \"public\",\r\n \"name\": \"jobs\"\r\n }\r\n}\r\n"
template: "{\r\n \"event\": {\r\n \"session_variables\": {\r\n \"x-hasura-user-id\": {{$body?.event?.session_variables?.x-hasura-user-id ?? \"Internal\"}},\r\n \"x-hasura-role\": {{$body?.event?.session_variables?.x-hasura-role ?? \"Internal\"}}\r\n }, \r\n \"op\": {{$body.event.op}},\r\n \"data\": {\r\n \"new\": {\r\n \"id\": {{$body.event.data.new.id}},\r\n \"shopid\": {{$body.event.data.new?.shopid}},\r\n \"ro_number\": {{$body.event.data.new?.ro_number}}\r\n }\r\n }\r\n },\r\n \"trigger\": {\r\n \"name\": \"notifications_jobs_autoadd\"\r\n },\r\n \"table\": {\r\n \"schema\": \"public\",\r\n \"name\": \"jobs\"\r\n }\r\n}\r\n"
method: POST
query_params: {}
template_engine: Kriti

View File

@@ -1,4 +0,0 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."jobs" add column "created_user_email" text
-- null;

View File

@@ -1,2 +0,0 @@
alter table "public"."jobs" add column "created_user_email" text
null;

View File

@@ -3089,19 +3089,17 @@ exports.INSERT_JOB_WATCHERS = `
`;
exports.GET_NOTIFICATION_WATCHERS = `
query GET_NOTIFICATION_WATCHERS($shopId: uuid!, $employeeIds: [uuid!]!, $createdUserEmail: String!) {
query GET_NOTIFICATION_WATCHERS($shopId: uuid!, $employeeIds: [uuid!]!) {
associations(where: {
_and: [
{ shopid: { _eq: $shopId } },
{ active: { _eq: true } },
{ notifications_autoadd: { _eq: true } },
{ useremail: { _eq: $createdUserEmail } }
{ notifications_autoadd: { _eq: true } }
]
}) {
id
useremail
}
employees(where: { id: { _in: $employeeIds }, shopid: { _eq: $shopId }, active: { _eq: true } }) {
user_email
}

View File

@@ -39,7 +39,6 @@ const autoAddWatchers = async (req) => {
const jobId = event?.data?.new?.id;
const shopId = event?.data?.new?.shopid;
const roNumber = event?.data?.new?.ro_number || "unknown";
const createdUserEmail = event?.data?.new?.created_user_email || "Unknown";
if (!jobId || !shopId) {
throw new Error(`Missing jobId (${jobId}) or shopId (${shopId}) for auto-add watchers`);
@@ -62,8 +61,7 @@ const autoAddWatchers = async (req) => {
const [notificationData, existingWatchersData] = await Promise.all([
gqlClient.request(GET_NOTIFICATION_WATCHERS, {
shopId,
employeeIds: notificationFollowers,
createdUserEmail
employeeIds: notificationFollowers
}),
gqlClient.request(GET_JOB_WATCHERS_MINIMAL, { jobid: jobId })
]);