diff --git a/src/front/Api/BaseApiService.ts b/src/front/Api/BaseApiService.ts
index 2992b609..166621bc 100644
--- a/src/front/Api/BaseApiService.ts
+++ b/src/front/Api/BaseApiService.ts
@@ -119,17 +119,18 @@ export default abstract class BaseApiService {
responseJson = await response.json();
} catch (err: unknown) {
responseJson = null;
+ return Promise.reject(err);
}
if (!response.ok) {
- return Promise.reject(response);
+ return Promise.reject(responseJson);
}
return responseJson as T;
}
protected onError(error: unknown) {
- console.error(error);
+ //console.error(error);
}
}
diff --git a/src/front/Components/DesignSystem/Form/BaseField.tsx b/src/front/Components/DesignSystem/Form/BaseField.tsx
index 109a776e..e36ed0f2 100644
--- a/src/front/Components/DesignSystem/Form/BaseField.tsx
+++ b/src/front/Components/DesignSystem/Form/BaseField.tsx
@@ -1,6 +1,7 @@
import React from "react";
import { FormContext, IFormContext } from ".";
import { ValidationError } from "class-validator";
+import Typography, { ITypo, ITypoColor } from "../Typography";
export type IProps = {
value?: string;
@@ -34,6 +35,10 @@ export default abstract class BaseField
) {
+ this.context?.onFieldFocusChange(this.props.name, this, true);
+ }
+
+ protected onBlur(event: React.FocusEvent) {
+ this.context?.onFieldFocusChange(this.props.name, this, false);
+ }
+
protected onChange(event: React.ChangeEvent) {
this.context?.onFieldChange(this.props.name, this);
this.setState({ value: event.currentTarget.value });
@@ -75,4 +88,22 @@ export default abstract class BaseField {
+ errors.push(
+
+ {value}
+ ,
+ );
+ });
+ return errors;
+ }
}
diff --git a/src/front/Components/DesignSystem/Form/TextField/index.tsx b/src/front/Components/DesignSystem/Form/TextField/index.tsx
index 76cb1e53..366e6f61 100644
--- a/src/front/Components/DesignSystem/Form/TextField/index.tsx
+++ b/src/front/Components/DesignSystem/Form/TextField/index.tsx
@@ -18,34 +18,23 @@ export default class TextField extends BaseField {
const value = this.state.value ?? "";
return (
-
+
- {this.state.validationError !== null &&
{this.renderErrors()}
}
+ {this.hasError() &&
{this.renderErrors()}
}
);
}
-
- private renderErrors(): JSX.Element[] | null {
- if (!this.state.validationError || !this.state.validationError.constraints) return null;
- let errors: JSX.Element[] = [];
- Object.entries(this.state.validationError.constraints).forEach(([key, value]) => {
- errors.push(
-
- {value}
- ,
- );
- });
- return errors;
- }
}
diff --git a/src/front/Components/DesignSystem/Form/TextareaField/index.tsx b/src/front/Components/DesignSystem/Form/TextareaField/index.tsx
index 4115c557..43dd9c75 100644
--- a/src/front/Components/DesignSystem/Form/TextareaField/index.tsx
+++ b/src/front/Components/DesignSystem/Form/TextareaField/index.tsx
@@ -18,7 +18,7 @@ export default class TextAreaField extends BaseField
{
const value = this.state.value ?? "";
return (
-
+
);
@@ -42,17 +44,4 @@ export default class TextAreaField extends BaseField
{
value: this.props.defaultValue ?? "",
});
}
-
- private renderErrors(): JSX.Element[] | null {
- if (!this.state.validationError || !this.state.validationError.constraints) return null;
- let errors: JSX.Element[] = [];
- Object.entries(this.state.validationError.constraints).forEach(([key, value]) => {
- errors.push(
-
- {value}
- ,
- );
- });
- return errors;
- }
}
diff --git a/src/front/Components/DesignSystem/Form/index.tsx b/src/front/Components/DesignSystem/Form/index.tsx
index 7ad9b593..e3ab0f3e 100644
--- a/src/front/Components/DesignSystem/Form/index.tsx
+++ b/src/front/Components/DesignSystem/Form/index.tsx
@@ -8,25 +8,31 @@ export type IFormContext = {
setField: (name: string, field: IBaseField) => void;
unSetField: (name: string) => void;
onFieldChange: (name: string, field: IBaseField) => void;
+ onFieldFocusChange: (name: string, field: IBaseField, focused: boolean) => void;
+ isInputFocused: (name: string) => boolean;
};
type IFields = {
[key: string]: IBaseField;
};
-type IState = {};
+type IState = {
+ inputFocused: {
+ name: string;
+ field: IBaseField;
+ focused: boolean;
+ };
+};
export type IProps = {
+ onFieldFocusChange?: (name: string, field: IBaseField, focused: boolean) => void;
onFieldChange?: (name: string, field: IBaseField) => void;
- onSubmit?: (
- e: React.FormEvent | null,
- values: { [key: string]: string },
- ) => void;
+ onSubmit?: (e: React.FormEvent | null, values: { [key: string]: string }) => void;
className?: string;
children?: ReactNode;
};
-export const FormContext = React.createContext({ setField: () => {}, unSetField: () => {}, onFieldChange: () => {} });
+export const FormContext = React.createContext({ setField: () => {}, unSetField: () => {}, onFieldChange: () => {}, onFieldFocusChange: () => {}, isInputFocused: () => false});
export default class Form extends React.Component {
protected fields: IFields = {};
@@ -35,12 +41,21 @@ export default class Form extends React.Component {
constructor(props: IProps) {
super(props);
- this.state = {};
+ this.state = {
+ inputFocused: {
+ name: "",
+ field: {} as IBaseField,
+ focused: false,
+ },
+ };
+
this.setField = this.setField.bind(this);
this.unSetField = this.unSetField.bind(this);
this.onFieldChange = this.onFieldChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.formRef = React.createRef();
+ this.onFieldFocusChange = this.onFieldFocusChange.bind(this);
+ this.isInputFocused = this.isInputFocused.bind(this);
}
public override render() {
@@ -50,6 +65,8 @@ export default class Form extends React.Component {
setField: this.setField,
unSetField: this.unSetField,
onFieldChange: this.onFieldChange,
+ onFieldFocusChange: this.onFieldFocusChange,
+ isInputFocused: this.isInputFocused,
}}>