diff --git a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx index 7ad48d93..8ed23e45 100644 --- a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx @@ -1,19 +1,31 @@ -import BasePage from "../../Base"; -import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; -import classes from "./classes.module.scss"; -import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; import RightImage from "@Front/Assets/images/create-folder/right-image.png"; -import BackArrow from "@Front/Components/Elements/BackArrow"; -import Form from "@Front/Components/DesignSystem/Form"; -import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField"; -import Select, { IOption } from "@Front/Components/DesignSystem/Select"; -import RadioBox from "@Front/Components/DesignSystem/RadioBox"; import Button from "@Front/Components/DesignSystem/Button"; +import Form, { IApiFormErrors } from "@Front/Components/DesignSystem/Form"; +import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField"; import MultiSelect from "@Front/Components/DesignSystem/MultiSelect"; +import RadioBox from "@Front/Components/DesignSystem/RadioBox"; +import Select, { IOption } from "@Front/Components/DesignSystem/Select"; +import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; +import BackArrow from "@Front/Components/Elements/BackArrow"; +import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; +import React from "react"; +import { ActionMeta, MultiValue } from "react-select"; + +import BasePage from "../../Base"; +import classes from "./classes.module.scss"; + +type IFormValues = { + folder_number: number; + entitled: string; + act_type: IOption | null; + personal_note: string; + collaborators: MultiValue; +}; type IProps = {}; type IState = { folder_access: string; + formValues: IFormValues; }; export default class CreateFolder extends BasePage { private collaboratorsOptions: IOption[] = [ @@ -30,17 +42,30 @@ export default class CreateFolder extends BasePage { { label: "Succession", value: "succession" }, { label: "Vente immobilière", value: "vente_immobiliere" }, ]; + public constructor(props: IProps) { super(props); this.state = { folder_access: "", + formValues: { + folder_number: NaN, + entitled: "", + act_type: null, + personal_note: "", + collaborators: [], + }, }; this.radioOnChange = this.radioOnChange.bind(this); + this.onFolderNumberChange = this.onFolderNumberChange.bind(this); + this.onEntitleChange = this.onEntitleChange.bind(this); + this.onActTypeChange = this.onActTypeChange.bind(this); + this.onPersonalNoteChange = this.onPersonalNoteChange.bind(this); + this.onCollaboratorsChange = this.onCollaboratorsChange.bind(this); + this.isFormSubmittable = this.isFormSubmittable.bind(this); } - // TODO: Message if the user has not created any folder yet public override render(): JSX.Element { return ( @@ -52,12 +77,22 @@ export default class CreateFolder extends BasePage { Informations dossier -
+
- - - +
@@ -76,11 +111,12 @@ export default class CreateFolder extends BasePage {
)}
-
@@ -93,6 +129,76 @@ export default class CreateFolder extends BasePage { public override async componentDidMount() {} + private onFolderNumberChange(e: React.ChangeEvent) { + this.setState({ + formValues: { + ...this.state.formValues, + folder_number: parseInt(e.target.value), + }, + }); + } + + private onEntitleChange(e: React.ChangeEvent) { + this.setState({ + formValues: { + ...this.state.formValues, + entitled: e.target.value, + }, + }); + } + + private onActTypeChange(selectedOption: IOption) { + this.setState({ + formValues: { + ...this.state.formValues, + act_type: selectedOption, + }, + }); + } + + private onPersonalNoteChange(e: React.ChangeEvent) { + this.setState({ + formValues: { + ...this.state.formValues, + personal_note: e.target.value, + }, + }); + } + + private onCollaboratorsChange(newValue: MultiValue, actionMeta: ActionMeta) { + this.setState({ + formValues: { + ...this.state.formValues, + collaborators: newValue, + }, + }); + } + + private onFormSubmit( + e: React.FormEvent | null, + values: { + [key: string]: string; + }, + onApiErrors: (apiFormErrors: IApiFormErrors | null) => void, + ) {} + + private isFormSubmittable(): boolean { + if ( + this.state.formValues.entitled === "" || + this.state.formValues.personal_note === "" || + Number.isNaN(this.state.formValues.folder_number) || + this.state.formValues.act_type === null + ) { + return false; + } + + if (this.state.folder_access === "select_collaborators" && this.state.formValues.collaborators.length === 0) { + return false; + } + + return true; + } + private radioOnChange(e: React.ChangeEvent) { this.setState({ folder_access: e.target.value,