Skip to content

Commit

Permalink
Merge pull request #22 from AjelmarMedina/development
Browse files Browse the repository at this point in the history
CTA & DB Optimization fixes
  • Loading branch information
AjelmarMedina authored Apr 27, 2024
2 parents b2226df + 430f85f commit 1c7b77c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 1c7b77c

Please sign in to comment.