feat: club membre import

This commit is contained in:
2025-07-02 18:13:34 +02:00
parent 17fea2272f
commit 5ce5df950f
4 changed files with 152 additions and 10 deletions

View File

@@ -193,8 +193,6 @@ function FileOutput() {
function FileInput() {
const [data, setData] = useState(null);
const re = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;
function excelDateToJSDate(serial) {
@@ -251,19 +249,30 @@ function FileInput() {
if (line["Nom médecin certificat"] === undefined || line["Nom médecin certificat"] === "" ||
line["Date certificat"] === undefined || line["Date certificat"] === "") {
cetifNotFill++;
}
try {
// noinspection JSNonASCIINames
tmp.certif = line["Nom médecin certificat"] + "¤" + excelDateToJSDate(line["Date certificat"]).toISOString()
} catch (e) {
toast.error("Format de la date de certificat invalide à la ligne " + (i + 2))
error++;
} else {
try {
const date = excelDateToJSDate(line["Date certificat"]);
if (Number.isNaN(date.getFullYear())) {
toast.error("Format de la date de certificat invalide à la ligne " + (i + 2))
error++;
} else {
// noinspection JSNonASCIINames
tmp.certif = line["Nom médecin certificat"] + "¤" + date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2);
}
} catch (e) {
toast.error("Format de la date de certificat invalide à la ligne " + (i + 2))
error++;
}
}
if (tmp.birthdate === undefined || tmp.birthdate === "") {
toast.error("Date de naissance vide à la ligne " + (i + 2))
error++;
}
}
if (tmp.birthdate !== undefined && tmp.birthdate !== "") {
console.log(tmp.birthdate);
try {
tmp.birthdate = excelDateToJSDate(tmp.birthdate).toISOString();
} catch (e) {
@@ -271,6 +280,7 @@ function FileInput() {
error++;
}
}
dataOut.push(tmp)
}
@@ -278,7 +288,22 @@ function FileInput() {
toast.error(`${error} erreur(s) dans le fichier, opération annulée`)
} else {
console.log(dataOut);
setData(sheetData);
toast.promise(
apiAxios.put(`/member/club/import`, dataOut),
{
pending: "Envoie des changement en cours",
success: "Changement envoyé avec succès 🎉",
error: {
render({data}) {
return errFormater(data, "Échec de l'envoie des changements")
}
}
}
).then(_ => {
if (cetifNotFill > 0)
toast.warn(`${cetifNotFill} certificat(s) médical(aux) non rempli(s)`)
})
}
};