diff --git a/src/app/contacts/[country]/page.tsx b/src/app/contacts/[country]/page.tsx new file mode 100644 index 0000000..b7eb476 --- /dev/null +++ b/src/app/contacts/[country]/page.tsx @@ -0,0 +1,78 @@ +import Footer from "@/components/Footer"; +import Navbar from "@/components/Navbar"; +import Title from "@/components/Title"; +import contacts from "../../../contacts.json"; + +interface Contact { + key: string; + label: string; + entries: { + name: string; + number: string; + email: string; + }[]; +} + +type Language = "en" | "ar"; + +interface PageProps { + params: { + country: string; + }; + searchParams: { + page: string; + language: Language; + }; +} + +export function generateStaticParams() { + // down the line, this is required to be loaded from a CMS + // for now, we'll just use a JSON file + + // do not forget the actually render this as multiple languages + return contacts.map(({ key }) => ({ + country: key.toLowerCase().replaceAll(" ", ""), + })); +} + +export default function Page({ + params: { country }, + searchParams: { page = "/contacts", language = "en" }, +}: PageProps) { + // this approach will not be viable later on when we have multiple languages + // or use the data from the server + // replace this with a fetch to the CMS + const contact = contacts.find(({ key }) => key === country) as Contact; + + return ( +
+ + +
+
+ {`${contact.label} Contacts`} +
+
+ +
+ {contact.entries.map((entry) => ( +
+

+ Name: + {entry.name} +

+

+ Number: + {entry.number} +

+

+ Email: + {entry.email} +

+
+ ))} +
+
+ ); +} diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index b19600a..78b05a7 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -8,7 +8,7 @@ import { BsList, BsXLg } from "react-icons/bs"; import { Fragment, useState } from "react"; import { Dialog, Transition } from "@headlessui/react"; import translation from "@/translation/navbar.json"; -import NestedNavbarEntry from "@/components/NestedNavbarEntry"; +import contacts from "@/contacts.json"; const items = [ { page: "/", key: "home" }, @@ -19,40 +19,11 @@ const items = [ { page: "/contact", key: "contact" }, { key: "country_manager", - page: '', - entries: [ - { - key: "Egypt", - entries: [ - { - name: "Modern Technology", - number: "+226578480830", - email: "egypt@encoach.com", - }, - ], - }, - { - key: "Oman", - entries: [ - { - name: "Smartway education", - number: "+9689944094", - email: "oman@encoach.com", - }, - { name: "MTI", number: "+9687445609", email: "mti@encoach.com" }, - ], - }, - { - key: "Saudi Arabia", - entries: [ - { - name: "Edutrach services", - number: "+96658499347", - email: "edu@encoach.com", - }, - ], - }, - ], + page: "/contacts", + entries: contacts.map((data) => ({ + key: data.key, + label: data.label, + })), }, ]; @@ -64,7 +35,6 @@ export default function Navbar({ language: "en" | "ar"; }) { const [isOpen, setIsOpen] = useState(false); - return ( <>
@@ -84,12 +54,30 @@ export default function Navbar({ > {items.map((item) => item.entries ? ( - + className={clsx( + "group relative hover:border-b-mti-purple-light transition duration-300 ease-in-out hover:border-b-2 z-10 cursor-pointer", + currentPage === item.page && + "border-b-mti-purple-light border-b-2" + )} + > + + {translation[item.key as keyof typeof translation][language]} + + + ) : ( { - const [open, setOpen] = React.useState(null); - - return ( -
    - {entry.entries.map((entry) => ( -
  • -
    setOpen(entry.key)} - onMouseLeave={() => setOpen(null)} - > - {entry.key} - {open === entry.key && ( -
      - {entry.entries.map((value) => ( -
    • - {value.name} -
    • - ))} -
    - )} -
    -
  • - ))} -
- ); -}; - -const NestedNavbarEntry = ({ - entry, - language, - translation -}: { - entry: NavbarEntry; - language: "en" | "ar"; - translation: any -}) => { - const [open, setOpen] = React.useState(null); - - return ( -
setOpen(entry.key)} - onMouseLeave={() => setOpen(null)} - > - - {translation[entry.key][language]} - - -
- ); -}; - -export default NestedNavbarEntry; \ No newline at end of file diff --git a/src/contacts.json b/src/contacts.json new file mode 100644 index 0000000..f69e645 --- /dev/null +++ b/src/contacts.json @@ -0,0 +1,36 @@ +[ + { + "label": "Egypt", + "key": "egypt", + "entries": [ + { + "name": "Modern Technology", + "number": "+226578480830", + "email": "egypt@encoach.com" + } + ] + }, + { + "label": "Oman", + "key": "oman", + "entries": [ + { + "name": "Smartway education", + "number": "+9689944094", + "email": "oman@encoach.com" + }, + { "name": "MTI", "number": "+9687445609", "email": "mti@encoach.com" } + ] + }, + { + "label": "Saudi Arabia", + "key": "saudiarabia", + "entries": [ + { + "name": "Edutrach services", + "number": "+96658499347", + "email": "edu@encoach.com" + } + ] + } +]