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