53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
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 }),
|
|
}));
|