Update DeedTypeEdit
This commit is contained in:
parent
b4d8562519
commit
129e3ea973
@ -16,6 +16,7 @@ import classes from "./classes.module.scss";
|
||||
|
||||
import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
|
||||
export default function DeedTypesEdit() {
|
||||
const router = useRouter();
|
||||
@ -31,10 +32,11 @@ export default function DeedTypesEdit() {
|
||||
async function getDeedType() {
|
||||
if (!deedTypeUid) return;
|
||||
LoaderService.getInstance().show();
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
||||
if (process) {
|
||||
const deedType: any = process.processData;
|
||||
setDeedTypeSelected(deedType);
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
MessageBus.getInstance().getProcessData(processId).then((processData: any) => {
|
||||
if (processData) {
|
||||
setDeedTypeSelected(processData);
|
||||
}
|
||||
LoaderService.getInstance().hide();
|
||||
});
|
||||
@ -47,51 +49,52 @@ export default function DeedTypesEdit() {
|
||||
setIsConfirmModalVisible(false);
|
||||
}, []);
|
||||
|
||||
const onSubmitHandler = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string | undefined }) => {
|
||||
const deedType = DeedType.hydrate<DeedType>({
|
||||
uid: deedTypeUid as string,
|
||||
name: values["name"],
|
||||
description: values["description"],
|
||||
});
|
||||
try {
|
||||
await deedType.validateOrReject?.({ groups: ["updateDeedType"], forbidUnknownValues: true });
|
||||
} catch (validationErrors: Array<ValidationError> | any) {
|
||||
if (!Array.isArray(validationErrors)) return;
|
||||
setValidationError(validationErrors as ValidationError[]);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LoaderService.getInstance().show();
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||
if (process) {
|
||||
// New data
|
||||
const newData: any = {
|
||||
name: values["name"],
|
||||
description: values["description"]
|
||||
};
|
||||
const onSubmitHandler = async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string | undefined }) => {
|
||||
// const deedType = DeedType.hydrate<DeedType>({
|
||||
// name: values["name"],
|
||||
// description: values["description"],
|
||||
// });
|
||||
|
||||
// Merge process data with new data & update process
|
||||
process.processData.name = newData.name;
|
||||
process.processData.description = newData.description;
|
||||
await DeedTypeService.updateDeedType(process, newData);
|
||||
// try {
|
||||
// await deedType.validateOrReject?.({ groups: ["updateDeedType"], forbidUnknownValues: true });
|
||||
// } catch (validationErrors: Array<ValidationError> | any) {
|
||||
// if (!Array.isArray(validationErrors)) return;
|
||||
// setValidationError(validationErrors as ValidationError[]);
|
||||
// return;
|
||||
// }
|
||||
|
||||
router.push(
|
||||
Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeUid as string),
|
||||
);
|
||||
LoaderService.getInstance().hide();
|
||||
}
|
||||
});
|
||||
} catch (validationErrors) {
|
||||
if (!Array.isArray(validationErrors)) return;
|
||||
setValidationError(validationErrors as ValidationError[]);
|
||||
return;
|
||||
try {
|
||||
LoaderService.getInstance().show();
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
|
||||
const process = await MessageBus.getInstance().getProcessData(processId);
|
||||
if (process) {
|
||||
console.log('process', process);
|
||||
// New data
|
||||
const newData: any = {
|
||||
name: values["name"],
|
||||
description: values["description"]
|
||||
};
|
||||
|
||||
// Merge process data with new data & update process
|
||||
process[processId].name = newData.name;
|
||||
process[processId].description = newData.description;
|
||||
await DeedTypeService.updateDeedType(processId, newData);
|
||||
|
||||
router.push(
|
||||
Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeUid as string),
|
||||
);
|
||||
}
|
||||
},
|
||||
[deedTypeUid, router],
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error updating deed type:', error);
|
||||
// Handle error appropriately
|
||||
} finally {
|
||||
LoaderService.getInstance().hide();
|
||||
}
|
||||
};
|
||||
|
||||
const onFieldChange = useCallback((name: string, field: any) => {
|
||||
setHasChanged(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user