.
This commit is contained in:
49
app/stores/modal-store.ts
Normal file
49
app/stores/modal-store.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { create } from "zustand";
|
||||
import type { ServerId } from "~/lib/api/types";
|
||||
|
||||
export enum ModalType {
|
||||
CREATE_SERVER = "CREATE_SERVER",
|
||||
CREATE_SERVER_CHANNEL = "CREATE_CHANNEL",
|
||||
CREATE_SERVER_INVITE = "CREATE_SERVER_INVITE",
|
||||
DELETE_SERVER_CONFIRM = "DELETE_SERVER_CONFIRM",
|
||||
UPDATE_PROFILE = "UPDATE_PROFILE",
|
||||
}
|
||||
|
||||
export type CreateServerInviteModalData = {
|
||||
type: ModalType.CREATE_SERVER_INVITE;
|
||||
data: {
|
||||
serverId: ServerId;
|
||||
};
|
||||
};
|
||||
|
||||
export type DeleteServerConfirmModalData = {
|
||||
type: ModalType.CREATE_SERVER_CHANNEL;
|
||||
data: {
|
||||
serverId: ServerId;
|
||||
}
|
||||
};
|
||||
|
||||
export type CreateServerChannelModalData = {
|
||||
type: ModalType.CREATE_SERVER_CHANNEL;
|
||||
data: {
|
||||
serverId: ServerId;
|
||||
}
|
||||
};
|
||||
|
||||
export type ModalData = CreateServerChannelModalData | CreateServerInviteModalData | DeleteServerConfirmModalData;
|
||||
|
||||
interface ModalState {
|
||||
type: ModalType | null;
|
||||
data?: ModalData['data'];
|
||||
isOpen: boolean;
|
||||
onOpen: (type: ModalType, data?: ModalData['data']) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const useModalStore = create<ModalState>()((set) => ({
|
||||
type: null,
|
||||
data: undefined,
|
||||
isOpen: false,
|
||||
onOpen: (type, data) => set({ type, data, isOpen: true }),
|
||||
onClose: () => set({ type: null, isOpen: false }),
|
||||
}));
|
||||
Reference in New Issue
Block a user