mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-12-05 17:30:50 +00:00
refactor: Set default colorScheme to purple
Took 1 hour 12 minutes
This commit is contained in:
@@ -32,8 +32,8 @@ export default function FormMessage(props: Props) {
|
||||
|
||||
return (
|
||||
<Flex gap={5} mt={5}>
|
||||
<Input type={text} colorScheme={'purple'} onChange={(evt) => setText(evt.target.value) } value={text} />
|
||||
<Button colorScheme={'purple'} onClick={handleSubmit} >Envoyer</Button>
|
||||
<Input type={text} onChange={evt => setText(evt.target.value) } value={text}/>
|
||||
<Button onClick={handleSubmit}>Envoyer</Button>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import {
|
||||
Input,
|
||||
Container,
|
||||
FormErrorMessage,
|
||||
} from "@chakra-ui/react";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { signIn, SignInResponse } from "next-auth/react";
|
||||
} from '@chakra-ui/react';
|
||||
import {useState} from 'react';
|
||||
import {useRouter} from 'next/router';
|
||||
import {signIn, SignInResponse} from 'next-auth/react';
|
||||
|
||||
import { LoginData } from "@/models/form/LoginData";
|
||||
import { useForm } from "react-hook-form";
|
||||
import {LoginData} from '@/models/form/LoginData';
|
||||
import {useForm} from 'react-hook-form';
|
||||
|
||||
export default function LoginForm() {
|
||||
const router = useRouter();
|
||||
@@ -24,92 +24,84 @@ export default function LoginForm() {
|
||||
const {
|
||||
handleSubmit,
|
||||
register,
|
||||
formState: { errors, isSubmitting },
|
||||
formState: {errors, isSubmitting},
|
||||
} = useForm();
|
||||
|
||||
const buttonWidth = { base: "100%", md: "unset" };
|
||||
const buttonWidth = {base: '100%', md: 'unset'};
|
||||
|
||||
const errorPassword = "Mot de passe incorrect";
|
||||
const errorPassword = 'Mot de passe incorrect';
|
||||
|
||||
const loginUser = async (value: LoginData) => {
|
||||
setIsLoading(true);
|
||||
signIn("credentials", { ...value, redirect: false }).then(
|
||||
(res: unknown) => {
|
||||
const { ok: connexionSuccess } = res as SignInResponse;
|
||||
setIsLoading(false);
|
||||
signIn('credentials', {...value, redirect: false}).then(
|
||||
(res: unknown) => {
|
||||
const {ok: connexionSuccess} = res as SignInResponse;
|
||||
setIsLoading(false);
|
||||
|
||||
if (connexionSuccess) router.push("/dashboard");
|
||||
else setWrongPasswordError(true);
|
||||
}
|
||||
if (connexionSuccess) router.push('/dashboard');
|
||||
else setWrongPasswordError(true);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box flexBasis={"100%"}>
|
||||
<Container>
|
||||
<form id="login_form" onSubmit={handleSubmit(loginUser)}>
|
||||
<Heading textAlign={"center"} size={"2xl"}>
|
||||
Connexion
|
||||
</Heading>
|
||||
|
||||
{/*Email*/}
|
||||
<FormControl mb={"1rem"} id={"email"} isInvalid={errors.email}>
|
||||
<FormLabel>Adresse email</FormLabel>
|
||||
<Input
|
||||
type="text"
|
||||
{...register("email", {
|
||||
required: { value: true, message: "Adresse email requise" },
|
||||
pattern: {
|
||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
message: "Adresse email invalide",
|
||||
},
|
||||
})}
|
||||
placeholder="adresse@email.com"
|
||||
/>
|
||||
<FormErrorMessage>{errors.email?.message}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Mot de passe*/}
|
||||
<FormControl
|
||||
mb={"1rem"}
|
||||
id="password"
|
||||
isInvalid={errors.password || wrongPasswordError}
|
||||
>
|
||||
<FormLabel>Mot de passe</FormLabel>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register("password", {
|
||||
required: { value: true, message: "Mot de passe requis" },
|
||||
})}
|
||||
/>
|
||||
<FormErrorMessage>{errors.password?.message}</FormErrorMessage>
|
||||
<FormErrorMessage>
|
||||
{wrongPasswordError && errorPassword}
|
||||
</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Boutons*/}
|
||||
<Flex
|
||||
justify={"center"}
|
||||
mt={"50px"}
|
||||
gap={5}
|
||||
justifyContent={"space-between"}
|
||||
>
|
||||
<Button onClick={() => router.push("/")} w={buttonWidth}>
|
||||
Retour
|
||||
</Button>
|
||||
<Button
|
||||
isLoading={isLoading}
|
||||
w={buttonWidth}
|
||||
colorScheme="purple"
|
||||
type="submit"
|
||||
>
|
||||
<Box flexBasis={'100%'}>
|
||||
<Container>
|
||||
<form id="login_form" onSubmit={handleSubmit(loginUser)}>
|
||||
<Heading textAlign={'center'} size={'2xl'}>
|
||||
Connexion
|
||||
</Button>
|
||||
</Flex>
|
||||
</form>
|
||||
</Container>
|
||||
</Box>
|
||||
</Heading>
|
||||
|
||||
{/*Email*/}
|
||||
<FormControl mb={'1rem'} id={'email'}
|
||||
isInvalid={errors.email as boolean | undefined}>
|
||||
<FormLabel>Adresse email</FormLabel>
|
||||
<Input
|
||||
type="text"
|
||||
{...register('email', {
|
||||
required: {value: true, message: 'Adresse email requise'},
|
||||
pattern: {
|
||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
message: 'Adresse email invalide',
|
||||
},
|
||||
})}
|
||||
placeholder="adresse@email.com"
|
||||
/>
|
||||
<FormErrorMessage>{errors.email?.message as string}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Mot de passe*/}
|
||||
<FormControl
|
||||
mb={'1rem'}
|
||||
id="password"
|
||||
isInvalid={errors.password as boolean | undefined ||
|
||||
wrongPasswordError}
|
||||
>
|
||||
<FormLabel>Mot de passe</FormLabel>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register('password', {
|
||||
required: {value: true, message: 'Mot de passe requis'},
|
||||
})}
|
||||
/>
|
||||
<FormErrorMessage>{errors.password?.message as string}</FormErrorMessage>
|
||||
<FormErrorMessage>{wrongPasswordError &&
|
||||
errorPassword}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Boutons*/}
|
||||
<Flex justify={'center'} mt={'50px'} gap={5}
|
||||
justifyContent={'space-between'}>
|
||||
<Button onClick={() => router.push('/')} w={buttonWidth}>
|
||||
Retour
|
||||
</Button>
|
||||
<Button isLoading={isLoading} w={buttonWidth} type="submit">
|
||||
Connexion
|
||||
</Button>
|
||||
</Flex>
|
||||
</form>
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
FormErrorMessage,
|
||||
} from '@chakra-ui/react';
|
||||
import {useRouter} from 'next/router';
|
||||
import {useState} from 'react';
|
||||
import {signIn, SignInResponse} from 'next-auth/react';
|
||||
import {RegisterData} from '@/models/form/RegisterData';
|
||||
import {SubmitHandler, useForm} from 'react-hook-form';
|
||||
@@ -48,137 +47,113 @@ export default function RegisterForm() {
|
||||
}),
|
||||
};
|
||||
|
||||
fetch('/api/users', options).then(() => {
|
||||
signIn('credentials', {email, password, redirect: false}).then(
|
||||
(res: unknown) => {
|
||||
const {ok: connexionSuccess} = res as SignInResponse;
|
||||
|
||||
// TODO If success -> goto interactive form else login
|
||||
router.push(connexionSuccess ? '/dashboard' : '/');
|
||||
},
|
||||
);
|
||||
}).catch((err) => console.error(err));
|
||||
fetch('/api/users', options)
|
||||
.then(() => signIn('credentials', {email, password, redirect: false}))
|
||||
.then((res: unknown) => {
|
||||
const {ok: connexionSuccess} = res as SignInResponse;
|
||||
router.push(connexionSuccess ? '/getting-start' : '/');
|
||||
},
|
||||
)
|
||||
.catch(err => console.error(err));
|
||||
};
|
||||
|
||||
return (
|
||||
<Box flexBasis={'100%'}>
|
||||
<Container>
|
||||
<form id="register_form" onSubmit={handleSubmit(submitHandler)}>
|
||||
<Heading textAlign={'center'} size={'2xl'}>
|
||||
Inscription
|
||||
</Heading>
|
||||
<Heading textAlign={'center'} size={'2xl'}>Inscription</Heading>
|
||||
|
||||
<Flex mt={'100px'} mb={'1rem'} gap={5}>
|
||||
{/*Prénom*/}
|
||||
<FormControl id="firstName" isInvalid={errors.firstName as boolean|undefined}>
|
||||
<FormControl id="firstName"
|
||||
isInvalid={errors.firstName as boolean | undefined}>
|
||||
<FormLabel>Prénom</FormLabel>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Prénom"
|
||||
{...register('firstName', {
|
||||
required: {value: true, message: 'Prénom requis'},
|
||||
})}
|
||||
/>
|
||||
<Input type="text" placeholder="Prénom"
|
||||
{...register('firstName', {
|
||||
required: {value: true, message: 'Prénom requis'},
|
||||
})}/>
|
||||
<FormErrorMessage>{errors.firstName?.message as string}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Nom*/}
|
||||
<FormControl id="lastName" isInvalid={errors.lastName as boolean|undefined}>
|
||||
<FormControl id="lastName"
|
||||
isInvalid={errors.lastName as boolean | undefined}>
|
||||
<FormLabel>Nom</FormLabel>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Nom"
|
||||
{...register('lastName', {
|
||||
required: {value: true, message: 'Nom requis'},
|
||||
})}
|
||||
/>
|
||||
<Input type="text" placeholder="Nom"
|
||||
{...register('lastName', {
|
||||
required: {value: true, message: 'Nom requis'},
|
||||
})}/>
|
||||
<FormErrorMessage>{errors.lastName?.message as string}</FormErrorMessage>
|
||||
</FormControl>
|
||||
</Flex>
|
||||
|
||||
{/*Email*/}
|
||||
<FormControl mb={'1rem'} id={'email'} isInvalid={errors.email as boolean|undefined}>
|
||||
<FormControl mb={'1rem'} id={'email'}
|
||||
isInvalid={errors.email as boolean | undefined}>
|
||||
<FormLabel>Adresse email</FormLabel>
|
||||
<Input
|
||||
type="text"
|
||||
{...register('email', {
|
||||
required: {value: true, message: 'Adresse email requise'},
|
||||
pattern: {
|
||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
message: 'Adresse email invalide',
|
||||
},
|
||||
})}
|
||||
placeholder="adresse@email.com"
|
||||
/>
|
||||
<Input type="text" placeholder="adresse@email.com"
|
||||
{...register('email', {
|
||||
required: {
|
||||
value: true,
|
||||
message: 'Adresse email requise',
|
||||
},
|
||||
pattern: {
|
||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
message: 'Adresse email invalide',
|
||||
},
|
||||
})}/>
|
||||
<FormErrorMessage>{errors.email?.message as string}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Date de naissance*/}
|
||||
<FormControl
|
||||
mb={'1rem'}
|
||||
id={'birthdate'}
|
||||
isInvalid={errors.birthdate as boolean|undefined}
|
||||
>
|
||||
<FormControl mb={'1rem'} id={'birthdate'}
|
||||
isInvalid={errors.birthdate as boolean | undefined}>
|
||||
<FormLabel>Date de naissance</FormLabel>
|
||||
<Input
|
||||
type="date"
|
||||
{...register('birthdate', {
|
||||
required: {
|
||||
value: true,
|
||||
message: 'Date de naissance requise',
|
||||
},
|
||||
validate: validateDate,
|
||||
})}
|
||||
/>
|
||||
{ (errors.birthdate) ? <FormErrorMessage>{errors.birthdate.message as string}</FormErrorMessage> : "" }
|
||||
<Input type="date"
|
||||
{...register('birthdate', {
|
||||
required: {
|
||||
value: true,
|
||||
message: 'Date de naissance requise',
|
||||
},
|
||||
validate: validateDate,
|
||||
})}/>
|
||||
{(errors.birthdate) &&
|
||||
<FormErrorMessage>{errors.birthdate.message as string}</FormErrorMessage>}
|
||||
</FormControl>
|
||||
|
||||
{/*Mot de passe*/}
|
||||
<FormControl mb={'1rem'} id="password" isInvalid={errors.password as boolean|undefined}>
|
||||
<FormControl mb={'1rem'} id="password"
|
||||
isInvalid={errors.password as boolean | undefined}>
|
||||
<FormLabel>Mot de passe</FormLabel>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register('password', {
|
||||
required: {value: true, message: 'Mot de passe requis'},
|
||||
})}
|
||||
/>
|
||||
<Input type="password" placeholder="Mot de passe"
|
||||
{...register('password', {
|
||||
required: {value: true, message: 'Mot de passe requis'},
|
||||
})}/>
|
||||
<FormErrorMessage>{errors.password?.message as string}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
{/*Mot de passe (2)*/}
|
||||
<FormControl
|
||||
mb={'1rem'}
|
||||
id="confirmPassword"
|
||||
isInvalid={errors.confirmPassword as boolean|undefined}
|
||||
>
|
||||
<FormControl mb={'1rem'} id="confirmPassword"
|
||||
isInvalid={errors.confirmPassword as boolean | undefined}>
|
||||
<FormLabel>Confirmation du mot de passe</FormLabel>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register('confirmPassword', {
|
||||
required: {value: true, message: 'Confirmation requise'},
|
||||
validate: (value: string) => {
|
||||
return (
|
||||
watch('password') === value ||
|
||||
'Les mots de passe ne correspondent pas'
|
||||
);
|
||||
},
|
||||
})}
|
||||
/>
|
||||
<Input type="password" placeholder="Mot de passe"
|
||||
{...register('confirmPassword', {
|
||||
required: {value: true, message: 'Confirmation requise'},
|
||||
validate: (value: string) => (
|
||||
watch('password') === value ||
|
||||
'Les mots de passe ne correspondent pas'
|
||||
),
|
||||
})}/>
|
||||
<FormErrorMessage>{errors.confirmPassword?.message as string}</FormErrorMessage>
|
||||
</FormControl>
|
||||
|
||||
<Flex mt={'50px'} w={'100%'} justify={'space-between'} gap={5}>
|
||||
<Button onClick={() => router.push('/')} w={{base: '100%', md: 'unset'}}>
|
||||
<Button onClick={() => router.push('/')}
|
||||
w={{base: '100%', md: 'unset'}}>
|
||||
Retour
|
||||
</Button>
|
||||
<Button
|
||||
isLoading={isSubmitting}
|
||||
w={{base: '100%', md: 'unset'}}
|
||||
colorScheme="purple"
|
||||
type="submit"
|
||||
>
|
||||
<Button isLoading={isSubmitting} w={{base: '100%', md: 'unset'}}
|
||||
type="submit">
|
||||
Je m'inscris
|
||||
</Button>
|
||||
</Flex>
|
||||
|
||||
Reference in New Issue
Block a user