From d6dd76021226802adf5295b3243d6f2ae4fa5cc2 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 10 Mar 2024 17:59:58 +0000 Subject: refactor: Move all components to the top level directory --- .../web/app/signin/components/CredentialsForm.tsx | 222 --------------------- 1 file changed, 222 deletions(-) delete mode 100644 packages/web/app/signin/components/CredentialsForm.tsx (limited to 'packages/web/app/signin/components/CredentialsForm.tsx') diff --git a/packages/web/app/signin/components/CredentialsForm.tsx b/packages/web/app/signin/components/CredentialsForm.tsx deleted file mode 100644 index 5296e163..00000000 --- a/packages/web/app/signin/components/CredentialsForm.tsx +++ /dev/null @@ -1,222 +0,0 @@ -"use client"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm } from "react-hook-form"; -import { z } from "zod"; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form"; -import { Input } from "@/components/ui/input"; -import { ActionButton } from "@/components/ui/action-button"; -import { zSignUpSchema } from "@hoarder/trpc/types/users"; -import { signIn } from "next-auth/react"; -import { useState } from "react"; -import { api } from "@/lib/trpc"; -import { useRouter } from "next/navigation"; -import { TRPCClientError } from "@trpc/client"; - -const signInSchema = z.object({ - email: z.string().email(), - password: z.string(), -}); - -function SignIn() { - const [signinError, setSigninError] = useState(false); - const router = useRouter(); - const form = useForm>({ - resolver: zodResolver(signInSchema), - }); - - return ( -
- { - const resp = await signIn("credentials", { - redirect: false, - email: value.email, - password: value.password, - }); - if (!resp || !resp?.ok) { - setSigninError(true); - return; - } - router.replace("/"); - })} - > -
- {signinError && ( -

- Incorrect username or password -

- )} - { - return ( - - Email - - - - - - ); - }} - /> - { - return ( - - Password - - - - - - ); - }} - /> - - Sign In - -
-
- - ); -} - -function SignUp() { - const form = useForm>({ - resolver: zodResolver(zSignUpSchema), - }); - const [errorMessage, setErrorMessage] = useState(""); - - const router = useRouter(); - - const createUserMutation = api.users.create.useMutation(); - - return ( -
- { - try { - await createUserMutation.mutateAsync(value); - } catch (e) { - if (e instanceof TRPCClientError) { - setErrorMessage(e.message); - } - return; - } - const resp = await signIn("credentials", { - redirect: false, - email: value.email, - password: value.password, - }); - if (!resp || !resp.ok) { - setErrorMessage("Hit an unexpected error while signing in"); - return; - } - router.replace("/"); - })} - > -
- {errorMessage && ( -

{errorMessage}

- )} - { - return ( - - Name - - - - - - ); - }} - /> - { - return ( - - Email - - - - - - ); - }} - /> - { - return ( - - Password - - - - - - ); - }} - /> - { - return ( - - Confirm Password - - - - - - ); - }} - /> - - Sign Up - -
-
- - ); -} - -export default function CredentialsForm() { - return ( - - - Sign In - Sign Up - - - - - - - - - ); -} -- cgit v1.2.3-70-g09d2