From 5b7ccf0b671e2999b62befc729a3e517a0433728 Mon Sep 17 00:00:00 2001 From: Bertrand Yuan Date: Mon, 15 Dec 2025 23:48:10 +0800 Subject: initial commit -- the front-end prototype The initial code is base on Anirudh's work. More to see at: https://github.com/techwithanirudh/shadcn-blog Therefore, the code in this commit is under MIT license. --- src/components/newsletter-form.tsx | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/components/newsletter-form.tsx (limited to 'src/components/newsletter-form.tsx') diff --git a/src/components/newsletter-form.tsx b/src/components/newsletter-form.tsx new file mode 100644 index 0000000..7dd0cc0 --- /dev/null +++ b/src/components/newsletter-form.tsx @@ -0,0 +1,96 @@ +'use client'; + +import { useAction } from 'next-safe-action/hooks'; + +import { Button } from '@/components/ui/button'; +import { + Form, + FormControl, + FormField, + FormItem, + FormMessage, +} from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import type { Newsletter } from '@/lib/validators'; +import { NewsletterSchema } from '@/lib/validators'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; + +import { Alert, AlertTitle } from '@/components/ui/alert'; + +import { subscribeUser } from '@/app/(home)/actions'; +import { Icons } from '@/components/icons/icons'; + +export const NewsletterForm = () => { + const form = useForm({ + resolver: zodResolver(NewsletterSchema), + defaultValues: { + email: '', + }, + }); + + const { execute, result, status } = useAction(subscribeUser); + + const onSubmit = (values: Newsletter) => { + execute(values); + }; + + return ( +
+ +
+
+ ( + + + + + + + )} + /> +
+ + +
+ + {status === 'hasSucceeded' && ( + + + + {result.data?.message ?? "Hmm... Our server didn't respond."} + + + )} + {result.serverError && ( + + + + {result.serverError} + + + )} +
+ + ); +}; -- cgit v1.2.3