Files
auto-trade/features/layout/stores/use-global-alert-store.ts

44 lines
1015 B
TypeScript

import { ReactNode } from "react";
import { create } from "zustand";
export type AlertType = "success" | "warning" | "error" | "info";
export interface AlertState {
isOpen: boolean;
type: AlertType;
title: ReactNode;
message: ReactNode;
confirmLabel?: string;
cancelLabel?: string;
onConfirm?: () => void;
onCancel?: () => void;
// 단일 버튼 모드 여부 (Confirm 모달이 아닌 단순 Alert)
isSingleButton?: boolean;
}
interface AlertActions {
openAlert: (params: Omit<AlertState, "isOpen">) => void;
closeAlert: () => void;
}
const initialState: AlertState = {
isOpen: false,
type: "info",
title: "",
message: "",
confirmLabel: "확인",
cancelLabel: "취소",
isSingleButton: true,
};
export const useGlobalAlertStore = create<AlertState & AlertActions>((set) => ({
...initialState,
openAlert: (params) =>
set({
...initialState, // 초기화 후 설정
...params,
isOpen: true,
}),
closeAlert: () => set({ isOpen: false }),
}));