switch to mongo's id handling

This commit is contained in:
Joao Correia
2025-01-30 11:50:28 +00:00
parent 5d727fc528
commit c968044160
6 changed files with 29 additions and 32 deletions

View File

@@ -108,7 +108,7 @@ export default function Home({ user, workflow, userEntitiesWithLabel, userEntiti
}));
const editableWorkflow: EditableApprovalWorkflow = {
id: uuidv4(),
id: uuidv4(), // this id is only used in UI. it is ommited on submission to DB and lets mongo handle unique id.
name: workflow.name,
entityId: workflow.entityId,
requester: user.id,
@@ -141,7 +141,7 @@ export default function Home({ user, workflow, userEntitiesWithLabel, userEntiti
};
axios
.post(`/api/approval-workflows/${workflow.id}/clone`, filteredWorkflow)
.post(`/api/approval-workflows/${workflow._id}/clone`, filteredWorkflow)
.then(() => {
toast.success("Approval Workflow cloned successfully.");
setIsRedirecting(true);

View File

@@ -71,7 +71,7 @@ export default function Home({ user, workflow, workflowEntityTeachers, workflowE
}));
const editableWorkflow: EditableApprovalWorkflow = {
id: workflow.id,
id: workflow._id?.toString() ?? "",
name: workflow.name,
entityId: workflow.entityId,
requester: user.id, // should it change to the editor?
@@ -104,7 +104,7 @@ export default function Home({ user, workflow, workflowEntityTeachers, workflowE
};
axios
.put(`/api/approval-workflows/${workflow.id}/edit`, filteredWorkflow)
.put(`/api/approval-workflows/${updatedWorkflow.id}/edit`, filteredWorkflow)
.then(() => {
toast.success("Approval Workflow edited successfully.");
setIsRedirecting(true);

View File

@@ -137,7 +137,7 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
if (isAdding) return;
setIsAdding(true);
const newId = uuidv4();
const newId = uuidv4(); // this id is only used in UI. it is ommited on submission to DB and lets mongo handle unique id.
const newWorkflow: EditableApprovalWorkflow = {
id: newId,
name: "",

View File

@@ -145,7 +145,8 @@ export default function ApprovalWorkflows({ user, workflows, workflowsAssignees,
setNameFilter(name);
};
const deleteApprovalWorkflow = (id: string, name: string) => {
const deleteApprovalWorkflow = (id: string | undefined, name: string) => {
if (id === undefined) return;
if (!confirm(`Are you sure you want to delete this Approval Workflow?`)) return;
axios
@@ -267,7 +268,7 @@ export default function ApprovalWorkflows({ user, workflows, workflowsAssignees,
className="cursor-pointer tooltip"
onClick={(e) => {
e.stopPropagation();
deleteApprovalWorkflow(row.original.id, row.original.name);
deleteApprovalWorkflow(row.original._id?.toString(), row.original.name);
}}
>
<BsTrash className="hover:text-mti-purple-light transition ease-in-out duration-300" />
@@ -276,7 +277,7 @@ export default function ApprovalWorkflows({ user, workflows, workflowsAssignees,
<Link
onClick={(e) => e.stopPropagation()}
data-tip="Clone"
href={`/approval-workflows/${row.original.id}/clone`}
href={`/approval-workflows/${row.original._id?.toString()}/clone`}
className="cursor-pointer tooltip"
>
<FaRegClone className="hover:text-mti-purple-light transition ease-in-out duration-300" />
@@ -286,7 +287,7 @@ export default function ApprovalWorkflows({ user, workflows, workflowsAssignees,
<Link
onClick={(e) => e.stopPropagation()}
data-tip="Edit"
href={`/approval-workflows/${row.original.id}/edit`}
href={`/approval-workflows/${row.original._id?.toString()}/edit`}
className="cursor-pointer tooltip"
>
<FaRegEdit className="hover:text-mti-purple-light transition ease-in-out duration-300" />
@@ -391,7 +392,7 @@ export default function ApprovalWorkflows({ user, workflows, workflowsAssignees,
{table.getRowModel().rows.map((row) => (
<tr
key={row.id}
onClick={() => window.location.href = `/approval-workflows/${row.original.id}`}
onClick={() => window.location.href = `/approval-workflows/${row.original._id?.toString()}`}
style={{ cursor: "pointer" }}
className="bg-purple-50"
>