From 9d189bfebd79fa96b05b6a4a7eea80a4b6e8c968 Mon Sep 17 00:00:00 2001 From: Guillaume Dorce Date: Fri, 28 Oct 2022 16:42:40 +0200 Subject: [PATCH] handle info change in modal --- client/src/components/User.tsx | 55 +++++++++++++++++------- client/src/controllers/UserController.ts | 48 +++++++++++++++++++++ 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/client/src/components/User.tsx b/client/src/components/User.tsx index b484ccb..df43aaa 100644 --- a/client/src/components/User.tsx +++ b/client/src/components/User.tsx @@ -1,6 +1,6 @@ -import { useState } from 'react'; +import { FormEvent, useState } from 'react'; import Modal from './Modal'; -import { getMeInfo, giveUserRights } from '@controllers/UserController'; +import { getMeInfo, giveUserRights, changeUserInfo } from '@controllers/UserController'; import { toastError, toastSuccess } from '@controllers/Toasts'; import { useQuery, useQueryClient } from '@tanstack/react-query'; @@ -55,10 +55,19 @@ const User = ({ author }: any) => { queryClient.invalidateQueries(['messages']); } - const handleChange = (e: any) => { + const handleChangeInfo = (e: FormEvent) => { e.preventDefault(); - toastSuccess('Infos personelles changées'); - setShow(!show); + const data = new FormData(e.target as HTMLFormElement); + + changeUserInfo(author.id, data).then((response) => { + if (response.error) { + return toastError(response.error); + } + toastSuccess('Infos personelles changées'); + queryClient.invalidateQueries(['messages']); + }).catch((error) => { + toastError(error.error); + }); }; return ( @@ -113,9 +122,13 @@ const User = ({ author }: any) => { ) : ( <>
Modifier ses infos personnelles
-
+
+ {' '} + Tous les champs avec * sont obligatoires +
+ { id="firstName" className="rounded-lg p-2" defaultValue={author.firstName} + required /> { id="lastName" className="rounded-lg p-2" defaultValue={author.lastName} + required /> - + - +
-
Changer son mot de passe:
+
Changer son mot de passe:
- +