Initial commit
Next.js + Express event management app for Hope Family Church.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"use client";
|
||||
|
||||
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
|
||||
export type SiteSettings = {
|
||||
org_name?: string;
|
||||
org_tagline?: string;
|
||||
org_email?: string;
|
||||
org_phone?: string;
|
||||
org_address?: string;
|
||||
accent_color?: string;
|
||||
logo_url?: string;
|
||||
setup_complete?: string;
|
||||
// Legal pages
|
||||
legal_operator_name?: string;
|
||||
legal_io_name?: string;
|
||||
legal_io_email?: string;
|
||||
legal_website_url?: string;
|
||||
legal_effective_date?: string;
|
||||
};
|
||||
|
||||
type SiteSettingsContextValue = {
|
||||
settings: SiteSettings;
|
||||
loading: boolean;
|
||||
reload: () => void;
|
||||
};
|
||||
|
||||
const SiteSettingsContext = createContext<SiteSettingsContextValue>({
|
||||
settings: {},
|
||||
loading: true,
|
||||
reload: () => {},
|
||||
});
|
||||
|
||||
export function SiteSettingsProvider({ children }: { children: React.ReactNode }) {
|
||||
const [settings, setSettings] = useState<SiteSettings>({});
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
const data = await apiFetch<SiteSettings>("/api/settings");
|
||||
setSettings(data || {});
|
||||
} catch {
|
||||
// Non-fatal — use defaults
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => { load(); }, []);
|
||||
|
||||
return (
|
||||
<SiteSettingsContext.Provider value={{ settings, loading, reload: load }}>
|
||||
{children}
|
||||
</SiteSettingsContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useSiteSettings() {
|
||||
return useContext(SiteSettingsContext);
|
||||
}
|
||||
Reference in New Issue
Block a user