From d2f8afac01f1b9a596129806e00a68ad8b8924af Mon Sep 17 00:00:00 2001 From: RizqiSyahrendra Date: Mon, 3 Mar 2025 21:52:24 +0700 Subject: [PATCH] fix: render contact & form dynamically from payload --- src/app/(main)/contact/page.tsx | 24 -- src/blocks/Contact.ts | 7 + src/collections/Pages.ts | 4 + src/components/Blocks/Contact/index.tsx | 284 ++++++++++++++++++ src/components/Blocks/Form/Checkbox/index.tsx | 2 +- src/components/Blocks/Form/index.tsx | 24 +- src/components/Blocks/RenderBlocks.tsx | 15 + src/payload-types.ts | 42 +++ 8 files changed, 370 insertions(+), 32 deletions(-) delete mode 100644 src/app/(main)/contact/page.tsx create mode 100644 src/blocks/Contact.ts create mode 100644 src/components/Blocks/Contact/index.tsx diff --git a/src/app/(main)/contact/page.tsx b/src/app/(main)/contact/page.tsx deleted file mode 100644 index 88a0474..0000000 --- a/src/app/(main)/contact/page.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import Contact from "@/components/Contacts/Contact"; -import ContactForm from "@/components/Contacts/ContactForm"; -import HeroOther from "@/components/HeroOther"; -import { Suspense } from "react"; - -export const metadata = { - title: "Contact - Cochise Oncology", - description: "Contact - Cochise Oncology", -}; - -export default async function ContactPage() { - return ( - <> - - -
- - }> - - -
- - ); -} diff --git a/src/blocks/Contact.ts b/src/blocks/Contact.ts new file mode 100644 index 0000000..bfdd32e --- /dev/null +++ b/src/blocks/Contact.ts @@ -0,0 +1,7 @@ +import { Block } from "payload"; + +export const ContactBlock: Block = { + slug: "contactBlock", + labels: { plural: "Contacts", singular: "Contacts" }, + fields: [], +}; diff --git a/src/collections/Pages.ts b/src/collections/Pages.ts index b5d4bff..fec04fe 100644 --- a/src/collections/Pages.ts +++ b/src/collections/Pages.ts @@ -1,6 +1,8 @@ import { BeforeFooterBlock } from "@/blocks/BeforeFooter"; import { BoxMenuGridBlock } from "@/blocks/BoxMenuGrid"; +import { ContactBlock } from "@/blocks/Contact"; import { ContentBlock } from "@/blocks/Content"; +import { FormBlock } from "@/blocks/Form"; import { GoogleReviewBlock } from "@/blocks/GoogleReview"; import { HorizontalImageContentBlock } from "@/blocks/HorizontalImageContent"; import { ImageSliderBlock } from "@/blocks/ImageSlider"; @@ -47,6 +49,8 @@ export const Pages: CollectionConfig = { ImageSliderBlock, BoxMenuGridBlock, GoogleReviewBlock, + ContactBlock, + FormBlock, ], }, { diff --git a/src/components/Blocks/Contact/index.tsx b/src/components/Blocks/Contact/index.tsx new file mode 100644 index 0000000..85069be --- /dev/null +++ b/src/components/Blocks/Contact/index.tsx @@ -0,0 +1,284 @@ +import { fetchContact } from "@/services/payload/contact"; +import { Suspense } from "react"; + +export default function ContactBlock() { + return ( + <> + }> + + + + ); +} + +async function ContactWithData() { + const contact = await fetchContact(); + + return ( +
+
+
+
+
+

Contact Us

+
+
+
+
+
+
+ {/* Contact Form */} +
+ {/* Contact Item */} +
+
+
+ +
+ +

Location

+ +
+
+ {/* End Contact Item */} + {/* Contact Item */} +
+
+
+ +
+

Phone

+ +
+
+ {/* End Contact Item */} +
+
+ {/* Contact Item */} +
+
+
+ +
+

Hours

+
+ {Array.isArray(contact?.hours) && + contact.hours.map((h) => ( +

+ {h.hour ?? ""} +

+ ))} +
+
+
+ {/* End Contact Item */} + {/* Contact Item */} +
+
+
+ +
+

Fax

+ +
+
+ {/* End Contact Item */} +
+ {/* End Contact Form */} +
+
+ {/* Google Map */} +
+