HifiPlanet-Website/hifi-src/src/components/PublicLayout.jsx
Maaxxs 5f1d4e1092 Add CMS v1: editable business identity and legal pages
Phase 5 of the dashboard roadmap. Business-facing data that was
previously hard-coded (and, for address/hours, duplicated three
independent ways across Footer.jsx, ContactPage.jsx, and the i18n
strings) is now stored in app_settings and editable under Website
settings: logo (light/dark variants, falling back to the bundled
defaults until set), street/zip/city, and a day-by-day business_hours
editor. Footer.jsx and ContactPage.jsx now share one open/closed and
hours-formatting implementation (new utils/businessHours.js) instead
of three separate hard-coded representations of the same thing.

New legal_pages table (impressum/datenschutz/agb) + PageContentController
replaces the three fully hard-coded React pages with fetched, admin-
editable HTML - built-in defaults matching the original page content
kick in until an admin saves anything, so a fresh install isn't blank.
Reuses the Phase 4 RichTextEditor (extended with a heading toggle and
inline-code toggle, since the legal text needs both) via a new
"Rechtstexte" tab in Settings. Legal content lives only in DB and is
authored exclusively by logged-in admins, so dangerouslySetInnerHTML
here doesn't take untrusted input.

IMAGE_COLUMNS in SettingsController (export/import) is now table =>
array of columns instead of table => one column, since app_settings
has three image columns (hero/logo/logo_dark) - this also retroactively
fixes hero_image_path never having been wired into export/import at
all. app_settings and legal_pages both got TABLE_COLUMNS/IMPORT_SECTIONS
entries so they round-trip through a hoster-migration export like
everything else.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 02:03:59 +02:00

100 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useEffect, useState } from 'react';
import { Outlet, useLocation } from 'react-router-dom';
import Navbar from './Navbar.jsx';
import Footer from './Footer.jsx';
import ScrollProgress from './ScrollProgress.jsx';
import MaintenanceNotice from './MaintenanceNotice.jsx';
import MaintenanceBypassBanner from './MaintenanceBypassBanner.jsx';
import CookieConsentBanner from './CookieConsentBanner.jsx';
import GoogleAnalytics from './GoogleAnalytics.jsx';
import { MaintenanceProvider } from '../context/MaintenanceContext.jsx';
import { SiteSettingsProvider } from '../context/SiteSettingsContext.jsx';
import { LanguageProvider } from '../context/LanguageContext.jsx';
import { useAuth } from '../context/AuthContext.jsx';
import { api } from '../api/client.js';
const FALLBACK_STATUS = {
global: { enabled: false, message: null },
services: { enabled: false, message: null },
vehicles: { enabled: false, message: null },
};
const DEFAULT_BUSINESS_HOURS = {
mon: { open: '09:00', close: '18:00', closed: false },
tue: { open: '09:00', close: '18:00', closed: false },
wed: { open: '09:00', close: '18:00', closed: false },
thu: { open: '09:00', close: '18:00', closed: false },
fri: { open: '09:00', close: '18:00', closed: false },
sat: { open: '10:00', close: '13:00', closed: false },
sun: { open: '', close: '', closed: true },
};
const DEFAULT_SITE_SETTINGS = {
phone: '09373 20 62 390',
whatsapp: null,
contact_email: 'info@hifi-planet-amorbach.de',
address_street: 'Boxbrunner Str. 20a',
address_zip: '63916',
address_city: 'Amorbach',
logo_path: null,
logo_dark_path: null,
business_hours: DEFAULT_BUSINESS_HOURS,
hero_image_path: null,
ga_measurement_id: null,
package_card_theme: 'graphite',
package_card_layout: 'strip',
package_wheel_hint_interval: 8,
};
// Das Impressum (und die anderen rechtlichen Pflichtseiten) müssen laut § 5 DDG
// "leicht erkennbar und unmittelbar erreichbar" bleiben – auch während der
// generellen Wartung darf diese Erreichbarkeit nicht durch die Wartungsseite
// verdeckt werden.
const LEGAL_PATHS = ['/impressum', '/datenschutz', '/agb'];
export default function PublicLayout() {
const [status, setStatus] = useState(null);
const [siteSettings, setSiteSettings] = useState(DEFAULT_SITE_SETTINGS);
const { loading: authLoading, hasPermission } = useAuth();
const location = useLocation();
useEffect(() => {
api.get('/maintenance').then(setStatus).catch(() => setStatus(FALLBACK_STATUS));
api.get('/site-settings').then(setSiteSettings).catch(() => {});
}, []);
if (status === null || authLoading) {
return <div className="min-h-screen bg-white dark:bg-neutral-950" />;
}
const bypass = hasPermission('maintenance.bypass');
const isLegalPage = LEGAL_PATHS.includes(location.pathname);
if (status.global.enabled && !bypass && !isLegalPage) {
return (
<LanguageProvider>
<MaintenanceNotice message={status.global.message} fullScreen />
</LanguageProvider>
);
}
return (
<LanguageProvider>
<MaintenanceProvider value={{ ...status, bypass }}>
<SiteSettingsProvider value={siteSettings}>
<div className="page-texture flex min-h-screen flex-col text-neutral-900 dark:text-neutral-100">
{bypass && status.global.enabled && <MaintenanceBypassBanner />}
<ScrollProgress />
<Navbar />
<main className="flex-1">
<Outlet />
</main>
<Footer />
<CookieConsentBanner />
<GoogleAnalytics />
</div>
</SiteSettingsProvider>
</MaintenanceProvider>
</LanguageProvider>
);
}