refactor: remove hardcoded default content from components and update dashboard to conditionally render sections after CMS data loading

This commit is contained in:
pradeepkumar
2026-03-30 12:07:20 +05:30
parent 75994c09bd
commit daa0e3ff67
3 changed files with 53 additions and 83 deletions

View File

@@ -10,27 +10,34 @@ import type { HeroContent, FeaturesContent, TopProfessionalsContent, Testimonial
export default function UserDashboard() {
const [cmsData, setCmsData] = useState<Record<string, unknown>>({});
const [cmsLoaded, setCmsLoaded] = useState(false);
useEffect(() => {
const fetchCms = async () => {
const sections = await cmsService.getPageContent('landing');
const data: Record<string, unknown> = {};
for (const s of sections) {
const content = s.content as Record<string, unknown>;
// Resolve S3 keys in image fields
if (s.sectionKey === 'features' && Array.isArray(content.features)) {
for (const feat of content.features as { iconPath?: string }[]) {
if (feat.iconPath) feat.iconPath = await resolveImageUrl(feat.iconPath);
try {
const sections = await cmsService.getPageContent('landing');
const data: Record<string, unknown> = {};
for (const s of sections) {
const content = s.content as Record<string, unknown>;
// Resolve S3 keys in image fields
if (s.sectionKey === 'features' && Array.isArray(content.features)) {
for (const feat of content.features as { iconPath?: string }[]) {
if (feat.iconPath) feat.iconPath = await resolveImageUrl(feat.iconPath);
}
}
}
if (s.sectionKey === 'testimonials' && Array.isArray(content.stats)) {
for (const stat of content.stats as { iconPath?: string }[]) {
if (stat.iconPath) stat.iconPath = await resolveImageUrl(stat.iconPath);
if (s.sectionKey === 'testimonials' && Array.isArray(content.stats)) {
for (const stat of content.stats as { iconPath?: string }[]) {
if (stat.iconPath) stat.iconPath = await resolveImageUrl(stat.iconPath);
}
}
data[s.sectionKey] = content;
}
data[s.sectionKey] = content;
setCmsData(data);
} catch {
// Use default content on error
} finally {
setCmsLoaded(true);
}
setCmsData(data);
};
fetchCms();
}, []);
@@ -38,7 +45,7 @@ export default function UserDashboard() {
return (
<div>
<HeroSection content={cmsData.hero as HeroContent | undefined} />
<FeaturesSection content={cmsData.features as FeaturesContent | undefined} />
{cmsLoaded && <FeaturesSection content={cmsData.features as FeaturesContent | undefined} />}
<TopProfessionals content={cmsData.topProfessionals as TopProfessionalsContent | undefined} />
<TestimonialsSection content={cmsData.testimonials as TestimonialsContent | undefined} />
</div>