Files
calendar/apps/web/components/booking/actions/BookingActionsStoreProvider.tsx
T
Eunjae LeeandGitHub 86353191d2 feat: add booking actions into BookingDetailsSheet (#24912)
* move booking actions into a subfolder

* fix logic to render booking actions dropdown

* skip dropdown portal when rendered from detail sheet

* fix type error
2025-11-11 16:14:48 +00:00

40 lines
1.2 KiB
TypeScript

"use client";
import { createContext, useContext, useRef, type ReactNode } from "react";
import { useStore } from "zustand";
import type { StoreApi } from "zustand";
import { createBookingActionsStore, type BookingActionsStore } from "./store";
export const BookingActionsStoreContext = createContext<StoreApi<BookingActionsStore> | null>(null);
export interface BookingActionsStoreProviderProps {
children: ReactNode;
}
export const BookingActionsStoreProvider = ({ children }: BookingActionsStoreProviderProps) => {
const storeRef = useRef<StoreApi<BookingActionsStore>>();
if (!storeRef.current) {
storeRef.current = createBookingActionsStore();
}
return (
<BookingActionsStoreContext.Provider value={storeRef.current}>
{children}
</BookingActionsStoreContext.Provider>
);
};
export const useBookingActionsStoreContext = <T,>(
selector: (store: BookingActionsStore) => T,
equalityFn?: (a: T, b: T) => boolean
): T => {
const bookingActionsStoreContext = useContext(BookingActionsStoreContext);
if (!bookingActionsStoreContext) {
throw new Error("useBookingActionsStoreContext must be used within BookingActionsStoreProvider");
}
return useStore(bookingActionsStoreContext, selector, equalityFn);
};