This commit is contained in:
gpt-engineer-app[bot]
2025-12-19 15:17:47 +00:00
parent f57bba6f9c
commit 7fc10126df
11 changed files with 979 additions and 88 deletions

104
src/hooks/useBranding.tsx Normal file
View File

@@ -0,0 +1,104 @@
import { createContext, useContext, useEffect, useState, ReactNode } from 'react';
import { supabase } from '@/integrations/supabase/client';
interface HomepageFeature {
icon: string;
title: string;
description: string;
}
interface BrandingSettings {
brand_name: string;
brand_tagline: string;
brand_logo_url: string;
brand_favicon_url: string;
brand_primary_color: string;
brand_accent_color: string;
brand_email_from_name: string;
homepage_headline: string;
homepage_description: string;
homepage_features: HomepageFeature[];
}
const defaultBranding: BrandingSettings = {
brand_name: 'LearnHub',
brand_tagline: 'Belajar bareng, dari praktisi.',
brand_logo_url: '',
brand_favicon_url: '',
brand_primary_color: '#111827',
brand_accent_color: '#0F766E',
brand_email_from_name: '',
homepage_headline: 'Learn. Grow. Succeed.',
homepage_description: 'Access premium consulting, live webinars, and intensive bootcamps to accelerate your career.',
homepage_features: [
{ icon: 'Users', title: 'Consulting', description: 'One-on-one sessions with industry experts to solve your specific challenges.' },
{ icon: 'Video', title: 'Webinars', description: 'Live and recorded sessions covering the latest trends and techniques.' },
{ icon: 'BookOpen', title: 'Bootcamps', description: 'Intensive programs to master new skills in weeks, not months.' },
],
};
const BrandingContext = createContext<BrandingSettings>(defaultBranding);
export function BrandingProvider({ children }: { children: ReactNode }) {
const [branding, setBranding] = useState<BrandingSettings>(defaultBranding);
useEffect(() => {
fetchBranding();
}, []);
const fetchBranding = async () => {
const { data, error } = await supabase
.from('platform_settings')
.select('*')
.single();
if (data) {
let features = defaultBranding.homepage_features;
// Parse homepage_features if it's a string
if (data.homepage_features) {
try {
features = typeof data.homepage_features === 'string'
? JSON.parse(data.homepage_features)
: data.homepage_features;
} catch (e) {
console.error('Error parsing homepage_features:', e);
}
}
setBranding({
brand_name: data.brand_name || defaultBranding.brand_name,
brand_tagline: data.brand_tagline || defaultBranding.brand_tagline,
brand_logo_url: data.brand_logo_url || '',
brand_favicon_url: data.brand_favicon_url || '',
brand_primary_color: data.brand_primary_color || defaultBranding.brand_primary_color,
brand_accent_color: data.brand_accent_color || defaultBranding.brand_accent_color,
brand_email_from_name: data.brand_email_from_name || '',
homepage_headline: data.homepage_headline || defaultBranding.homepage_headline,
homepage_description: data.homepage_description || defaultBranding.homepage_description,
homepage_features: features,
});
// Update favicon if set
if (data.brand_favicon_url) {
const link = document.querySelector("link[rel~='icon']") as HTMLLinkElement;
if (link) link.href = data.brand_favicon_url;
}
// Update document title
if (data.brand_name) {
document.title = data.brand_name;
}
}
};
return (
<BrandingContext.Provider value={branding}>
{children}
</BrandingContext.Provider>
);
}
export function useBranding() {
return useContext(BrandingContext);
}