- Fix console warn, add two missing try catch blocks
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -176,7 +176,7 @@ export function TaskUpsertModalComponent({
|
|||||||
label={t("tasks.fields.assigned_to")}
|
label={t("tasks.fields.assigned_to")}
|
||||||
name="assigned_to"
|
name="assigned_to"
|
||||||
initialValue={
|
initialValue={
|
||||||
bodyshop.employees.find((employee) => employee.user_email === currentUser.email && employee.active)
|
bodyshop.employees.find((employee) => employee?.user_email === currentUser.email && employee.active)
|
||||||
? currentUser.email
|
? currentUser.email
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ export function TaskUpsertModalComponent({
|
|||||||
<Select
|
<Select
|
||||||
placeholder={t("tasks.placeholders.assigned_to")}
|
placeholder={t("tasks.placeholders.assigned_to")}
|
||||||
options={bodyshop.employees
|
options={bodyshop.employees
|
||||||
.filter((x) => x.active)
|
.filter((x) => x.active && x.user_email)
|
||||||
.map((employee) => ({
|
.map((employee) => ({
|
||||||
key: employee.id,
|
key: employee.id,
|
||||||
value: employee.user_email,
|
value: employee.user_email,
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import { selectTaskUpsert } from "../../redux/modals/modals.selectors";
|
|||||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||||
import TaskUpsertModalComponent from "./task-upsert-modal.component";
|
import TaskUpsertModalComponent from "./task-upsert-modal.component";
|
||||||
import { replaceUndefinedWithNull } from "../../utils/undefinedtonull.js";
|
import { replaceUndefinedWithNull } from "../../utils/undefinedtonull.js";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import axios from "axios";
|
|
||||||
import dayjs from "../../utils/day";
|
|
||||||
import { insertAuditTrail } from "../../redux/application/application.actions.js";
|
import { insertAuditTrail } from "../../redux/application/application.actions.js";
|
||||||
import AuditTrailMapping from "../../utils/AuditTrailMappings.js";
|
import AuditTrailMapping from "../../utils/AuditTrailMappings.js";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
@@ -42,6 +40,7 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
const [selectedJobDetails, setSelectedJobDetails] = useState(null);
|
const [selectedJobDetails, setSelectedJobDetails] = useState(null);
|
||||||
const [jobIdState, setJobIdState] = useState(null);
|
const [jobIdState, setJobIdState] = useState(null);
|
||||||
const [isTouched, setIsTouched] = useState(false);
|
const [isTouched, setIsTouched] = useState(false);
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const { loading, error, data } = useQuery(QUERY_GET_TASKS_JOB_DETAILS_BY_ID, {
|
const { loading, error, data } = useQuery(QUERY_GET_TASKS_JOB_DETAILS_BY_ID, {
|
||||||
variables: { id: jobIdState },
|
variables: { id: jobIdState },
|
||||||
@@ -108,6 +107,15 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
history(`${window.location.pathname}?${urlParams}`);
|
history(`${window.location.pathname}?${urlParams}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task Query Refetch function to determine if we need to refetch the task query
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
const taskQueryRefetch = () =>
|
||||||
|
(!jobid || !joblineid || !billid || !partsorderid || !taskId) &&
|
||||||
|
taskQuery &&
|
||||||
|
location.pathname.includes("/manage/tasks");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle existing task
|
* Handle existing task
|
||||||
* @param values
|
* @param values
|
||||||
@@ -135,7 +143,7 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
// We have a relationship query, so we need to refetch the query
|
// We have a relationship query, so we need to refetch the query
|
||||||
if (query && Object.keys(query).length) {
|
if (query && Object.keys(query).length) {
|
||||||
taskObject.refetchQueries.push(Object.keys(query)[0]);
|
taskObject.refetchQueries.push(Object.keys(query)[0]);
|
||||||
} else if (taskQuery) {
|
} else if (taskQueryRefetch()) {
|
||||||
taskObject.refetchQueries.push(taskQuery);
|
taskObject.refetchQueries.push(taskQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,29 +159,29 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAssignedToDirty) {
|
// if (isAssignedToDirty) {
|
||||||
// TODO This is being moved serverside
|
// // TODO This is being moved serverside
|
||||||
axios
|
// axios
|
||||||
.post("/sendemail", {
|
// .post("/sendemail", {
|
||||||
from: {
|
// from: {
|
||||||
name: bodyshop.shopname,
|
// name: bodyshop.shopname,
|
||||||
address: bodyshop.email
|
// address: bodyshop.email
|
||||||
},
|
// },
|
||||||
ReplyTo: {
|
// ReplyTo: {
|
||||||
Email: "noreply@imex.online"
|
// Email: "noreply@imex.online"
|
||||||
},
|
// },
|
||||||
to: values.assigned_to,
|
// to: values.assigned_to,
|
||||||
subject: `A Task has been re-assigned to you on ${bodyshop.shopname} - ${values.title}`,
|
// subject: `A Task has been re-assigned to you on ${bodyshop.shopname} - ${values.title}`,
|
||||||
templateStrings: {
|
// templateStrings: {
|
||||||
header: values.title,
|
// header: values.title,
|
||||||
subHeader: `Assigned by ${currentUser.email} ${values.due_at ? `| Due on ${dayjs(values.due_at).format("MM/DD/YYYY")}` : ""}`,
|
// subHeader: `Assigned by ${currentUser.email} ${values.due_at ? `| Due on ${dayjs(values.due_at).format("MM/DD/YYYY")}` : ""}`,
|
||||||
body: `<a href="${window.location.protocol}//${window.location.host}/manage/tasks/alltasks?taskid=${existingTask.id}">Please sign in to your account to view the task details.</a>`
|
// body: `<a href="${window.location.protocol}//${window.location.host}/manage/tasks/alltasks?taskid=${existingTask.id}">Please sign in to your account to view the task details.</a>`
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.catch((e) =>
|
// .catch((e) =>
|
||||||
console.error(`Something went wrong sending email to Assigned party on Task creation. ${e.message || ""}`)
|
// console.error(`Something went wrong sending email to Assigned party on Task creation. ${e.message || ""}`)
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
notification["success"]({
|
notification["success"]({
|
||||||
message: t("tasks.successes.updated")
|
message: t("tasks.successes.updated")
|
||||||
@@ -182,6 +190,11 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
toggleModalVisible();
|
toggleModalVisible();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle new task
|
||||||
|
* @param values
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
const handleNewTask = async (values) => {
|
const handleNewTask = async (values) => {
|
||||||
const newTaskObject = {
|
const newTaskObject = {
|
||||||
variables: {
|
variables: {
|
||||||
@@ -207,12 +220,11 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
// We have a relationship query, so we need to refetch the query
|
// We have a relationship query, so we need to refetch the query
|
||||||
if (query && Object.keys(query).length) {
|
if (query && Object.keys(query).length) {
|
||||||
newTaskObject.refetchQueries.push(Object.keys(query)[0]);
|
newTaskObject.refetchQueries.push(Object.keys(query)[0]);
|
||||||
} else if (taskQuery) {
|
} else if (taskQueryRefetch()) {
|
||||||
newTaskObject.refetchQueries.push(taskQuery);
|
newTaskObject.refetchQueries.push(taskQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newTaskData = await insertTask(newTaskObject);
|
const newTaskData = await insertTask({ ...newTaskObject });
|
||||||
|
|
||||||
const newTask = newTaskData?.data?.insert_tasks?.returning[0];
|
const newTask = newTaskData?.data?.insert_tasks?.returning[0];
|
||||||
const newTaskID = newTask?.id;
|
const newTaskID = newTask?.id;
|
||||||
|
|
||||||
@@ -229,27 +241,27 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
|
|
||||||
// send notification to the assigned user
|
// send notification to the assigned user
|
||||||
// TODO: This is being moved serverside
|
// TODO: This is being moved serverside
|
||||||
axios
|
// axios
|
||||||
.post("/sendemail", {
|
// .post("/sendemail", {
|
||||||
from: {
|
// from: {
|
||||||
name: bodyshop.shopname,
|
// name: bodyshop.shopname,
|
||||||
address: bodyshop.email
|
// address: bodyshop.email
|
||||||
},
|
// },
|
||||||
replyTo: {
|
// replyTo: {
|
||||||
Email: "noreply@imex.online"
|
// Email: "noreply@imex.online"
|
||||||
},
|
// },
|
||||||
to: values.assigned_to,
|
// to: values.assigned_to,
|
||||||
subject: `A new Task has been assigned to you on ${bodyshop.shopname} - ${values.title}`,
|
// subject: `A new Task has been assigned to you on ${bodyshop.shopname} - ${values.title}`,
|
||||||
templateName: "taskAssigned",
|
// templateName: "taskAssigned",
|
||||||
templateStrings: {
|
// templateStrings: {
|
||||||
header: values.title,
|
// header: values.title,
|
||||||
subHeader: `Assigned by ${currentUser.email} ${values.due_at ? `| Due on ${dayjs(values.due_at).format("MM/DD/YYYY")}` : ""}`,
|
// subHeader: `Assigned by ${currentUser.email} ${values.due_at ? `| Due on ${dayjs(values.due_at).format("MM/DD/YYYY")}` : ""}`,
|
||||||
body: `<a href="${window.location.protocol}//${window.location.host}/manage/tasks/alltasks?taskid=${newTaskID}">Please sign to your account to view the task details.</a>`
|
// body: `<a href="${window.location.protocol}//${window.location.host}/manage/tasks/alltasks?taskid=${newTaskID}">Please sign to your account to view the task details.</a>`
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.catch((e) =>
|
// .catch((e) =>
|
||||||
console.error(`Something went wrong sending email to Assigned party on Task edit. ${e.message || ""}`)
|
// console.error(`Something went wrong sending email to Assigned party on Task edit. ${e.message || ""}`)
|
||||||
);
|
// );
|
||||||
|
|
||||||
notification["success"]({
|
notification["success"]({
|
||||||
message: t("tasks.successes.created")
|
message: t("tasks.successes.created")
|
||||||
@@ -269,9 +281,21 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
|||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
await handleExistingTask(dirtyValues);
|
try {
|
||||||
|
await handleExistingTask(dirtyValues);
|
||||||
|
} catch (e) {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("tasks.failures.updated")
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await handleNewTask(formValues);
|
try {
|
||||||
|
await handleNewTask(formValues);
|
||||||
|
} catch (e) {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("tasks.failures.created")
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user