mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-07-09 15:08:06 +00:00
feat(Error display form userProfile): Error is displayed on wrong input of Editable
rules : 240 car max on bio, firstName and lastName required
This commit is contained in:
+44
-18
@@ -35,7 +35,11 @@ export default function UserProfile() {
|
|||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const { handleSubmit, control } = useForm();
|
const {
|
||||||
|
handleSubmit,
|
||||||
|
control,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm();
|
||||||
|
|
||||||
const [userData, setUserData] = useState({});
|
const [userData, setUserData] = useState({});
|
||||||
|
|
||||||
@@ -76,7 +80,6 @@ export default function UserProfile() {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
fetch(`/api/users/${user.id}`, options)
|
fetch(`/api/users/${user.id}`, options)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
toast({
|
toast({
|
||||||
title: `Modifications effectuées`,
|
title: `Modifications effectuées`,
|
||||||
@@ -140,56 +143,68 @@ export default function UserProfile() {
|
|||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Box as="form" onSubmit={handleSubmit(saveData)} width={"80%"}>
|
<Box as="form" onSubmit={handleSubmit(saveData)} width={"80%"}>
|
||||||
<FormControl width={"100%"}>
|
<Flex width={"100%"} justify={"space-between"} mb={"1rem"}>
|
||||||
<Flex justify={"space-between"} mb={"1rem"}>
|
|
||||||
<Box>
|
<Box>
|
||||||
|
<FormControl id="firstName" isInvalid={errors.firstName}>
|
||||||
<FormLabel as="legend" htmlFor={"firstName"}>
|
<FormLabel as="legend" htmlFor={"firstName"}>
|
||||||
Prénom :
|
Prénom :
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<Controller
|
<Controller
|
||||||
name={"firstName"}
|
name={"firstName"}
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field }) => (
|
|
||||||
<Editable
|
|
||||||
{...field}
|
|
||||||
id={"firstName"}
|
|
||||||
placeholder={"Non renseigné"}
|
|
||||||
as={"b"}
|
|
||||||
defaultValue={
|
defaultValue={
|
||||||
user.firstName === null ? "" : user.firstName
|
user.firstName === null ? "" : user.firstName
|
||||||
}
|
}
|
||||||
|
rules={{
|
||||||
|
required: { value: true, message: "Prénom requis" },
|
||||||
|
}}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<Editable
|
||||||
|
{...field}
|
||||||
|
id={"firstName"}
|
||||||
|
as={"b"}
|
||||||
|
placeholder={"Non renseigné"}
|
||||||
>
|
>
|
||||||
<EditablePreview />
|
<EditablePreview />
|
||||||
<EditableInput />
|
<EditableInput />
|
||||||
</Editable>
|
</Editable>
|
||||||
)}
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
<FormErrorMessage as="b">
|
||||||
|
{errors.firstName?.message}
|
||||||
|
</FormErrorMessage>
|
||||||
|
</FormControl>
|
||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
|
<FormControl id="lastName" isInvalid={errors.lastName}>
|
||||||
<FormLabel as={"legend"} htmlFor={"lastName"}>
|
<FormLabel as={"legend"} htmlFor={"lastName"}>
|
||||||
Nom :
|
Nom :
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<Controller
|
<Controller
|
||||||
name={"lastName"}
|
name={"lastName"}
|
||||||
control={control}
|
control={control}
|
||||||
|
defaultValue={user.lastName === null ? "" : user.lastName}
|
||||||
|
rules={{
|
||||||
|
required: { value: true, message: "Nom requis" },
|
||||||
|
}}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Editable
|
<Editable
|
||||||
{...field}
|
{...field}
|
||||||
id={"lastName"}
|
id={"lastName"}
|
||||||
as={"b"}
|
as={"b"}
|
||||||
placeholder={"Non renseigné"}
|
placeholder={"Non renseigné"}
|
||||||
defaultValue={
|
|
||||||
user.lastName === null ? "" : user.lastName
|
|
||||||
}
|
|
||||||
// onSubmit={(value) => {
|
|
||||||
// setUserData({ ...userData, lastName: value });
|
|
||||||
// }}
|
|
||||||
>
|
>
|
||||||
<EditablePreview />
|
<EditablePreview />
|
||||||
<EditableInput />
|
<EditableInput />
|
||||||
</Editable>
|
</Editable>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormErrorMessage as={"b"}>
|
||||||
|
{errors.lastName?.message}
|
||||||
|
</FormErrorMessage>
|
||||||
|
</FormControl>
|
||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
<FormLabel as={"legend"} htmlFor={"birthdate"}>
|
<FormLabel as={"legend"} htmlFor={"birthdate"}>
|
||||||
@@ -247,12 +262,20 @@ export default function UserProfile() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
<Divider colorScheme={"purple"} />
|
<Divider colorScheme={"purple"} />
|
||||||
<Box my={"1rem"}>
|
<Box my={"1rem"}>
|
||||||
|
<FormControl id="lastName" isInvalid={errors.bio}>
|
||||||
<FormLabel as={"legend"} htmlFor={"bio"}>
|
<FormLabel as={"legend"} htmlFor={"bio"}>
|
||||||
À propos :
|
À propos :
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<Controller
|
<Controller
|
||||||
name={"bio"}
|
name={"bio"}
|
||||||
control={control}
|
control={control}
|
||||||
|
defaultValue={user.bio === null ? "" : user.bio}
|
||||||
|
rules={{
|
||||||
|
maxLength: {
|
||||||
|
value: 240,
|
||||||
|
message: "240 caractères maximum",
|
||||||
|
},
|
||||||
|
}}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Editable
|
<Editable
|
||||||
{...field}
|
{...field}
|
||||||
@@ -270,6 +293,10 @@ export default function UserProfile() {
|
|||||||
</Editable>
|
</Editable>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormErrorMessage as="b">
|
||||||
|
{errors.bio?.message}
|
||||||
|
</FormErrorMessage>
|
||||||
|
</FormControl>
|
||||||
</Box>
|
</Box>
|
||||||
<Divider colorScheme={"purple"} />
|
<Divider colorScheme={"purple"} />
|
||||||
<Box my={"1rem"}>
|
<Box my={"1rem"}>
|
||||||
@@ -354,7 +381,6 @@ export default function UserProfile() {
|
|||||||
Sauvegarder les modifications
|
Sauvegarder les modifications
|
||||||
</Button>
|
</Button>
|
||||||
</Center>
|
</Center>
|
||||||
</FormControl>
|
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
Reference in New Issue
Block a user