diff --git a/src/app/dashboard/cms/page.tsx b/src/app/dashboard/cms/page.tsx index b1f4633..a8d2430 100644 --- a/src/app/dashboard/cms/page.tsx +++ b/src/app/dashboard/cms/page.tsx @@ -24,6 +24,9 @@ import { AboutTeamContent, AboutTeamMember, AboutCtaContent, + FaqContent, + FaqCategoryItem, + FaqItem, User, } from '@/services'; @@ -53,6 +56,10 @@ const ABOUT_SECTIONS: SectionMeta[] = [ { pageSlug: 'about', sectionKey: 'cta', label: 'Call to Action', description: 'Bottom CTA section' }, ]; +const FAQ_SECTIONS: SectionMeta[] = [ + { pageSlug: 'faq', sectionKey: 'faqContent', label: 'FAQ Content', description: 'Categories, questions and answers' }, +]; + // --------------------------------------------------------------------------- // Default content factories // --------------------------------------------------------------------------- @@ -83,6 +90,11 @@ function defaultContentFor(pageSlug: string, sectionKey: string): unknown { case 'cta': return { title: '', description: '', buttonText: '' } as AboutCtaContent; } } + if (pageSlug === 'faq') { + switch (sectionKey) { + case 'faqContent': return { pageTitle: '', categories: [], faqs: [], supportTitle: '', supportDescription: '' } as FaqContent; + } + } switch (sectionKey) { case 'hero': return defaultHero(); case 'features': return defaultFeatures(); @@ -120,9 +132,10 @@ const textareaCls = inputCls; export default function CmsPage() { const router = useRouter(); - const [activePage, setActivePage] = useState<'landing' | 'about'>('landing'); + const [activePage, setActivePage] = useState<'landing' | 'about' | 'faq'>('landing'); const [records, setRecords] = useState([]); const [aboutRecords, setAboutRecords] = useState([]); + const [faqRecords, setFaqRecords] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(''); const [notification, setNotification] = useState<{ type: 'success' | 'error'; message: string } | null>(null); @@ -148,12 +161,14 @@ export default function CmsPage() { setIsLoading(true); setError(''); try { - const [landingData, aboutData] = await Promise.all([ + const [landingData, aboutData, faqData] = await Promise.all([ cmsService.getByPage('landing'), cmsService.getByPage('about'), + cmsService.getByPage('faq'), ]); setRecords(landingData); setAboutRecords(aboutData); + setFaqRecords(faqData); } catch (err) { const msg = getErrorMessage(err); setError(msg); @@ -230,7 +245,7 @@ export default function CmsPage() { // Helpers function recordFor(pageSlug: string, sectionKey: string): CmsContentRecord | undefined { - const source = pageSlug === 'about' ? aboutRecords : records; + const source = pageSlug === 'about' ? aboutRecords : pageSlug === 'faq' ? faqRecords : records; return source.find((r) => r.sectionKey === sectionKey); } @@ -825,6 +840,123 @@ export default function CmsPage() { ); } + function renderFaqForm() { + const data = editContent as FaqContent; + const update = (patch: Partial) => setEditContent({ ...data, ...patch }); + + function addCategory() { + const newCat: FaqCategoryItem = { id: '', label: '' }; + update({ categories: [...data.categories, newCat] }); + } + function updateCategory(index: number, patch: Partial) { + const categories = [...data.categories]; + categories[index] = { ...categories[index], ...patch }; + update({ categories }); + } + function removeCategory(index: number) { + update({ categories: data.categories.filter((_, i) => i !== index) }); + } + + function addFaq() { + const newFaq: FaqItem = { id: Date.now(), icon: '', question: '', answer: '', category: '' }; + update({ faqs: [...data.faqs, newFaq] }); + } + function updateFaq(index: number, patch: Partial) { + const faqs = [...data.faqs]; + faqs[index] = { ...faqs[index], ...patch }; + update({ faqs }); + } + function removeFaq(index: number) { + update({ faqs: data.faqs.filter((_, i) => i !== index) }); + } + + return ( +
+ {/* Page Title */} +
+ + update({ pageTitle: e.target.value })} placeholder="e.g. Frequently Asked Questions ?" /> +
+ + {/* Support Title */} +
+ + update({ supportTitle: e.target.value })} placeholder="e.g. Still Need Help ?" /> +
+ + {/* Support Description */} +
+ +