feat: hide all demo badges when demo mode is disabled
All checks were successful
Staging Build / build (push) Successful in 2m36s
All checks were successful
Staging Build / build (push) Successful in 2m36s
This commit is contained in:
34
shop/components/DemoWrapper.tsx
Normal file
34
shop/components/DemoWrapper.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
interface DemoWrapperProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function DemoWrapper({ children }: DemoWrapperProps) {
|
||||
const [showDemo, setShowDemo] = useState<boolean>(true);
|
||||
const [isMounted, setIsMounted] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
const checkDemo = () => {
|
||||
const disabled = localStorage.getItem('demo_banner_disabled') === 'true';
|
||||
setShowDemo(!disabled);
|
||||
};
|
||||
|
||||
checkDemo();
|
||||
window.addEventListener('storage_demo_changed', checkDemo);
|
||||
return () => window.removeEventListener('storage_demo_changed', checkDemo);
|
||||
}, []);
|
||||
|
||||
if (!isMounted) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (!showDemo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user