Updated the code to send the full page link

This commit is contained in:
Tiago Ribeiro
2024-02-27 14:22:59 +00:00
parent e02dce8878
commit 902d3adf55
2 changed files with 188 additions and 222 deletions

View File

@@ -16,7 +16,7 @@ interface PageProps {
}
async function getCountryManagers(country: string) {
const res = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/users/agents/${country}`);
const res = await fetch(`https://platform.encoach.com/api/users/agents/${country}`);
if (!res.ok) {
throw new Error("Failed to fetch contacts");
@@ -26,7 +26,7 @@ async function getCountryManagers(country: string) {
}
export async function generateStaticParams() {
const contacts = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/users/agents`).then((res) => res.json()) as Contact[];
const contacts = (await fetch(`https://platform.encoach.com/api/users/agents`).then((res) => res.json())) as Contact[];
// down the line, this is required to be loaded from a CMS
// for now, we'll just use a JSON file
@@ -37,11 +37,8 @@ export async function generateStaticParams() {
}));
}
export default async function Page({
params: { country },
searchParams: { page = "/contacts", language = "en" },
}: PageProps) {
const contact = await getCountryManagers(country) as Contact;
export default async function Page({params: {country}, searchParams: {page = "/contacts", language = "en"}}: PageProps) {
const contact = (await getCountryManagers(country)) as Contact;
return (
<main className="text-mti-black flex h-screen w-full flex-col bg-white">
<Navbar currentPage={page} language={language} />

View File

@@ -67,7 +67,7 @@ export default function App({ language, page }: Props) {
},
subject: data.subject,
type: data.type,
reportedFrom: window.location.href,
reportedFrom: window?.location.toString() || "",
status: "submitted",
date: new Date().toISOString(),
description: data.description,
@@ -90,10 +90,7 @@ export default function App({ language, page }: Props) {
return (
<>
<ToastContainer />
<main
className="text-mti-black flex h-screen w-full flex-col bg-white"
dir={language === "ar" ? "rtl" : "ltr"}
>
<main className="text-mti-black flex h-screen w-full flex-col bg-white" dir={language === "ar" ? "rtl" : "ltr"}>
<Navbar currentPage={page} language={language} />
<section className="w-full bg-mti-purple text-white text-center p-8 md:p-16">
<div className="w-full h-full flex flex-col items-center justify-center">
@@ -101,10 +98,7 @@ export default function App({ language, page }: Props) {
</div>
</section>
<section className="w-full bg-white text-center p-8 md:p-16 flex justify-center items-center gap-32">
<form
onSubmit={handleSubmit(onSubmit)}
className="form-control items-center gap-2 text-mti-black flex flex-col w-96"
>
<form onSubmit={handleSubmit(onSubmit)} className="form-control items-center gap-2 text-mti-black flex flex-col w-96">
<input
id="name"
type="text"
@@ -112,9 +106,7 @@ export default function App({ language, page }: Props) {
{...register("name", {required: true})}
className="input input-bordered md:w-full sm:w-1/2 max-w-md"
/>
{errors.name && errors.name.type === "required" && (
<ErrorMessage message={translation.fieldRequired[language]} />
)}
{errors.name && errors.name.type === "required" && <ErrorMessage message={translation.fieldRequired[language]} />}
<input
id="email"
placeholder={translation.email[language]}
@@ -122,12 +114,8 @@ export default function App({ language, page }: Props) {
{...register("email", {required: true, pattern: /^\S+@\S+$/i})}
className="input input-bordered md:w-full sm:w-1/2 max-w-md"
/>
{errors.email && errors.email.type === "required" && (
<ErrorMessage message={translation.fieldRequired[language]} />
)}
{errors.email && errors.email.type === "pattern" && (
<ErrorMessage message={translation.invalidEmail[language]} />
)}
{errors.email && errors.email.type === "required" && <ErrorMessage message={translation.fieldRequired[language]} />}
{errors.email && errors.email.type === "pattern" && <ErrorMessage message={translation.invalidEmail[language]} />}
<input
id="subject"
placeholder={translation.subject[language]}
@@ -135,14 +123,8 @@ export default function App({ language, page }: Props) {
{...register("subject", {required: true})}
className="input input-bordered md:w-full sm:w-1/2 max-w-md"
/>
{errors.subject && errors.subject.type === "required" && (
<ErrorMessage message={translation.fieldRequired[language]} />
)}
<select
id="type"
{...register("type", { required: true })}
className="select select-bordered md:w-full sm:w-1/2 max-w-md"
>
{errors.subject && errors.subject.type === "required" && <ErrorMessage message={translation.fieldRequired[language]} />}
<select id="type" {...register("type", {required: true})} className="select select-bordered md:w-full sm:w-1/2 max-w-md">
<option value="" disabled>
{translation.selectType[language]}
</option>
@@ -152,9 +134,7 @@ export default function App({ language, page }: Props) {
</option>
))}
</select>
{errors.type && errors.type.type === "required" && (
<ErrorMessage message={translation.fieldRequired[language]} />
)}
{errors.type && errors.type.type === "required" && <ErrorMessage message={translation.fieldRequired[language]} />}
<textarea
id="description"
placeholder={translation.description[language]}
@@ -165,21 +145,10 @@ export default function App({ language, page }: Props) {
{errors.description && errors.description.type === "required" && (
<ErrorMessage message={translation.fieldRequired[language]} />
)}
<input
type="submit"
className="btn"
disabled={!isDirty || !isValid}
value={translation.submit[language]}
/>
<input type="submit" className="btn" disabled={!isDirty || !isValid} value={translation.submit[language]} />
</form>
<div className="flex flex-col">
<Image
src="/person_laptop_focus.jpg"
alt="Contact Us"
width={500}
height={340}
className="rounded-xl"
/>
<Image src="/person_laptop_focus.jpg" alt="Contact Us" width={500} height={340} className="rounded-xl" />
</div>
</section>
<Footer language={language} />