import { DialogAction, dialogActions } from "./dialog-actions";
-export type DialogState = Record<string, Dialog>;
+export type DialogState = Record<string, Dialog<any>>;
-export interface Dialog {
+export interface Dialog <T> {
open: boolean;
- data?: any;
+ data: T;
}
export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
CLOSE_DIALOG: ({ id }) => ({
...state,
- [id]: state[id] ? { ...state[id], open: false } : { open: false } }),
+ [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} } }),
default: () => state,
});
+export const getDialog = <T>(state: DialogState, id: string) =>
+ state[id] ? state[id] as Dialog<T> : undefined;