Update DeedTypeCreate
This commit is contained in:
parent
4540ac726a
commit
b4d8562519
@ -7,7 +7,6 @@ import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography";
|
|||||||
import DefaultDeedTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDeedTypeDashboard";
|
import DefaultDeedTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDeedTypeDashboard";
|
||||||
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
|
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
|
||||||
import Module from "@Front/Config/Module";
|
import Module from "@Front/Config/Module";
|
||||||
import { DeedType, Office } from "le-coffre-resources/dist/Admin";
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
@ -19,6 +18,7 @@ import UserStore from "@Front/Stores/UserStore";
|
|||||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||||
import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
||||||
import { DEFAULT_VALIDATOR_ID } from "@Front/Config/AppConstants";
|
import { DEFAULT_VALIDATOR_ID } from "@Front/Config/AppConstants";
|
||||||
|
import Auth from "@Front/Api/Auth/IdNot";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
export default function DeedTypesCreate(props: IProps) {
|
export default function DeedTypesCreate(props: IProps) {
|
||||||
@ -31,27 +31,44 @@ export default function DeedTypesCreate(props: IProps) {
|
|||||||
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
try {
|
try {
|
||||||
const user: any = UserStore.instance.getUser();
|
const user: any = UserStore.instance.getUser();
|
||||||
const officeId: string = user.office.uid;
|
if (!user) {
|
||||||
|
console.error("DeedTypesCreate: User not found - user is null or undefined");
|
||||||
const deedType = DeedType.hydrate<DeedType>({
|
|
||||||
name: values["name"],
|
|
||||||
description: values["description"],
|
|
||||||
office: Office.hydrate<Office>({
|
|
||||||
uid: officeId,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
await validateOrReject(deedType, { groups: ["createDeedType"], forbidUnknownValues: true });
|
|
||||||
} catch (validationErrors: Array<ValidationError> | any) {
|
|
||||||
setValidationError(validationErrors as ValidationError[]);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const res = await Auth.getInstance().getOfficeProcessByIdNot();
|
||||||
|
if (!res.success) {
|
||||||
|
console.error("DeedTypesCreate: Office not found - office is null or undefined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const officeId: string | undefined = res.data.processId;
|
||||||
|
const officeIdNot: string | undefined = res.data.processData['idNot'];
|
||||||
|
if (!officeId || !officeIdNot) {
|
||||||
|
console.error("DeedTypesCreate: officeId or officeIdNot is undefined - office.processData.idNot is missing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: We should update the type definition to be able to use validation again
|
||||||
|
// const deedType = DeedType.hydrate<DeedType>({
|
||||||
|
// name: values["name"],
|
||||||
|
// description: values["description"],
|
||||||
|
// office: Office.hydrate<Office>({
|
||||||
|
// idNot: officeId,
|
||||||
|
// }),
|
||||||
|
// });
|
||||||
|
// try {
|
||||||
|
// await validateOrReject(deedType, { groups: ["createDeedType"], forbidUnknownValues: true });
|
||||||
|
// } catch (validationErrors: Array<ValidationError> | any) {
|
||||||
|
// console.log("validationErrors", validationErrors);
|
||||||
|
// setValidationError(Array.isArray(validationErrors) ? validationErrors : []);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
const deedTypeData: any = {
|
const deedTypeData: any = {
|
||||||
name: values["name"],
|
name: values["name"],
|
||||||
description: values["description"],
|
description: values["description"],
|
||||||
office: {
|
office: {
|
||||||
uid: officeId,
|
uid: officeId,
|
||||||
|
idNot: officeIdNot,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,15 +78,18 @@ export default function DeedTypesCreate(props: IProps) {
|
|||||||
title: "Succès !",
|
title: "Succès !",
|
||||||
description: "Type d'acte créé avec succès"
|
description: "Type d'acte créé avec succès"
|
||||||
});
|
});
|
||||||
|
const deedTypeUid = processCreated.processId;
|
||||||
|
// Remove ':0' suffix from processId for URL navigation
|
||||||
|
const urlId = deedTypeUid.replace(/:0$/, '');
|
||||||
router.push(
|
router.push(
|
||||||
Module.getInstance()
|
Module.getInstance()
|
||||||
.get()
|
.get()
|
||||||
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", processCreated.processData.uid),
|
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", urlId),
|
||||||
);
|
);
|
||||||
LoaderService.getInstance().hide();
|
LoaderService.getInstance().hide();
|
||||||
});
|
});
|
||||||
} catch (validationErrors: Array<ValidationError> | any) {
|
} catch (validationErrors: Array<ValidationError> | any) {
|
||||||
setValidationError(validationErrors as ValidationError[]);
|
setValidationError(Array.isArray(validationErrors) ? validationErrors : []);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -106,12 +126,12 @@ export default function DeedTypesCreate(props: IProps) {
|
|||||||
<TextField
|
<TextField
|
||||||
name="name"
|
name="name"
|
||||||
placeholder="Nom de l'acte"
|
placeholder="Nom de l'acte"
|
||||||
validationError={validationError.find((error) => error.property === "name")}
|
validationError={Array.isArray(validationError) ? validationError.find((error) => error.property === "name") : undefined}
|
||||||
/>
|
/>
|
||||||
<TextAreaField
|
<TextAreaField
|
||||||
name="description"
|
name="description"
|
||||||
placeholder="Description"
|
placeholder="Description"
|
||||||
validationError={validationError.find((error) => error.property === "description")}
|
validationError={Array.isArray(validationError) ? validationError.find((error) => error.property === "description") : undefined}
|
||||||
/>
|
/>
|
||||||
<div className={classes["buttons-container"]}>
|
<div className={classes["buttons-container"]}>
|
||||||
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED} onClick={onCancel}>
|
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED} onClick={onCancel}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user