* Reapply "fix: replace filter implementations on bookings (#19445)" (#19506)
This reverts commit f6af6e34bd.
* force custom date range selector for bookings except for Past tab
* fix e2e test
* add e2e tests
* fix e2e test
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import type { Table } from "@tanstack/react-table";
|
|
import { useCallback } from "react";
|
|
|
|
import { convertFacetedValuesToMap, type FacetedValue } from "@calcom/features/data-table";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import { useEventTypes } from "./useEventTypes";
|
|
|
|
export function useFacetedUniqueValues() {
|
|
const eventTypes = useEventTypes();
|
|
const { data: teams } = trpc.viewer.teams.list.useQuery();
|
|
const { data: members } = trpc.viewer.teams.listSimpleMembers.useQuery();
|
|
|
|
return useCallback(
|
|
(_: Table<any>, columnId: string) => (): Map<FacetedValue, number> => {
|
|
if (columnId === "eventTypeId") {
|
|
return convertFacetedValuesToMap(eventTypes || []);
|
|
} else if (columnId === "teamId") {
|
|
return convertFacetedValuesToMap(
|
|
(teams || []).map((team) => ({
|
|
label: team.name,
|
|
value: team.id,
|
|
}))
|
|
);
|
|
} else if (columnId === "userId") {
|
|
return convertFacetedValuesToMap(
|
|
(members || [])
|
|
.map((member) => ({
|
|
label: member.name,
|
|
value: member.id,
|
|
}))
|
|
.filter((option): option is { label: string; value: number } => Boolean(option.label))
|
|
);
|
|
}
|
|
return new Map<FacetedValue, number>();
|
|
},
|
|
[eventTypes, teams, members]
|
|
);
|
|
}
|