on workflow builder, only render steps if name and entity are set. reset workflow on entity reset.

This commit is contained in:
Joao Correia
2025-01-23 22:56:45 +00:00
parent c921d54d50
commit dcd25465fd
2 changed files with 74 additions and 58 deletions

View File

@@ -51,7 +51,7 @@ interface Props {
export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers, userEntitiesCorporates }: Props) {
const [workflows, setWorkflows] = useState<ApprovalWorkflow[]>([]);
const [selectedWorkflowId, setSelectedWorkflowId] = useState<string | undefined>(undefined);
const [entityId, setEntityId] = useState<string | undefined>(undefined);
const [entityId, setEntityId] = useState<string | null | undefined>(null);
const [entityTeachers, setEntityTeachers] = useState<TeacherUser[]>([]);
const [entityCorporates, setEntityCorporates] = useState<CorporateUser[]>([]);
@@ -122,6 +122,11 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
}
};
const handleResetWorkflow = (id: string) => {
setWorkflows(prev => prev.filter(wf => wf.id !== id));
handleAddNewWorkflow();
}
return (
<>
<Head>
@@ -201,6 +206,11 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
/>
<Select
options={ENTITY_OPTIONS}
value={
currentWorkflow.entityId === ""
? null
: ENTITY_OPTIONS.find(option => option.value === currentWorkflow.entityId)
}
onChange={(selectedEntity) => {
if (selectedEntity?.value) {
setEntityId(selectedEntity.value);
@@ -209,6 +219,9 @@ export default function Home({ user, userEntitiesWithLabel, userEntitiesTeachers
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;
handleResetWorkflow(currentWorkflow.id);
}
}}
isClearable