diff --git a/src/app/[practiceCode]/book/opengraph-image.tsx b/src/app/[practiceCode]/book/opengraph-image.tsx new file mode 100644 index 0000000..681860c --- /dev/null +++ b/src/app/[practiceCode]/book/opengraph-image.tsx @@ -0,0 +1,72 @@ +/* eslint-disable @next/next/no-img-element */ +import { ImageResponse } from 'next/server'; +import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; +import { cookies } from 'next/headers'; + +export const size = { + width: 800, + height: 500, +}; + +// Route segment config +export const runtime = 'edge'; +export const contentType = 'image/png'; + +const supabase = createServerComponentClient({ cookies }); + +export default async function og({ + params, +}: { + params: { practiceCode: string }; +}) { + const { practiceCode } = params; + + try { + const { data: practice } = await supabase + .from('Practice') + .select() + .eq('practice_code', practiceCode); + + if (!practice || practice.length === 0) { + throw new Error('Practice data not found'); + } + const [{ name, logo }] = practice; + const imageUrl = logo || '/connectient-logo.png'; + + return new ImageResponse( + ( +
+
+ {name} +
+
{name}
+
+ ), + ); + } catch (error) { + console.error(error); + } +} diff --git a/src/app/[practiceCode]/book/page.tsx b/src/app/[practiceCode]/book/page.tsx index 7537be0..7ab8d3a 100644 --- a/src/app/[practiceCode]/book/page.tsx +++ b/src/app/[practiceCode]/book/page.tsx @@ -7,6 +7,55 @@ import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; import { cookies } from 'next/headers'; import { redirect } from 'next/navigation'; +export async function generateMetadata({ + params, +}: { + params: { + practiceCode: string; + }; +}) { + const supabase = createServerComponentClient({ cookies }); + try { + const { practiceCode } = params; + const { data: practice } = await supabase + .from('Practice') + .select() + .eq('practice_code', practiceCode); + + if (!practice || practice.length === 0) + return { + title: 'Not Found', + description: 'The page you are looking for does not exist.', + }; + + const [{ name, logo }] = practice; + const imageUrl = logo || '/connectient-logo.png'; + + return { + title: name, + description: `Appointments Made Easy at ${name}`, + openGraph: { + images: [ + { + url: imageUrl, + + alt: `${name} Logo`, + }, + ], + }, + alternates: { + canonical: `/${practiceCode}/book`, + }, + }; + } catch (error) { + console.error(error); + return { + title: 'Not Found', + description: 'The page you are looking for does not exist.', + }; + } +} + export default async function Appointment({ params, }: { diff --git a/src/app/admin/dashboard/page.tsx b/src/app/admin/dashboard/page.tsx index 877f7d7..6faabd5 100644 --- a/src/app/admin/dashboard/page.tsx +++ b/src/app/admin/dashboard/page.tsx @@ -63,7 +63,7 @@ const AppointmentDashboard = async () => { return (
{practiceInfo && ( -
+
{practiceInfo.logo && ( { return ( - - - -
{children}
- -
- - - + <> + + + +
{children}
+ +
+ + + + ); }; diff --git a/src/components/AppointmentForm.tsx b/src/components/AppointmentForm.tsx index fb40cfb..8125c2a 100644 --- a/src/components/AppointmentForm.tsx +++ b/src/components/AppointmentForm.tsx @@ -483,7 +483,7 @@ const AppointmentForm = ({ (form.formState.isDirty && !form.formState.isValid) } > - Request Appointment + Send Request