✨ Create document type working
This commit is contained in:
parent
22e8578b21
commit
3c0bccf397
@ -52,7 +52,7 @@ export default class DocumentTypes extends BaseAdmin {
|
|||||||
/**
|
/**
|
||||||
* @description : Create a Document
|
* @description : Create a Document
|
||||||
*/
|
*/
|
||||||
public async post(body: IPostDocumentTypesParams): Promise<DocumentType> {
|
public async post(body: DocumentType): Promise<DocumentType> {
|
||||||
const url = new URL(this.baseURl);
|
const url = new URL(this.baseURl);
|
||||||
try {
|
try {
|
||||||
return await this.postRequest<DocumentType>(url, body as any);
|
return await this.postRequest<DocumentType>(url, body as any);
|
||||||
|
@ -1,16 +1,42 @@
|
|||||||
|
import DocumentTypes from "@Front/Api/LeCoffreApi/Admin/DocumentTypes/DocumentTypes";
|
||||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import Form from "@Front/Components/DesignSystem/Form";
|
import Form from "@Front/Components/DesignSystem/Form";
|
||||||
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
||||||
import TextField from "@Front/Components/DesignSystem/Form/TextField";
|
import TextField from "@Front/Components/DesignSystem/Form/TextField";
|
||||||
import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
|
||||||
import DefaultDocumentTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDocumentTypesDashboard";
|
import DefaultDocumentTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDocumentTypesDashboard";
|
||||||
|
import Module from "@Front/Config/Module";
|
||||||
|
import { validateOrReject } from "class-validator";
|
||||||
|
import { DocumentType, Office } from "le-coffre-resources/dist/Admin";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
export default function DocumentTypesCreate(props: IProps) {
|
export default function DocumentTypesCreate(props: IProps) {
|
||||||
const onSubmitHandler = useCallback(async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {}, []);
|
const router = useRouter();
|
||||||
|
const onSubmitHandler = useCallback(
|
||||||
|
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
|
try {
|
||||||
|
const documentToCreate = DocumentType.hydrate<DocumentType>({
|
||||||
|
...values,
|
||||||
|
office: Office.hydrate<Office>({
|
||||||
|
uid: "6981326f-8a0a-4437-b15c-4cd5c4d80f6e",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
await validateOrReject(documentToCreate, { groups: ["createDocumentType"] });
|
||||||
|
const documentTypeCreated = await DocumentTypes.getInstance().post(documentToCreate);
|
||||||
|
|
||||||
|
router.push(
|
||||||
|
Module.getInstance().get().modules.pages.DocumentTypes.pages.Edit.props.path.replace("[uid]", documentTypeCreated.uid!),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[router],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DefaultDocumentTypesDashboard mobileBackText={"Liste des types d'actes"} hasBackArrow title="Créer un type d'acte">
|
<DefaultDocumentTypesDashboard mobileBackText={"Liste des types d'actes"} hasBackArrow title="Créer un type d'acte">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user