From 259e6ba5557ebfd3fa3f027c579f762d1d0c6374 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Fri, 26 Apr 2024 13:43:41 +0700 Subject: [PATCH] Add contact form, cookie banner, and update packages This commit includes the addition of a contact form and a cookie banner to improve user experience and comply with regulations. The contact form involves email submission functionality. Several packages have also been updated and new routes have been added to the sitemap for better SEO. Environment variables have also been adjusted for email and contact form functionality. --- apps/web/.env.development | 5 + .../contact/_components/contact-form.tsx | 161 ++++++++++++++++++ .../contact/_lib/contact-email.schema.ts | 7 + .../contact/_lib/server/server-actions.ts | 51 ++++++ apps/web/app/(marketing)/contact/page.tsx | 31 +++- apps/web/app/server-sitemap.xml/route.ts | 3 + apps/web/public/locales/en/common.json | 6 + apps/web/public/locales/en/marketing.json | 13 +- packages/next/src/actions/index.ts | 58 ++++--- packages/ui/package.json | 3 +- packages/ui/src/makerkit/cookie-banner.tsx | 120 +++++++++++++ turbo/generators/templates/package.json.hbs | 4 +- 12 files changed, 435 insertions(+), 27 deletions(-) create mode 100644 apps/web/app/(marketing)/contact/_components/contact-form.tsx create mode 100644 apps/web/app/(marketing)/contact/_lib/contact-email.schema.ts create mode 100644 apps/web/app/(marketing)/contact/_lib/server/server-actions.ts create mode 100644 packages/ui/src/makerkit/cookie-banner.tsx diff --git a/apps/web/.env.development b/apps/web/.env.development index 99bb9a23b..03afb0b1b 100644 --- a/apps/web/.env.development +++ b/apps/web/.env.development @@ -4,10 +4,12 @@ # SUPABASE NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321 NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0 +SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU ## THIS IS FOR DEVELOPMENT ONLY - DO NOT USE IN PRODUCTION SUPABASE_DB_WEBHOOK_SECRET=WEBHOOKSECRET +# EMAILS EMAIL_SENDER=test@makerkit.dev EMAIL_PORT=54325 EMAIL_HOST=localhost @@ -15,6 +17,9 @@ EMAIL_TLS=false EMAIL_USER=user EMAIL_PASSWORD=password +# CONTACT FORM +CONTACT_EMAIL=test@makerkit.dev + # STRIPE NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= diff --git a/apps/web/app/(marketing)/contact/_components/contact-form.tsx b/apps/web/app/(marketing)/contact/_components/contact-form.tsx new file mode 100644 index 000000000..106cf0ffa --- /dev/null +++ b/apps/web/app/(marketing)/contact/_components/contact-form.tsx @@ -0,0 +1,161 @@ +'use client'; + +import { useState, useTransition } from 'react'; + +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; + +import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert'; +import { Button } from '@kit/ui/button'; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@kit/ui/form'; +import { Input } from '@kit/ui/input'; +import { Textarea } from '@kit/ui/textarea'; +import { Trans } from '@kit/ui/trans'; + +import { ContactEmailSchema } from '~/(marketing)/contact/_lib/contact-email.schema'; +import { sendContactEmail } from '~/(marketing)/contact/_lib/server/server-actions'; + +export function ContactForm() { + const [pending, startTransition] = useTransition(); + + const [state, setState] = useState({ + success: false, + error: false, + }); + + const form = useForm({ + resolver: zodResolver(ContactEmailSchema), + defaultValues: { + name: '', + email: '', + message: '', + }, + }); + + if (state.success) { + return ; + } + + if (state.error) { + return ; + } + + return ( +
+ { + startTransition(async () => { + try { + await sendContactEmail(data); + + setState({ success: true, error: false }); + } catch (error) { + setState({ error: true, success: false }); + } + }); + })} + > + { + return ( + + + + + + + + + + + + ); + }} + /> + + { + return ( + + + + + + + + + + + + ); + }} + /> + + { + return ( + + + + + + +