Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTA & DB Optimization fixes #22

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ model Certifications {

model PortfolioContacts {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
date DateTime @db.Date @default(now())
name String
email String
message String
Expand Down
20 changes: 19 additions & 1 deletion src/components/(cta)/cta-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { toast } from "@/lib/use-toast";
import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { Button } from "../ui/button";
Expand All @@ -29,6 +31,7 @@ const formSchema = z.object({
})

export function CtaForm() {
const [isSubmitted, setSubmitted] = useState(false);
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
Expand All @@ -39,6 +42,7 @@ export function CtaForm() {
})

function onSubmit(values: z.infer<typeof formSchema>) {
setSubmitted(true);
const data = JSON.stringify(values);
fetch("/contact", {
method: "POST", // or 'PUT'
Expand All @@ -48,10 +52,16 @@ export function CtaForm() {
body: JSON.stringify(data),
})
.then((response) => {
toast({
title: "Thank you for reaching out!"
})
// const result = response.json();
// console.log("Success:", result);
})
.catch((error) => {
toast({
title: "Something went wrong..."
})
console.error("Error:", error);
})
}
Expand Down Expand Up @@ -113,7 +123,15 @@ export function CtaForm() {
)}
/>
</div>
<Button variant={"fill"} fill={"light"} outline={"dark"} type="submit" className="w-full">
<Button
variant={"fill"}
fill={"light"}
outline={"dark"}
type="submit"
className="w-full"
disabled={isSubmitted}
aria-disabled={isSubmitted}
>
Submit
</Button>
</form>
Expand Down