Files
acc-server-manager-web/src/lib/context/ServerCreationPopupContext.tsx
Fran Jurmanović b0ee67c2be server creation
2025-09-18 01:34:16 +02:00

62 lines
1.4 KiB
TypeScript

'use client';
import { createContext, useContext, useState, ReactNode } from 'react';
interface ServerCreationPopupState {
serverId: string;
serverName: string;
isOpen: boolean;
}
interface ServerCreationPopupContextType {
popup: ServerCreationPopupState | null;
showPopup: (serverId: string, serverName: string) => void;
hidePopup: () => void;
isPopupOpen: boolean;
}
const ServerCreationPopupContext = createContext<ServerCreationPopupContextType | null>(null);
export function useServerCreationPopup() {
const context = useContext(ServerCreationPopupContext);
if (!context) {
throw new Error('useServerCreationPopup must be used within a ServerCreationPopupProvider');
}
return context;
}
interface ServerCreationPopupProviderProps {
children: ReactNode;
}
export function ServerCreationPopupProvider({ children }: ServerCreationPopupProviderProps) {
const [popup, setPopup] = useState<ServerCreationPopupState | null>(null);
const showPopup = (serverId: string, serverName: string) => {
setPopup({
serverId,
serverName,
isOpen: true
});
};
const hidePopup = () => {
setPopup(null);
};
const isPopupOpen = popup?.isOpen || false;
return (
<ServerCreationPopupContext.Provider
value={{
popup,
showPopup,
hidePopup,
isPopupOpen
}}
>
{children}
</ServerCreationPopupContext.Provider>
);
}