2025-11-03 09:35:43 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { usePathname } from 'next/navigation';
|
2025-11-04 15:32:50 +01:00
|
|
|
import { useState, useEffect } from 'react';
|
2025-11-03 09:35:43 +01:00
|
|
|
import { Header } from './Header';
|
|
|
|
|
import { Footer } from './Footer';
|
2025-11-04 15:32:50 +01:00
|
|
|
import { UpdateNotification } from './UpdateNotification';
|
|
|
|
|
import * as swRegistration from '../lib/serviceWorkerRegistration';
|
2025-11-03 09:35:43 +01:00
|
|
|
|
|
|
|
|
export function RootLayoutClient({ children }: { children: React.ReactNode }) {
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const isAdminRoute = pathname?.startsWith('/admin');
|
2025-11-03 15:05:11 +01:00
|
|
|
const isCheckoutSuccess = pathname?.startsWith('/checkout/success');
|
2025-11-04 15:32:50 +01:00
|
|
|
const [updateAvailable, setUpdateAvailable] = useState<ServiceWorkerRegistration | null>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Register service worker with update detection
|
|
|
|
|
swRegistration.register({
|
|
|
|
|
onUpdate: (registration) => {
|
|
|
|
|
console.log('New version available!');
|
|
|
|
|
setUpdateAvailable(registration);
|
|
|
|
|
},
|
2025-11-04 15:47:52 +01:00
|
|
|
onSuccess: () => {
|
2025-11-04 15:32:50 +01:00
|
|
|
console.log('Service worker registered successfully');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
2025-11-03 09:35:43 +01:00
|
|
|
|
2025-11-03 15:05:11 +01:00
|
|
|
if (isAdminRoute || isCheckoutSuccess) {
|
|
|
|
|
// Admin routes and checkout success render without header/footer
|
2025-11-04 15:32:50 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{children}
|
|
|
|
|
<UpdateNotification registration={updateAvailable} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2025-11-03 09:35:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Regular routes render with header/footer
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Header />
|
|
|
|
|
<main className="flex-1 max-w-[1600px] w-full mx-auto pb-8 sm:pb-12 px-4 sm:px-6 lg:px-8 overflow-hidden" style={{ paddingTop: '110px' }}>
|
|
|
|
|
{children}
|
|
|
|
|
</main>
|
|
|
|
|
<Footer />
|
2025-11-04 15:32:50 +01:00
|
|
|
<UpdateNotification registration={updateAvailable} />
|
2025-11-03 09:35:43 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|