- Tasks Audit Trail Additions
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -18,6 +18,8 @@ import {replaceUndefinedWithNull} from "../../utils/undefinedtonull.js";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import axios from "axios";
|
||||
import dayjs from '../../utils/day';
|
||||
import {insertAuditTrail} from "../../redux/application/application.actions.js";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
@@ -26,6 +28,8 @@ const mapStateToProps = createStructuredSelector({
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("taskUpsert")),
|
||||
insertAuditTrail: ({ jobid, billid, operation, type }) =>
|
||||
dispatch(insertAuditTrail({ jobid, billid, operation, type }))
|
||||
});
|
||||
|
||||
export function TaskUpsertModalContainer({
|
||||
@@ -33,6 +37,7 @@ export function TaskUpsertModalContainer({
|
||||
currentUser,
|
||||
taskUpsert,
|
||||
toggleModalVisible,
|
||||
insertAuditTrail
|
||||
}) {
|
||||
const {t} = useTranslation();
|
||||
const history = useNavigate();
|
||||
@@ -123,14 +128,28 @@ export function TaskUpsertModalContainer({
|
||||
const handleExistingTask = async (values) => {
|
||||
const isAssignedToDirty = values.assigned_to !== existingTask.assigned_to;
|
||||
|
||||
await updateTask({
|
||||
const taskData = await updateTask({
|
||||
variables: {
|
||||
taskId: existingTask.id,
|
||||
task: replaceUndefinedWithNull(values)
|
||||
},
|
||||
});
|
||||
|
||||
if (!taskData.errors) {
|
||||
const oldTask = taskData?.data?.update_tasks?.returning[0];
|
||||
|
||||
insertAuditTrail({
|
||||
jobid: oldTask.jobid,
|
||||
operation: AuditTrailMapping.tasksUpdated(
|
||||
oldTask.title,
|
||||
currentUser.email
|
||||
),
|
||||
type: "tasksUpdated"
|
||||
});
|
||||
}
|
||||
|
||||
if (isAssignedToDirty) {
|
||||
// TODO This is being moved serverside
|
||||
axios.post("/sendemail", {
|
||||
from: {
|
||||
name: bodyshop.shopname,
|
||||
@@ -163,7 +182,7 @@ export function TaskUpsertModalContainer({
|
||||
};
|
||||
|
||||
const handleNewTask = async (values) => {
|
||||
const newTaskID = (await insertTask({
|
||||
const newTaskData = await insertTask({
|
||||
variables: {
|
||||
taskInput: [
|
||||
{
|
||||
@@ -173,30 +192,29 @@ export function TaskUpsertModalContainer({
|
||||
},
|
||||
],
|
||||
},
|
||||
// TODO: Consult Patrick, because this fails on relationship data, and an event emitter is just much easier to use
|
||||
// update(cache) {
|
||||
// cache.modify({
|
||||
// fields: {
|
||||
// tasks(existingTasks) {
|
||||
// return [{
|
||||
// ...values,
|
||||
// jobid: selectedJobId || values.jobid,
|
||||
// created_by: currentUser.email,
|
||||
// bodyshopid: bodyshop.id
|
||||
// }, ...existingTasks]
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
})).data.insert_tasks.returning[0].id;
|
||||
|
||||
});
|
||||
|
||||
const newTask = newTaskData?.data?.insert_tasks?.returning[0];
|
||||
const newTaskID = newTask?.id;
|
||||
|
||||
if (!newTaskData.errors) {
|
||||
insertAuditTrail({
|
||||
jobid: newTask.jobid,
|
||||
operation: AuditTrailMapping.tasksCreated(
|
||||
newTask.title,
|
||||
currentUser.email
|
||||
),
|
||||
type: "tasksCreated"
|
||||
});
|
||||
}
|
||||
|
||||
if (refetch) await refetch();
|
||||
|
||||
form.resetFields();
|
||||
|
||||
toggleModalVisible();
|
||||
|
||||
|
||||
// send notification to the assigned user
|
||||
// TODO: This is being moved serverside
|
||||
axios.post("/sendemail", {
|
||||
from: {
|
||||
name: bodyshop.shopname,
|
||||
|
||||
Reference in New Issue
Block a user