add branding option
All checks were successful
Build & Push Docker Image / build (push) Successful in 1m10s
All checks were successful
Build & Push Docker Image / build (push) Successful in 1m10s
This commit is contained in:
37
src/contexts/BrandingContext.jsx
Normal file
37
src/contexts/BrandingContext.jsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
||||
import api from '../services/api';
|
||||
|
||||
const BrandingContext = createContext();
|
||||
|
||||
export function BrandingProvider({ children }) {
|
||||
const [branding, setBranding] = useState({
|
||||
appName: 'Redlight',
|
||||
hasLogo: false,
|
||||
logoUrl: null,
|
||||
});
|
||||
|
||||
const fetchBranding = useCallback(async () => {
|
||||
try {
|
||||
const res = await api.get('/branding');
|
||||
setBranding(res.data);
|
||||
} catch {
|
||||
// keep defaults
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchBranding();
|
||||
}, [fetchBranding]);
|
||||
|
||||
return (
|
||||
<BrandingContext.Provider value={{ ...branding, refreshBranding: fetchBranding }}>
|
||||
{children}
|
||||
</BrandingContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useBranding() {
|
||||
const ctx = useContext(BrandingContext);
|
||||
if (!ctx) throw new Error('useBranding must be used within BrandingProvider');
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user