Finish Approval Workflow builder for the most part. TODO: implement permissions

This commit is contained in:
Joao Correia
2025-01-24 00:33:45 +00:00
parent dcd25465fd
commit f6b0c96b3b
3 changed files with 80 additions and 37 deletions

View File

@@ -10,6 +10,7 @@ import { BsChevronLeft, BsTrash } from "react-icons/bs";
import { ToastContainer } from "react-toastify";
import { v4 as uuidv4 } from 'uuid';
import Tip from "@/components/ApprovalWorkflows/Tip";
import WorkflowForm from "@/components/ApprovalWorkflows/WorkflowForm";
import Button from "@/components/Low/Button";
import Input from "@/components/Low/Input";
@@ -19,6 +20,7 @@ import { Entity } from "@/interfaces/entity";
import { CorporateUser, TeacherUser, User } from "@/interfaces/user";
import { getEntities } from "@/utils/entities.be";
import { getEntitiesUsers } from "@/utils/users.be";
import { LayoutGroup, motion } from "framer-motion";
import { useEffect, useState } from "react";
import { MdFormatListBulletedAdd } from "react-icons/md";
@@ -116,9 +118,12 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
const handleDeleteWorkflow = (id: string) => {
if (!confirm(`Are you sure you want to delete this Approval Workflow?`)) return;
setWorkflows(prev => prev.filter(wf => wf.id !== id));
const updatedWorkflows = workflows.filter(wf => wf.id !== id);
setWorkflows(updatedWorkflows);
if (selectedWorkflowId === id) {
workflows.length > 0 ? setSelectedWorkflowId(workflows[0].id) : setSelectedWorkflowId(undefined);
setSelectedWorkflowId(updatedWorkflows.find(wf => wf.id)?.id);
}
};
@@ -212,15 +217,15 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
: ENTITY_OPTIONS.find(option => option.value === currentWorkflow.entityId)
}
onChange={(selectedEntity) => {
if (selectedEntity?.value) {
if (!currentWorkflow.entityId && selectedEntity?.value) {
setEntityId(selectedEntity.value);
const updatedWorkflow = {
...currentWorkflow,
entityId: selectedEntity.value,
};
onWorkflowChange(updatedWorkflow);
} else if (selectedEntity === null) {
if (!confirm("Clearing entity will reset this workflow. Are you sure you want to proceed?")) return;
} else {
if (!confirm("Clearing or changing entity will reset this workflow. Are you sure you want to proceed?")) return;
handleResetWorkflow(currentWorkflow.id);
}
}}
@@ -239,12 +244,34 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
</Button>
</div>
<WorkflowForm
workflow={currentWorkflow}
onWorkflowChange={onWorkflowChange}
entityTeachers={entityTeachers}
entityCorporates={entityCorporates}
/>
<LayoutGroup>
{(!currentWorkflow.name || !currentWorkflow.entityId) && (
<motion.div
key={0}
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
<Tip text="Please fill workflow name and associated entity to start configuring workflow." />
</motion.div>
)}
<motion.div
key={1}
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
<WorkflowForm
workflow={currentWorkflow}
onWorkflowChange={onWorkflowChange}
entityTeachers={entityTeachers}
entityCorporates={entityCorporates}
/>
</motion.div>
</LayoutGroup>
</>
)}
</form>