diff --git a/components/ServiceSectionS2/ServiceSectionS2.js b/components/ServiceSectionS2/ServiceSectionS2.js index 946fc73..15279cb 100644 --- a/components/ServiceSectionS2/ServiceSectionS2.js +++ b/components/ServiceSectionS2/ServiceSectionS2.js @@ -1,21 +1,38 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { TabContent, TabPane, Nav, NavItem, NavLink, Row } from "reactstrap"; import classnames from "classnames"; import Link from "next/link"; import Image from "next/image"; -import { TabServices } from "../../utils/constant.utils"; // JSON array -import Campaign from "../../api/campaign"; +import { useTranslation } from "next-i18next"; const ClickHandler = () => { - window.scrollTo(10, 0); + window.scrollTo(0, 0); }; -// Extract unique categories from the JSON dynamically -const categories = [...new Set(Campaign.map((service) => service.category))]; - const ServiceSectionS2 = () => { + const { t, i18n } = useTranslation("services"); + + // Get campaigns array from the translation JSON + const campaigns = t("campaigns", { returnObjects: true }); + + // Extract unique categories from the campaigns dynamically + const categories = [...new Set(campaigns.map((service) => service.category))]; + + // Default active tab is the first category, but we will set it dynamically based on the language const [activeTab, setActiveTab] = useState(categories[0]); + // Function to change the active tab based on the selected language + const changeActiveTabOnLanguageChange = () => { + // Set the active tab to the first category whenever the language changes + setActiveTab(categories[0]); + }; + + // Track language changes using the `useEffect` hook + useEffect(() => { + // Whenever the language changes, reset the active tab + changeActiveTabOnLanguageChange(); + }, [i18n.language]); // `i18n.language` triggers the effect when the language changes + const toggle = (tab) => { if (activeTab !== tab) setActiveTab(tab); }; @@ -26,7 +43,7 @@ const ServiceSectionS2 = () => {
{/* Tab Navigation */}
- ) - )} + ))} ))} diff --git a/components/header2/Header2.js b/components/header2/Header2.js index 5dea9f8..b29db5a 100644 --- a/components/header2/Header2.js +++ b/components/header2/Header2.js @@ -83,7 +83,7 @@ const Header2 = (props) => {
diff --git a/next-i18next.config.js b/next-i18next.config.js index 8de3690..aba8eff 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -5,7 +5,7 @@ module.exports = { locales: ['en', 'es'], localeDetection: false, }, - ns: ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer', 'ourMission', 'racialJustice', 'services', 'ourStory', 'aboutService', 'aboutMission', 'aboutRacial', 'aboutDonor'], + ns: ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer', 'ourMission', 'racialJustice', 'services', 'ourStory', 'aboutService', 'aboutMission', 'aboutRacial', 'aboutDonor', 'OurApproach', 'contact'], defaultNS: 'common', // localePath: './public/locales', }; diff --git a/pages/index.js b/pages/index.js index 6b8da0b..cdb01ca 100644 --- a/pages/index.js +++ b/pages/index.js @@ -40,7 +40,7 @@ export default HomePage; export async function getStaticProps({ locale }) { return { props: { - ...(await serverSideTranslations(locale, ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer'])), // Add 'home', 'footer', etc. if needed + ...(await serverSideTranslations(locale, ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer', 'services'])), // Add 'home', 'footer', etc. if needed }, }; }