From db9a02b84724c621a37ec161b8cebc0b313985fb Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 12 Jul 2025 09:45:41 +0000 Subject: feat(ui): Revamp the signin/signup page --- apps/web/components/signup/SignUpForm.tsx | 228 ++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 apps/web/components/signup/SignUpForm.tsx (limited to 'apps/web/components/signup') diff --git a/apps/web/components/signup/SignUpForm.tsx b/apps/web/components/signup/SignUpForm.tsx new file mode 100644 index 00000000..85346f98 --- /dev/null +++ b/apps/web/components/signup/SignUpForm.tsx @@ -0,0 +1,228 @@ +"use client"; + +import { useState } from "react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { ActionButton } from "@/components/ui/action-button"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { useClientConfig } from "@/lib/clientConfig"; +import { api } from "@/lib/trpc"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { TRPCClientError } from "@trpc/client"; +import { AlertCircle, UserX } from "lucide-react"; +import { signIn } from "next-auth/react"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; + +import { zSignUpSchema } from "@karakeep/shared/types/users"; + +const VERIFY_EMAIL_ERROR = "Please verify your email address before signing in"; + +export default function SignUpForm() { + const form = useForm>({ + resolver: zodResolver(zSignUpSchema), + }); + const [errorMessage, setErrorMessage] = useState(""); + const router = useRouter(); + const clientConfig = useClientConfig(); + + const createUserMutation = api.users.create.useMutation(); + + if ( + clientConfig.auth.disableSignups || + clientConfig.auth.disablePasswordAuth + ) { + return ( + + + + Sign Up Unavailable + + + Account registration is currently disabled + + + +
+ + + + Signups are currently disabled. Please contact an administrator + for access. + + + +
+
+
+ ); + } + + return ( + + + + Create Your Account + + + Join Karakeep to start organizing your bookmarks + + + +
+ { + 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.trim(), + password: value.password, + }); + if (!resp || !resp.ok || resp.error) { + if (resp?.error === VERIFY_EMAIL_ERROR) { + router.replace( + `/check-email?email=${encodeURIComponent(value.email.trim())}`, + ); + } else { + setErrorMessage( + resp?.error ?? "Hit an unexpected error while signing in", + ); + } + return; + } + router.replace("/"); + })} + className="space-y-4" + > + {errorMessage && ( + + + {errorMessage} + + )} + + ( + + Full Name + + + + + + )} + /> + + ( + + Email + + + + + + )} + /> + + ( + + Password + + + + + + )} + /> + + ( + + Confirm Password + + + + + + )} + /> + + + Create Account + + + + +
+

+ Already have an account?{" "} + + Sign in + +

+
+
+
+ ); +} -- cgit v1.2.3-70-g09d2