Update assigned_to handling on front end & debug task assignment.

This commit is contained in:
Patrick Fic
2024-04-19 09:22:20 -07:00
parent fb322f760f
commit 2a8846297f
24 changed files with 88 additions and 34 deletions

View File

@@ -236,6 +236,7 @@ export function ReportCenterModalComponent({ reportCenterModal, bodyshop }) {
<EmployeeSearchSelect options={employeeData ? employeeData.employees : []} />
</Form.Item>
);
//This was introduced with tasks before assigned_to was shifted to UUID. Keeping in place for reference in the future if needed.
if (idtype === "employeeWithEmail")
return (
<Form.Item

View File

@@ -149,7 +149,7 @@ function TaskListComponent({
sorter: true,
sortOrder: sortcolumn === "assigned_to" && sortorder,
render: (text, record) => {
const employee = bodyshop?.employees?.find((e) => e.user_email === record.assigned_to);
const employee = bodyshop?.employees?.find((e) => e.id === record.assigned_to);
return employee ? `${employee.first_name} ${employee.last_name}` : t("general.labels.na");
}
});

View File

@@ -48,8 +48,8 @@ export function TaskListContainer({
bodyshop: bodyshop.id,
[relationshipType]: relationshipId,
deleted: deleted === "true",
completed: completed === "true",
assigned_to: mine === "true" ? currentUser.email : undefined, // replace currentUserID with the actual ID of the current user
completed: completed === "true", //TODO: Find where mine is set.
assigned_to: onlyMine ? bodyshop?.employees?.find((e) => e.user_email === currentUser.email)?.id : undefined, // replace currentUserID with the actual ID of the current user
offset: page ? (page - 1) * pageLimit : 0,
limit: pageLimit,
order: [

View File

@@ -224,9 +224,7 @@ export function TaskUpsertModalComponent({
label={t("tasks.fields.assigned_to")}
name="assigned_to"
initialValue={
bodyshop.employees.find((employee) => employee?.user_email === currentUser.email && employee.active)
? currentUser.email
: undefined
bodyshop.employees.find((employee) => employee?.user_email === currentUser.email && employee.active)?.id
}
rules={[
{
@@ -240,7 +238,7 @@ export function TaskUpsertModalComponent({
.filter((x) => x.active && x.user_email)
.map((employee) => ({
key: employee.id,
value: employee.user_email,
value: employee.id,
label: `${employee.first_name} ${employee.last_name}`
}))}
/>

View File

@@ -12,6 +12,10 @@ export const PARTIAL_TASK_FIELDS = gql`
due_date
created_by
assigned_to
assigned_to_employee {
id
user_email
}
completed
completed_at
remind_at
@@ -80,7 +84,7 @@ export const QUERY_ALL_TASKS_PAGINATED = gql`
$bodyshop: uuid!
$deleted: Boolean
$completed: Boolean
$assigned_to: String
$assigned_to: uuid
$order: [tasks_order_by!]!
) {
tasks(
@@ -121,7 +125,7 @@ export const QUERY_JOBLINE_TASKS_PAGINATED = gql`
$bodyshop: uuid!
$deleted: Boolean
$completed: Boolean
$assigned_to: String
$assigned_to: uuid
$order: [tasks_order_by!]!
) {
tasks(
@@ -164,7 +168,7 @@ export const QUERY_PARTSORDER_TASKS_PAGINATED = gql`
$bodyshop: uuid!
$deleted: Boolean
$completed: Boolean
$assigned_to: String
$assigned_to: uuid
$order: [tasks_order_by!]!
) {
tasks(
@@ -207,7 +211,7 @@ export const QUERY_BILL_TASKS_PAGINATED = gql`
$bodyshop: uuid!
$deleted: Boolean
$completed: Boolean
$assigned_to: String
$assigned_to: uuid
$order: [tasks_order_by!]!
) {
tasks(
@@ -250,7 +254,7 @@ export const QUERY_JOB_TASKS_PAGINATED = gql`
$bodyshop: uuid!
$deleted: Boolean
$completed: Boolean
$assigned_to: String
$assigned_to: uuid
$order: [tasks_order_by!]!
) {
tasks(
@@ -288,7 +292,7 @@ export const QUERY_MY_TASKS_PAGINATED = gql`
query QUERY_MY_TASKS_PAGINATED(
$offset: Int
$limit: Int
$user: String!
$assigned_to: uuid!
$bodyshop: uuid!
$deleted: Boolean
$completed: Boolean
@@ -299,7 +303,7 @@ export const QUERY_MY_TASKS_PAGINATED = gql`
limit: $limit
order_by: $order
where: {
assigned_to: { _eq: $user }
assigned_to: { _eq: $assigned_to }
bodyshopid: { _eq: $bodyshop }
deleted: { _eq: $deleted }
completed: { _eq: $completed }
@@ -309,7 +313,7 @@ export const QUERY_MY_TASKS_PAGINATED = gql`
}
tasks_aggregate(
where: {
assigned_to: { _eq: $user }
assigned_to: { _eq: $assigned_to }
bodyshopid: { _eq: $bodyshop }
deleted: { _eq: $deleted }
completed: { _eq: $completed }

View File

@@ -3,24 +3,25 @@ import TaskListContainer from "../../components/task-list/task-list.container.js
import { QUERY_ALL_TASKS_PAGINATED, QUERY_MY_TASKS_PAGINATED } from "../../graphql/tasks.queries.js";
import taskPageTypes from "./taskPageTypes.jsx";
import { createStructuredSelector } from "reselect";
import { selectCurrentUser } from "../../redux/user/user.selectors.js";
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors.js";
import { connect } from "react-redux";
const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser
currentUser: selectCurrentUser,
bodyshop: selectBodyshop
});
const mapDispatchToProps = (dispatch) => ({});
export default connect(mapStateToProps, mapDispatchToProps)(TasksPageComponent);
export function TasksPageComponent({ currentUser, type }) {
export function TasksPageComponent({ bodyshop, currentUser, type }) {
switch (type) {
case taskPageTypes.MY_TASKS:
return (
<TaskListContainer
onlyMine={true}
relationshipId={currentUser.email}
relationshipType={"user"}
relationshipId={bodyshop?.employees?.find((e) => e.user_email === currentUser.email)?.id}
relationshipType={"assigned_to"}
query={{ QUERY_MY_TASKS_PAGINATED }}
titleTranslation={"tasks.titles.my_tasks"}
disableJobRefetch={true}

View File

@@ -2114,7 +2114,7 @@ export const TemplateList = (type, context) => {
title: i18n.t("reportcenter.templates.tasks_date_employee"),
subject: i18n.t("reportcenter.templates.tasks_date_employee"),
key: "tasks_date_employee",
idtype: "employeeWithEmail",
idtype: "employee",
disabled: false,
rangeFilter: {
object: i18n.t("reportcenter.labels.objects.tasks"),

View File

@@ -2335,6 +2335,13 @@
table:
name: jobs
schema: public
- name: tasks
using:
foreign_key_constraint_on:
column: assigned_to
table:
name: tasks
schema: public
- name: timetickets
using:
foreign_key_constraint_on:
@@ -5678,15 +5685,15 @@
name: tasks
schema: public
object_relationships:
- name: assigned_to_employee
using:
foreign_key_constraint_on: assigned_to
- name: bill
using:
foreign_key_constraint_on: billid
- name: bodyshop
using:
foreign_key_constraint_on: bodyshopid
- name: employee
using:
foreign_key_constraint_on: assigned_to
- name: job
using:
foreign_key_constraint_on: jobid
@@ -5736,6 +5743,7 @@
- role: user
permission:
columns:
- assigned_to
- billid
- bodyshopid
- completed
@@ -5807,7 +5815,7 @@
columns: '*'
update:
columns:
- bodyshopid
- assigned_to
retry_conf:
interval_sec: 10
num_retries: 3

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_jobid";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_jobid" on
"public"."tasks" using btree ("jobid");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_assigned-to";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_assigned-to" on
"public"."tasks" using btree ("assigned_to");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_joblineid";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_joblineid" on
"public"."tasks" using btree ("joblineid");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_partsorderid";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_partsorderid" on
"public"."tasks" using btree ("partsorderid");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_remind_at";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_remind_at" on
"public"."tasks" using btree ("remind_at");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_remind_at_sent";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_remind_at_sent" on
"public"."tasks" using btree ("remind_at_sent");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."tasks_bodyshopid";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "tasks_bodyshopid" on
"public"."tasks" using btree ("bodyshopid");

View File

@@ -105,8 +105,8 @@ const formatPriority = (priority) => {
const generateTemplateArgs = (title, priority, description, dueDate, taskId) => {
return {
header: title,
subHeader: `Priority: ${formatPriority(priority)} ${priority} ${formatDate(dueDate)}`,
body: `${description}<br><a href="${endPoints}/manage/tasks/alltasks?taskid=${taskId}">Please sign in to your account to view the further details of the Task.</a>`
subHeader: `Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`,
body: `${description || ""}<br><a href="${endPoints}/manage/tasks/alltasks?taskid=${taskId}">View this task.</a>`
};
};
@@ -154,19 +154,26 @@ const sendMail = (type, to, subject, html, taskIds, successCallback) => {
*/
const taskAssignedEmail = async (req, res) => {
// We have no event Data, bail
if (!req?.payload?.event?.data?.new) {
return res.status(400).json({ message: "No data in the event payload" });
if (!req?.body?.event?.data?.new) {
return res.status(400).json({ message: "No data in the event body" });
}
const { new: newTask } = req.payload.event.data;
const { new: newTask } = req.body.event.data;
// This is not a new task, but a reassignment.
const dirty = req.payload.event.data?.old && req.payload.event.data?.old?.assigned_to;
const dirty = req.body.event.data?.old && req.body.event.data?.old?.assigned_to;
//Query to get the employee assigned currently.
const {
employees_by_pk: { user_email }
} = await client.request(queries.QUERY_EMPLOYEE_EMAIL_BY_ID, {
id: newTask.assigned_to
});
sendMail(
"assigned",
newTask.assigned_to,
`A ${formatPriority(newTask.priority)} PriorityTask has been ${dirty ? "reassigned" : "created"} for you - ${newTask.title}`,
user_email,
`A ${formatPriority(newTask.priority)} priority task has been ${dirty ? "reassigned to" : "created for"} you - ${newTask.title}`,
generateEmailTemplate(
generateTemplateArgs(newTask.title, newTask.priority, newTask.description, newTask.due_date, newTask.id)
)
@@ -195,7 +202,7 @@ const tasksRemindEmail = async (req, res) => {
// Group tasks by assigned_to, to avoid sending multiple emails to the same recipient.
const groupedTasks = tasksRequest.tasks.reduce((acc, task) => {
const key = task.assigned_to;
const key = task.assigned_to_email.user_email;
if (!acc[key]) {
acc[key] = [];
}

View File

@@ -2411,6 +2411,10 @@ exports.QUERY_REMIND_TASKS = `
due_date
created_by
assigned_to
assigned_to_employee {
id
user_email
}
remind_at
remind_at_sent
priority
@@ -2428,3 +2432,13 @@ exports.UPDATE_TASKS_REMIND_AT_SENT = `mutation UPDATE_TASK_REMIND_AT_SENT($task
affected_rows
}
}`;
exports.QUERY_EMPLOYEE_EMAIL_BY_ID = `
query QUERY_EMPLOYEE_EMAIL_BY_ID($id: uuid!) {
employees_by_pk(id: $id) {
id
user_email
}
}
`;