Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

876 B
Raw Blame
import { useDisclosure } from "@mantine/hooks";
import {
  type JSX,
  type PropsWithChildren,
  createContext,
  useContext,
} from "react";

interface QuestionAlertModalContext {
  isOpen: boolean;
  toggle: () => void;
  close: () => void;
}

const DEFAULT_CONTEXT_VALUE: QuestionAlertModalContext = {
  isOpen: false,
  toggle: () => {},
  close: () => {},
};

const questionAlertModalContext = createContext<QuestionAlertModalContext>(
  DEFAULT_CONTEXT_VALUE,
);

export function QuestionAlertModalProvider({
  children,
}: PropsWithChildren): JSX.Element {
  const [isOpen, { close, toggle }] = useDisclosure(false);
  return (
    <questionAlertModalContext.Provider value={{ isOpen, toggle, close }}>
      {children}
    </questionAlertModalContext.Provider>
  );
}

export function useQuestionAlertModalContext() {
  return useContext(questionAlertModalContext);
}