From 1d5c094a20a72d53ab536a631e6e327b50071b0f Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:01:40 +0200 Subject: [PATCH] :sparkles: Modifying deed types document types --- .../LeCoffreApi/Admin/DeedTypes/DeedTypes.ts | 20 +++++++++++++++++++ .../DeedTypes/DeedTypesInformations/index.tsx | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts index a9254f9d..efeee6f2 100644 --- a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts +++ b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts @@ -2,6 +2,16 @@ import { DeedType } from "le-coffre-resources/dist/Admin"; import BaseAdmin from "../BaseAdmin"; +export type IPutDeedTypesParams = { + uid?: DeedType["uid"]; + name?: DeedType["name"]; + description?: DeedType["description"]; + deed?: DeedType["deed"]; + office?: DeedType["office"]; + archived_at?: DeedType["archived_at"]; + document_types?: DeedType["document_types"]; +}; + export type IGetDeedTypesParams = { where?: {}; include?: {}; @@ -46,4 +56,14 @@ export default class DeedTypes extends BaseAdmin { return Promise.reject(err); } } + + public async put(uid: string, body: IPutDeedTypesParams) { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index 35fd704c..a403dce2 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -57,7 +57,14 @@ export default function DeedTypesInformations(props: IProps) { getDeedType(); }, [deedTypeUid]); - const onSubmitHandler = useCallback(async (e: React.FormEvent | null, values: { [key: string]: string }) => {}, []); + const onSubmitHandler = useCallback( + async (e: React.FormEvent | null, values: { [key: string]: string }) => { + await DeedTypes.getInstance().put(deedTypeUid as string, { + document_types: selectedDocuments.map((document) => DocumentType.hydrate({ uid: document.value as string })), + }); + }, + [deedTypeUid, selectedDocuments], + ); const onDocumentChangeHandler = useCallback((values: MultiValue) => { setSelectedDocuments(values as IOption[]);