From 4c7060a802a1ef3ac6f41dbf4c2a86f6d2988616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o?= <43091603+glazk0@users.noreply.github.com> Date: Mon, 4 Sep 2023 13:54:24 +0200 Subject: [PATCH] fix: remove unused nextjs folder --- components/ui/UserAuthForm.tsx | 204 --------------------------------- 1 file changed, 204 deletions(-) delete mode 100644 components/ui/UserAuthForm.tsx diff --git a/components/ui/UserAuthForm.tsx b/components/ui/UserAuthForm.tsx deleted file mode 100644 index 27094db..0000000 --- a/components/ui/UserAuthForm.tsx +++ /dev/null @@ -1,204 +0,0 @@ -'use client'; - -import { zodResolver } from '@hookform/resolvers/zod'; -import cookies from 'js-cookie'; -import { Loader2 } from 'lucide-react'; -import { usePathname, useRouter } from 'next/navigation'; -import { useState } from 'react'; -import { useForm } from 'react-hook-form'; -import * as z from 'zod'; - -import AppLink from '@/components/ui/AppLink'; -import { Button } from '@/components/ui/Button'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage -} from '@/components/ui/Form'; -import { Input } from '@/components/ui/Input'; - -const AuthFormSchema = z.object({ - pseudo: z.string().nonempty({ message: "Nom d'utilisateur requis" }), - email: z.string().optional(), - passwd: z.string().nonempty({ message: 'Mot de passe requis' }), - firstname: z.string().optional(), - lastname: z.string().optional(), - // Remove this soon cause not supported anymore - description: z.string().optional(), - sgroup: z.string().optional(), - avatar: z.string().optional() -}); - -export default function UserAuthForm() { - const form = useForm>({ - resolver: zodResolver(AuthFormSchema), - defaultValues: { - pseudo: '', - email: '', - passwd: '', - firstname: '', - lastname: '', - // Remove this soon cause not supported anymore - description: '', - sgroup: '', - avatar: '' - } - }); - - const [isLoading, setIsLoading] = useState(false); - - const router = useRouter(); - const pathname = usePathname()!; - - const isSignIn = pathname.includes('sign-in'); - - async function onSubmit(data: z.infer) { - setIsLoading(true); - - const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/${isSignIn ? 'login' : 'register'}`, - { - method: 'POST', - body: JSON.stringify(data) - } - ); - - if (!res) { - form.setError('passwd', { - type: 'manual', - message: "Une erreur s'est produite." - }); - setIsLoading(false); - return; - } - - if (!isSignIn) { - if (res.status === 400) { - const { username_valid, email_valid } = await res.json(); - if (!username_valid) { - form.setError('pseudo', { - message: "Nom d'utilisateur indisponible" - }); - setIsLoading(false); - return; - } - if (!email_valid) { - form.setError('email', { - message: 'Adresse e-mail indisponible' - }); - setIsLoading(false); - return; - } - } - } - - if (res.status === 200) { - const token = res.headers.get('Authorization')?.split(' ')[1]; - if (token) { - cookies.set('token', token, { - sameSite: 'strict', - secure: process.env.NODE_ENV === 'production' - }); - router.refresh(); - } - } else { - form.setError('passwd', { - message: "Nom d'utilisateur ou mot de passe incorrect" - }); - setIsLoading(false); - return; - } - } - - return ( -
- - {!isSignIn && ( - <> - ( - - Email - - - - - - )} - /> - ( - - Prénom - - - - - - )} - /> - ( - - Nom - - - - - - )} - /> - - )} - ( - - Nom d'utilisateur - - - - - - )} - /> - ( - - Mot de passe - - - - - - )} - /> - -

- {isSignIn ? "Vous n'avez pas de compte?" : 'Vous possédez un compte?'}{' '} - - {isSignIn ? "S'inscrire maintenant" : 'Se connecter'} - -

- - - ); -}