From cc68b85bc22ae4f687334d9d229d5178367702d1 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:12:24 +0200 Subject: [PATCH] :sparkles: Create deed type --- .../LeCoffreApi/Admin/DeedTypes/DeedTypes.ts | 15 ++++++++ .../DeedTypes/DeedTypesCreate/index.tsx | 36 +++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts index efeee6f2..896427c6 100644 --- a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts +++ b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts @@ -12,6 +12,11 @@ export type IPutDeedTypesParams = { document_types?: DeedType["document_types"]; }; +export type IPostDeedTypesParams = { + name?: DeedType["name"]; + description?: DeedType["description"]; +}; + export type IGetDeedTypesParams = { where?: {}; include?: {}; @@ -66,4 +71,14 @@ export default class DeedTypes extends BaseAdmin { return Promise.reject(err); } } + + public async post(body: IPostDeedTypesParams) { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx index 274b4205..39d22720 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx @@ -1,16 +1,46 @@ +import DeedTypes from "@Front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; +import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; +import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import DefaultDeedTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDeedTypeDashboard"; +import Module from "@Front/Config/Module"; +import JwtService from "@Front/Services/JwtService/JwtService"; +import { DeedType, Office } from "le-coffre-resources/dist/Admin"; +import { useRouter } from "next/router"; import { useCallback } from "react"; import classes from "./classes.module.scss"; -import TextField from "@Front/Components/DesignSystem/Form/TextField"; -import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; type IProps = {}; export default function DeedTypesCreate(props: IProps) { - const onSubmitHandler = useCallback(async (e: React.FormEvent | null, values: { [key: string]: string }) => {}, []); + const router = useRouter(); + const onSubmitHandler = useCallback( + async (e: React.FormEvent | null, values: { [key: string]: string }) => { + try { + const jwt = JwtService.getInstance().decodeJwt(); + const deedType = await DeedTypes.getInstance().post( + DeedType.hydrate({ + name: values["name"], + description: values["description"], + office: Office.hydrate({ + uid: jwt?.office_Id + }) + }), + ); + + router.push( + Module.getInstance() + .get() + .modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedType.uid!), + ); + } catch (e) { + console.error(e); + } + }, + [router], + ); return (