[공통컴포넌트] alert 제작
This commit is contained in:
43
features/layout/stores/use-global-alert-store.ts
Normal file
43
features/layout/stores/use-global-alert-store.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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 }),
|
||||
}));
|
||||
Reference in New Issue
Block a user