diff --git a/src/components/ApprovalWorkflows/WorkflowEditableStepComponent.tsx b/src/components/ApprovalWorkflows/WorkflowEditableStepComponent.tsx
index 511ff65e..1f208321 100644
--- a/src/components/ApprovalWorkflows/WorkflowEditableStepComponent.tsx
+++ b/src/components/ApprovalWorkflows/WorkflowEditableStepComponent.tsx
@@ -1,12 +1,12 @@
import { WorkflowStep } from "@/interfaces/approval.workflow";
import Option from "@/interfaces/option";
-import { useEffect, useState } from "react";
+import { CorporateUser, TeacherUser } from "@/interfaces/user";
+import { useMemo, useState } from "react";
+import { AiOutlineUserAdd } from "react-icons/ai";
import { BsTrash } from "react-icons/bs";
import { LuGripHorizontal } from "react-icons/lu";
import WorkflowStepNumber from "./WorkflowStepNumber";
import WorkflowStepSelects from "./WorkflowStepSelects";
-import { CorporateUser, TeacherUser } from "@/interfaces/user";
-import { AiOutlineUserAdd } from "react-icons/ai";
interface Props extends WorkflowStep {
entityTeachers: TeacherUser[];
@@ -15,7 +15,6 @@ interface Props extends WorkflowStep {
}
export default function WorkflowEditableStepComponent({
- stepType,
stepNumber,
finalStep,
onDelete,
@@ -26,7 +25,42 @@ export default function WorkflowEditableStepComponent({
const [selects, setSelects] = useState<(Option | null | undefined)[]>([null]);
- const showSelects = stepType === "approval-by";
+ const teacherOptions: Option[] = useMemo(() =>
+ entityTeachers
+ .map((teacher) => ({
+ value: teacher.id,
+ label: teacher.name,
+ icon: () =>
+ }))
+ .sort((a, b) => a.label.localeCompare(b.label)),
+ [entityTeachers]
+ );
+
+ const corporateOptions: Option[] = useMemo(() =>
+ entityCorporates
+ .map((corporate) => ({
+ value: corporate.id,
+ label: corporate.name,
+ icon: () =>
+ }))
+ .sort((a, b) => a.label.localeCompare(b.label)),
+ [entityCorporates]
+ );
+
+ const selectedValues = useMemo(() =>
+ selects.filter((opt): opt is Option => !!opt).map(opt => opt.value),
+ [selects]
+ );
+
+ const availableTeacherOptions = useMemo(() =>
+ teacherOptions.filter(opt => !selectedValues.includes(opt.value)),
+ [teacherOptions, selectedValues]
+ );
+
+ const availableCorporateOptions = useMemo(() =>
+ corporateOptions.filter(opt => !selectedValues.includes(opt.value)),
+ [corporateOptions, selectedValues]
+ );
const handleAddSelectComponent = () => {
setSelects((prev) => {
@@ -59,52 +93,34 @@ export default function WorkflowEditableStepComponent({
:
}
- {showSelects && (
-
-
-
- )}
+
+
+
- {stepNumber === 1 && (
-
-
- {/* h-[40px] probably is not the best way to match the height with the select component, but for now should be ok */}
-
- Form Intake
-
-
- Prof. X
-
-
-
- )}
-
- {stepNumber !== 1 && (
-
+
+
+ {stepNumber !== 1 && !finalStep && (
- {!finalStep && (
-
- )}
-
- )}
-
+ )}
+
);
diff --git a/src/components/ApprovalWorkflows/WorkflowForm.tsx b/src/components/ApprovalWorkflows/WorkflowForm.tsx
index 505915af..838319f6 100644
--- a/src/components/ApprovalWorkflows/WorkflowForm.tsx
+++ b/src/components/ApprovalWorkflows/WorkflowForm.tsx
@@ -111,7 +111,7 @@ export default function WorkflowForm({ workflow, onWorkflowChange, entityTeacher
variant="solid"
onClick={addStep}
type="button"
- className="max-w-fit text-lg font-medium flex items-center gap-2 text-left"
+ className="max-w-fit text-lg font-medium flex items-center gap-2 text-left mb-8"
>
Add Step
diff --git a/src/components/ApprovalWorkflows/WorkflowStepSelects.tsx b/src/components/ApprovalWorkflows/WorkflowStepSelects.tsx
index 155d8bd6..c0ebc585 100644
--- a/src/components/ApprovalWorkflows/WorkflowStepSelects.tsx
+++ b/src/components/ApprovalWorkflows/WorkflowStepSelects.tsx
@@ -1,11 +1,11 @@
import Option from "@/interfaces/option";
import Select from "../Low/Select";
-import { CorporateUser, TeacherUser } from "@/interfaces/user";
interface Props {
- teachers: TeacherUser[];
- corporates: CorporateUser[];
+ teachers: Option[];
+ corporates: Option[];
selects: (Option | null | undefined)[];
+ placeholder: string;
onSelectChange: (numberOfSelects: number, index: number, value: Option | null) => void;
}
@@ -13,20 +13,10 @@ export default function WorkflowStepSelects({
teachers,
corporates,
selects,
+ placeholder,
onSelectChange,
}: Props) {
- const teacherOptions: Option[] = teachers.map((teacher) => ({
- value: teacher.id,
- label: teacher.name,
- icon: () =>
- }));
- const corporateOptions: Option[] = corporates.map((corporate) => ({
- value: corporate.id,
- label: corporate.name,
- icon: () =>
- }));
-
return (
+