From 4b869f7aa710daad01812c0402cd29e27bfea0bf Mon Sep 17 00:00:00 2001 From: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:51:13 -0700 Subject: [PATCH] fix verify, add resend verify page (#94) Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> --- .../app/(auth)/resend-verify/page.styles.tsx | 12 +++ .../src/app/(auth)/resend-verify/page.tsx | 17 ++++ apps/console/src/app/(auth)/verify/page.tsx | 8 +- apps/console/src/app/(auth)/waitlist/page.tsx | 4 +- apps/console/src/app/api/auth/resend/route.ts | 21 +++++ .../pages/auth/resend-verify/resend.styles.ts | 23 +++++ .../pages/auth/resend-verify/resend.tsx | 89 +++++++++++++++++++ .../pages/auth/subscribe/subscribe.tsx | 2 +- .../pages/auth/subscriber-verify/verifier.tsx | 48 +++++----- .../pages/auth/verify/page.styles.tsx | 22 +++++ .../components/pages/auth/verify/verifier.tsx | 31 ++++--- apps/console/src/lib/user.ts | 21 +++++ apps/console/src/middleware.ts | 2 +- 13 files changed, 256 insertions(+), 44 deletions(-) create mode 100644 apps/console/src/app/(auth)/resend-verify/page.styles.tsx create mode 100644 apps/console/src/app/(auth)/resend-verify/page.tsx create mode 100644 apps/console/src/app/api/auth/resend/route.ts create mode 100644 apps/console/src/components/pages/auth/resend-verify/resend.styles.ts create mode 100644 apps/console/src/components/pages/auth/resend-verify/resend.tsx create mode 100644 apps/console/src/components/pages/auth/verify/page.styles.tsx diff --git a/apps/console/src/app/(auth)/resend-verify/page.styles.tsx b/apps/console/src/app/(auth)/resend-verify/page.styles.tsx new file mode 100644 index 0000000..ec27ed0 --- /dev/null +++ b/apps/console/src/app/(auth)/resend-verify/page.styles.tsx @@ -0,0 +1,12 @@ +import { tv, type VariantProps } from 'tailwind-variants' + +const pageStyles = tv({ + slots: { + content: 'flex items-center justify-center h-screen relative', + form: 'w-full relative z-3 px-4' + }, +}) + +export type PageVariants = VariantProps + +export { pageStyles } diff --git a/apps/console/src/app/(auth)/resend-verify/page.tsx b/apps/console/src/app/(auth)/resend-verify/page.tsx new file mode 100644 index 0000000..b0c0684 --- /dev/null +++ b/apps/console/src/app/(auth)/resend-verify/page.tsx @@ -0,0 +1,17 @@ +'use client' + +import { Resend } from '@/components/pages/auth/resend-verify/resend' +import { pageStyles } from './page.styles' + +const ResendVerification: React.FC = () => { + const { content, form } = pageStyles() + return ( +
+
+ +
+
+ ) +} + +export default ResendVerification diff --git a/apps/console/src/app/(auth)/verify/page.tsx b/apps/console/src/app/(auth)/verify/page.tsx index 223a619..20c06b0 100644 --- a/apps/console/src/app/(auth)/verify/page.tsx +++ b/apps/console/src/app/(auth)/verify/page.tsx @@ -2,18 +2,18 @@ import { Suspense } from 'react' import { LoaderCircle } from 'lucide-react' -import { TokenVerifier } from '@/components/pages/auth/subscriber-verify/verifier' +import { TokenVerifier } from '@/components/pages/auth/verify/verifier' export const dynamic = 'force-dynamic' const VerifyUser: React.FC = () => { - return( + return ( } > - ) - } + ) +} export default VerifyUser diff --git a/apps/console/src/app/(auth)/waitlist/page.tsx b/apps/console/src/app/(auth)/waitlist/page.tsx index cdd2cb5..cfa8e09 100644 --- a/apps/console/src/app/(auth)/waitlist/page.tsx +++ b/apps/console/src/app/(auth)/waitlist/page.tsx @@ -2,7 +2,7 @@ import { Logo } from '@repo/ui/logo' import { Panel } from '@repo/ui/panel' -import {Subscribe} from '@/components/pages/auth/subscribe/subscribe' +import { Subscribe } from '@/components/pages/auth/subscribe/subscribe' import Link from 'next/link' const Waitlist: React.FC = () => { @@ -18,7 +18,7 @@ const Waitlist: React.FC = () => {
We are currently in a private beta, please subscribe to our newsletter to get notified when we launch.
- + diff --git a/apps/console/src/app/api/auth/resend/route.ts b/apps/console/src/app/api/auth/resend/route.ts new file mode 100644 index 0000000..d35c741 --- /dev/null +++ b/apps/console/src/app/api/auth/resend/route.ts @@ -0,0 +1,21 @@ +import { NextResponse } from 'next/server' + +export async function POST(request: Request) { + const bodyData = await request.json() + + const fData = await fetch(`${process.env.API_REST_URL}/v1/resend`, { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify(bodyData), + }) + + if (fData.ok) { + return NextResponse.json(await fData.json(), { status: 200 }) + } + + if (fData.status !== 201) { + return NextResponse.json(await fData.json(), { status: fData.status }) + } +} diff --git a/apps/console/src/components/pages/auth/resend-verify/resend.styles.ts b/apps/console/src/components/pages/auth/resend-verify/resend.styles.ts new file mode 100644 index 0000000..d869aea --- /dev/null +++ b/apps/console/src/components/pages/auth/resend-verify/resend.styles.ts @@ -0,0 +1,23 @@ +import { tv, type VariantProps } from 'tailwind-variants' + +const resendStyles = tv({ + slots: { + logo: 'flex justify-center mb-10', + text: "text-center text-sm", + header: "text-xl text-center", + wrapper: 'relative mt-1 flex flex-col gap-2 md:flex-row', + input: 'w-full h-12 md:h-auto text-ziggurat-900', + button: + 'absolute h-10 text-md md:relative md:text-md md:top-0 md:h-14', + errorMessage: 'text-ziggurat-200 mt-14', + success: + 'mt-14 text-center bg-ziggurat-900 bg-opacity-20 p-5 rounded-md text-white flex gap-3', + successMessage: 'flex-1', + successIcon: 'mt-1', + }, +}) + + +export type ResendVariants = VariantProps + +export { resendStyles } diff --git a/apps/console/src/components/pages/auth/resend-verify/resend.tsx b/apps/console/src/components/pages/auth/resend-verify/resend.tsx new file mode 100644 index 0000000..f976e2c --- /dev/null +++ b/apps/console/src/components/pages/auth/resend-verify/resend.tsx @@ -0,0 +1,89 @@ +'use client' + +import { zodResolver } from '@hookform/resolvers/zod' +import { useForm } from 'react-hook-form' +import { z } from 'zod' + +import { Button } from '@repo/ui/button' +import { + Form, + FormField, + FormControl, + FormMessage, + FormLabel, +} from '@repo/ui/form' +import { Input } from '@repo/ui/input' +import { resendStyles } from './resend.styles' +import { resendVerification } from '@/lib/user' +import { useRouter } from 'next/navigation' +import { Panel } from '@repo/ui/panel' +import { Logo } from '@repo/ui/logo' + +const formSchema = z.object({ + email: z.string().email(), +}) + +export const Resend = () => { + const router = useRouter() + + const { + wrapper, + input, + button, + text, + header, + logo, + } = resendStyles() + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + email: '', + }, + }) + + const onSubmit = ({ email }: z.infer) => { + const result = resendVerification({ email }) + router.push('/verify') + } + + + return ( + <> + +
+ +
+

Can't find that email?

+

+ We got you, enter your email to have our robots
+ resend that verification email right over to you.

+
+ + ( + <> + Email + + + + + + )} + /> + + + +
+ + ) +} diff --git a/apps/console/src/components/pages/auth/subscribe/subscribe.tsx b/apps/console/src/components/pages/auth/subscribe/subscribe.tsx index 825bf5b..cd713dd 100644 --- a/apps/console/src/components/pages/auth/subscribe/subscribe.tsx +++ b/apps/console/src/components/pages/auth/subscribe/subscribe.tsx @@ -61,7 +61,7 @@ export const Subscribe = () => { return ( <> - {data ? ( + {data ? (
diff --git a/apps/console/src/components/pages/auth/subscriber-verify/verifier.tsx b/apps/console/src/components/pages/auth/subscriber-verify/verifier.tsx index 2b18a5e..6cdb576 100644 --- a/apps/console/src/components/pages/auth/subscriber-verify/verifier.tsx +++ b/apps/console/src/components/pages/auth/subscriber-verify/verifier.tsx @@ -7,8 +7,8 @@ import { verificationStyles } from './page.styles' import { Logo } from '@repo/ui/logo' export const TokenVerifier = () => { - const { errorMessage, successMessage, successIcon, success, loading } = - verificationStyles() + const { errorMessage, successMessage, successIcon, success, loading } = + verificationStyles() const searchParams = useSearchParams() const token = searchParams.get('token') @@ -41,7 +41,7 @@ export const TokenVerifier = () => { return ( <>
- +
No token provided, please check your email for a verification link. @@ -52,40 +52,40 @@ export const TokenVerifier = () => { if (error) { return ( - <> -
- -
-
{error}
- + <> +
+ +
+
{error}
+ ) } if (message) { return ( <> -
+
-
-
- - - Thank you for subscribing. Your email is now verified. - -
+
+
+ + + Thank you for subscribing. Your email is now verified. + +
) } return ( <> -
- -
-
- - Verifying -
+
+ +
+
+ + Verifying +
) } \ No newline at end of file diff --git a/apps/console/src/components/pages/auth/verify/page.styles.tsx b/apps/console/src/components/pages/auth/verify/page.styles.tsx new file mode 100644 index 0000000..43ce027 --- /dev/null +++ b/apps/console/src/components/pages/auth/verify/page.styles.tsx @@ -0,0 +1,22 @@ +import { tv, type VariantProps } from 'tailwind-variants' + +const verificationStyles = tv({ + slots: { + content: 'flex flex-col min-h-screen w-full items-center space-between dark:bg-dk-surface-0 bg-surface-0', + wrapper: 'flex flex-col justify-center mx-auto my-auto w-full p-6 sm:w-1/3 h-full relative ease-in-out', + errorMessage: 'text-ziggurat-200 mt-14', + success: + 'mt-14 bg-ziggurat-900 bg-opacity-20 p-5 rounded-md text-white justify-center text-center', + successMessage: 'text-center', + successIcon: 'mt-1 justify-center items-center', + loading: 'mt-14 p-5 rounded-md text-white flex gap-3', + resendMessage: 'text-xs text-gray-400 mt-4 text-center', + button: 'mt-12 flex w-full justify-center', + logo: 'mx-auto b-3', + verifying: 'text-3xl text-center mt-4 animate-pulse', + }, +}) + +export type VerificationVariants = VariantProps + +export { verificationStyles } \ No newline at end of file diff --git a/apps/console/src/components/pages/auth/verify/verifier.tsx b/apps/console/src/components/pages/auth/verify/verifier.tsx index e2e7455..613bfd0 100644 --- a/apps/console/src/components/pages/auth/verify/verifier.tsx +++ b/apps/console/src/components/pages/auth/verify/verifier.tsx @@ -2,12 +2,18 @@ import { useEffect } from 'react' import { Button } from '@repo/ui/button' -import { useSearchParams } from 'next/navigation' +import { useRouter, useSearchParams } from 'next/navigation' import { signIn } from 'next-auth/react' import { Logo } from '@repo/ui/logo' import { useVerifyUser } from '@/lib/user' +import { verificationStyles } from './page.styles' +import { buttonVariants } from '@repo/ui/plate-ui/button' export const TokenVerifier = () => { + const { successMessage, button, success, content, logo, wrapper, verifying } = + verificationStyles() + + const router = useRouter() const searchParams = useSearchParams() const token = searchParams?.get('token') @@ -27,28 +33,29 @@ export const TokenVerifier = () => { }, [verified, error]) return ( -
-
-
+
+
+
{isLoading ? ( -

+

Verifying your account...

) : null} {!isLoading && ( -
-

- Please check your email to verify your account. -

+
+ + Thank you for signing up for Openlane!
+ Check your email and give that awesome verification link a click to get started. +
)} -
+