✨ add error message when no client selected
This commit is contained in:
parent
68468f7793
commit
a9ce560a1b
@ -34,6 +34,8 @@ export default class AutocompleteField extends BaseField<IProps, IState> {
|
||||
};
|
||||
|
||||
public override componentDidUpdate(prevProps: IProps): void {
|
||||
super.componentDidUpdate(prevProps);
|
||||
|
||||
if (prevProps.selectedOption !== this.props.selectedOption) {
|
||||
this.setState({ selectedOption: this.props.selectedOption ?? null });
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ export default class AutocompleteMultiSelectField extends BaseField<IProps, ISta
|
||||
};
|
||||
|
||||
public override componentDidUpdate(prevProps: IProps): void {
|
||||
super.componentDidUpdate(prevProps);
|
||||
|
||||
if (prevProps.selectedOptions !== this.props.selectedOptions) {
|
||||
this.setState({ selectedOptions: this.props.selectedOptions ?? null });
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ export default class SelectField extends BaseField<IProps, IState> {
|
||||
};
|
||||
|
||||
public override componentDidUpdate(prevProps: IProps): void {
|
||||
super.componentDidUpdate(prevProps);
|
||||
|
||||
|
||||
if (prevProps.selectedOption !== this.props.selectedOption) {
|
||||
this.setState({ selectedOption: this.props.selectedOption ?? null });
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
|
||||
import classes from "./classes.module.scss";
|
||||
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
|
||||
import AutocompleteMultiSelectField from "@Front/Components/DesignSystem/Form/AutocompleteMultiSelectField";
|
||||
import { ValidationError } from "class-validator";
|
||||
import TextField from "@Front/Components/DesignSystem/Form/TextField";
|
||||
|
||||
enum EClientSelection {
|
||||
ALL_CLIENTS = "all_clients",
|
||||
@ -31,6 +34,7 @@ export default function SendDocuments() {
|
||||
const [selectedClients, setSelectedClients] = useState<string[]>([]);
|
||||
const [files, setFiles] = useState<File[]>([]);
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
const [validationError, setValidationError] = useState<ValidationError | null>(null);
|
||||
|
||||
const onFormSubmit = useCallback(
|
||||
async (
|
||||
@ -46,6 +50,17 @@ export default function SendDocuments() {
|
||||
|
||||
try {
|
||||
setIsSending(true);
|
||||
|
||||
if (selectedClients.length === 0) {
|
||||
setValidationError({
|
||||
property: "clients",
|
||||
constraints: {
|
||||
isEmpty: "Veuillez sélectionner au moins un client",
|
||||
},
|
||||
});
|
||||
throw new Error("No clients selected");
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
selectedClients.map(async (customer) => {
|
||||
const promises = files.map(async (file) => {
|
||||
@ -72,7 +87,7 @@ export default function SendDocuments() {
|
||||
ToasterService.getInstance().success({ title: "Succès !", description: "Votre document a été envoyée avec succès." });
|
||||
} catch (error) {
|
||||
setIsSending(false);
|
||||
console.error("Error while sending files: ", error);
|
||||
console.warn("Error while sending files: ", error);
|
||||
}
|
||||
},
|
||||
[files, folderUid, router, selectedClients],
|
||||
@ -163,10 +178,12 @@ export default function SendDocuments() {
|
||||
|
||||
<Form onSubmit={onFormSubmit} className={classes["form"]}>
|
||||
{clientSelection === EClientSelection.SELECTED_CLIENTS && (
|
||||
<AutocompleteMultiSelect
|
||||
<AutocompleteMultiSelectField
|
||||
name="clients"
|
||||
label="Choisir le ou les clients: "
|
||||
options={clientsOptions}
|
||||
onSelectionChange={handleClientSelectionChange}
|
||||
validationError={validationError ?? undefined}
|
||||
/>
|
||||
)}
|
||||
{clientSelection && (
|
||||
|
Loading…
x
Reference in New Issue
Block a user