import { Faq } from "../../../services/content/types"; import { DataCacheKey, staleTime } from "../../../global/constants"; import { useQuery } from "@tanstack/react-query"; import React, { useState, useEffect, useCallback } from "react"; import { contentApi } from "../../../apis/contentApi"; import { startLoading, stopLoading, } from "../../../features/loading/loadingSlice"; import { useAppDispatch } from "../../../hooks/useRedux"; import { useTranslation } from "react-i18next"; const HomeFaq = () => { const [openFaqIndex, setOpenFaqIndex] = useState(0); const dispatch = useAppDispatch(); const { t } = useTranslation(); const { data: loadFaqsData = [] } = useQuery({ queryKey: [DataCacheKey.FAQS], queryFn: async (): Promise => { try { dispatch(startLoading({})); const res = await contentApi.LoadFaq({ pageNumber: 0, pageSize: 10, isFeatured: true, }); return res.data.faqs as Faq[]; } catch (error) { console.error(error); return []; // 🔴 bắt buộc } finally { dispatch(stopLoading()); } }, staleTime: staleTime, }); const toggleFaq = (index: number) => { setOpenFaqIndex(openFaqIndex === index ? null : index); }; return ( <>

{t("frequently")}{" "} {t("askedQuestions")}

{t("weAreAlwaysHereToSupportYou")}

{loadFaqsData.map((faq, index) => (
{/* show html */}
{/*

{faq.answer}

*/}
))}
); }; export default HomeFaq;