diff --git a/src/App.tsx b/src/App.tsx index 7ba2641..8ddda54 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -380,6 +380,14 @@ function GetSecureRoutes() { } /> + + + + } + /> = ({ editMode, }) => { const { t } = useTranslation(Namespaces.Common); - const { userId } = useParams<{ userId: string }>(); + const { workflowTemplateId } = useParams<{ workflowTemplateId: string }>(); const [activeTab, setActiveTab] = React.useState("general"); const [taskValidation, setTaskValidation] = useState>( @@ -43,7 +44,7 @@ const WorkflowTemplateDetails: React.FC<{ editMode: boolean }> = ({ activityNameTemplate: "", description: "", tasks: [] as TaskDefinition[], - } as CreateWorkflowTemplateVersion, + } as CreateWorkflowTemplateVersion | ReadWorkflowTemplateVersion, errors: {}, redirect: "", }); @@ -67,38 +68,46 @@ const WorkflowTemplateDetails: React.FC<{ editMode: boolean }> = ({ description: Joi.string().required().allow("").label(t("Description")), domainId: Joi.required(), tasks: Joi.array().required(), + deleted: Joi.boolean().optional(), + guid: Joi.string().optional(), + id: Joi.number().optional(), + lastUpdated: Joi.date().optional(), + version: Joi.number().optional(), + workflowId: Joi.optional(), + }; + + const load = async () => { + let newData: CreateWorkflowTemplateVersion | ReadWorkflowTemplateVersion = { + ...form.state.data, + }; + + if (editMode && workflowTemplateId) { + try { + const loadedData = await templateVersionsService.getTemplateVersion( + BigInt(workflowTemplateId), + ); + + if (loadedData) { + newData = loadedData; + } + } catch (ex: any) { + form.handleGeneralError(ex); + } + } else { + const user = authentication.getCurrentUser(); + newData.domainId = MakeGeneralIdRef(user?.domainid); + } + + form.setState({ ...form.state, loaded: true, data: newData }); }; // ----------------------------- // Load existing template (edit mode) // ----------------------------- useEffect(() => { - const load = async () => { - const newData: CreateWorkflowTemplateVersion = { ...form.state.data }; - - if (editMode && userId) { - try { - const loadedData = await templateVersionsService.getTemplateVersion( - BigInt(userId), - ); - - if (loadedData) { - newData.workflowName = loadedData.workflowName ?? ""; - } - } catch (ex: any) { - form.handleGeneralError(ex); - } - } else { - const user = authentication.getCurrentUser(); - newData.domainId = MakeGeneralIdRef(user?.domainid); - } - - form.setState({ ...form.state, loaded: true, data: newData }); - }; - load(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [editMode, userId]); + }, [editMode, workflowTemplateId]); // ----------------------------- // Save handler (called by useForm.handleSubmit) @@ -109,10 +118,10 @@ const WorkflowTemplateDetails: React.FC<{ editMode: boolean }> = ({ var json = JSON.stringify(data); - console.log("Submitting workflow template:", json); - if (editMode) { - //await templateVersionsService.putTemplateVersion({ name }); + await templateVersionsService.putTemplateVersion( + data as ReadWorkflowTemplateVersion, + ); toast.info(t("WorkflowTemplateEdited")); } else { await templateVersionsService.postTemplateVersion( @@ -126,6 +135,7 @@ const WorkflowTemplateDetails: React.FC<{ editMode: boolean }> = ({ } form.markAsSaved(); + load(); } catch (ex: any) { form.handleGeneralError(ex); } diff --git a/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts b/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts index 3cfcd3b..c064d43 100644 --- a/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts +++ b/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts @@ -17,15 +17,17 @@ export type ReadWorkflowTemplate = { version: bigint; }; -export type ReadWorkflowTemplateVersion = { +export interface ReadWorkflowTemplateVersion extends FormData { id: bigint; - guid?: string; - workflowId: GeneralIdRef; - name: string; - domainId: GeneralIdRef; + guid: string; activityNameTemplate: string; + domainId: GeneralIdRef; + version: bigint; + workflowId: GeneralIdRef; + workflowName: string; description: string; -}; + tasks: TaskDefinition[]; +} export interface TaskDefinition> { type: string; @@ -94,8 +96,11 @@ export async function getTemplateVersions( return response?.data; } -export async function getTemplateVersion(id?: bigint, guid?: string) { - const params = MakeGeneralIdRefParams(id, guid); +export async function getTemplateVersion( + workflowTemplateId: bigint, + guid?: string, +): Promise { + const params = MakeGeneralIdRefParams(workflowTemplateId, guid); const response = await httpService.get( apiEndpoint + "/templateVersion?" + params, @@ -111,17 +116,9 @@ export async function postTemplateVersion( } export async function putTemplateVersion( - id: GeneralIdRef, - name: string, - address: string, - status: string, + data: ReadWorkflowTemplateVersion, ): Promise { - return await httpService.put(apiEndpoint + "/templateVersion", { - GeneralIdRef: id, - name, - address, - status, - }); + return await httpService.put(apiEndpoint + "/templateVersion", data); } export async function deleteTemplateVersion( diff --git a/src/services/httpService.ts b/src/services/httpService.ts index a166670..a7e1369 100644 --- a/src/services/httpService.ts +++ b/src/services/httpService.ts @@ -75,6 +75,7 @@ export function Get(url: string, config?: any): any { }) .catch((error) => { toast.error(error.message); + throw error; }); } @@ -86,6 +87,7 @@ export function Post(url: string, data?: any, config?: any): any { }) .catch((error) => { toast.error(error.message); + throw error; }); } @@ -97,6 +99,7 @@ export function Put(url: string, data?: any, config?: any): any { }) .catch((error) => { toast.error(error.message); + throw error; }); } @@ -108,6 +111,7 @@ export function Patch(url: string, data?: any, config?: any): any { }) .catch((error) => { toast.error(error.message); + throw error; }); } @@ -119,6 +123,7 @@ export function Delete(url: string, config?: any): any { }) .catch((error) => { toast.error(error.message); + throw error; }); }