2023-03-23 22:10:01 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
|
|
|
import type { Dayjs } from "@calcom/dayjs";
|
|
|
|
|
2023-06-29 17:03:44 +00:00
|
|
|
interface IFilter {
|
|
|
|
dateRange: [Dayjs, Dayjs, null | string];
|
|
|
|
selectedTimeView?: "year" | "week" | "month";
|
|
|
|
selectedFilter?: Array<"user" | "event-type"> | null;
|
|
|
|
selectedTeamId?: number | null;
|
|
|
|
selectedTeamName?: string | null;
|
|
|
|
selectedUserId?: number | null;
|
|
|
|
selectedMemberUserId?: number | null;
|
|
|
|
selectedEventTypeId?: number | null;
|
|
|
|
isAll?: boolean;
|
|
|
|
initialConfig?: {
|
|
|
|
teamId?: number | null;
|
|
|
|
userId?: number | null;
|
2023-09-18 23:36:07 +00:00
|
|
|
isAll?: boolean | null;
|
2023-03-23 22:10:01 +00:00
|
|
|
};
|
2023-06-29 17:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type FilterContextType = {
|
|
|
|
filter: IFilter;
|
2023-04-04 11:58:19 +00:00
|
|
|
clearFilters: () => void;
|
2023-06-29 17:03:44 +00:00
|
|
|
setConfigFilters: (config: Partial<IFilter>) => void;
|
2023-03-23 22:10:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const FilterContext = React.createContext<FilterContextType | null>(null);
|
|
|
|
|
|
|
|
export function useFilterContext() {
|
|
|
|
const context = React.useContext(FilterContext);
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error("useFilterContext must be used within a FilterProvider");
|
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function FilterProvider<F extends FilterContextType>(props: { value: F; children: React.ReactNode }) {
|
|
|
|
return React.createElement(FilterContext.Provider, { value: props.value }, props.children);
|
|
|
|
}
|