diff --git a/apps/web/components/dialog/EditLocationDialog.tsx b/apps/web/components/dialog/EditLocationDialog.tsx index 24f1a4aaca..ba5f16b353 100644 --- a/apps/web/components/dialog/EditLocationDialog.tsx +++ b/apps/web/components/dialog/EditLocationDialog.tsx @@ -173,8 +173,6 @@ export const EditLocationDialog = (props: ISetLocationDialog) => { } ); - console.log(defaultLocation); - const LocationOptions = (() => { if (eventLocationType && eventLocationType.organizerInputType && LocationInput) { if (!eventLocationType.variable) { diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index c0655b43be..bc92e7cf2d 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -352,6 +352,7 @@ "no_status_bookings_yet_description": "You have no {{status}} bookings. {{description}}", "event_between_users": "{{eventName}} between {{host}} and {{attendeeName}}", "bookings": "Bookings", + "booking_not_found": "Booking not found", "bookings_description": "See upcoming and past events booked through your event type links.", "upcoming_bookings": "As soon as someone books a time with you it will show up here.", "recurring_bookings": "As soon as someone books a recurring meeting with you it will show up here.", @@ -504,6 +505,7 @@ "additional_guests": "Add guests", "your_name": "Your name", "your_full_name": "Your full name", + "no_name":"No name", "email_address": "Email address", "enter_valid_email": "Please enter a valid email", "location": "Location", @@ -551,6 +553,9 @@ "members": "Members", "organization_members": "Organization members", "member": "Member", + "number_member_one": "{{count}} member", + "number_member_other": "{{count}} members", + "number_selected": "{{count}} selected", "owner": "Owner", "admin": "Admin", "administrator_user": "Administrator user", @@ -657,6 +662,7 @@ "event_type_updated_successfully": "{{eventTypeTitle}} event type updated successfully", "event_type_deleted_successfully": "Event type deleted successfully", "hours": "Hours", + "people": "People", "your_email": "Your Email", "change_avatar": "Change Avatar", "language": "Language", @@ -1543,6 +1549,7 @@ "apps_settings": "Apps settings", "fill_this_field": "Please fill in this field", "options": "Options", + "no_options_available":"No options available", "enter_option": "Enter Option {{index}}", "add_an_option": "Add an option", "radio": "Radio", diff --git a/packages/features/bookings/BookingMultiFiltersStore.ts b/packages/features/bookings/BookingMultiFiltersStore.ts new file mode 100644 index 0000000000..bfbb9ae646 --- /dev/null +++ b/packages/features/bookings/BookingMultiFiltersStore.ts @@ -0,0 +1,52 @@ +import { create } from "zustand"; + +import type { SVGComponent } from "@calcom/types/SVGComponent"; +import { User, Link } from "@calcom/ui/components/icon"; + +interface addFilterOption { + StartIcon?: SVGComponent; + label: "people" | "event_type" | "date_range" | "location"; +} + +export type BookingMultiFilterStore = { + addFilterOptions: addFilterOption[]; + toggleOption: (option: addFilterOption) => void; + isFilterActive: (label: addFilterOption["label"]) => boolean; +}; + +export const useBookingMultiFilterStore = create((set, get) => ({ + addFilterOptions: [ + { + label: "people", + StartIcon: User, + }, + { + label: "event_type", + StartIcon: Link, + }, + // { + // label: "date_range", + // StartIcon: Calendar, + // }, + // { + // label: "location", + // StartIcon: MapPin, + // }, + ], + isFilterActive: (label: addFilterOption["label"]) => { + return !get().addFilterOptions.some((option) => option.label === label); + }, + setState: (state: BookingMultiFilterStore) => set(state), + toggleOption: (option: addFilterOption) => { + const availableOptions = get().addFilterOptions; + const foundOption = availableOptions.find((activeOption) => activeOption.label === option.label); + + if (foundOption) { + set({ + addFilterOptions: availableOptions.filter((activeOption) => activeOption.label !== foundOption.label), + }); + } else { + set({ addFilterOptions: [...availableOptions, option] }); + } + }, +})); diff --git a/packages/features/bookings/components/EventTypeFilter.tsx b/packages/features/bookings/components/EventTypeFilter.tsx index 7aa377e38d..4449fc5a51 100644 --- a/packages/features/bookings/components/EventTypeFilter.tsx +++ b/packages/features/bookings/components/EventTypeFilter.tsx @@ -51,20 +51,28 @@ export const EventTypeFilter = () => { }); if (!eventTypes.data) return null; + const isEmpty = eventTypes.data.length === 0; - const isNotEmpty = eventTypes.data.length > 0; + const getTextForPopover = () => { + const eventTypeIds = query.eventTypeIds; + if (eventTypeIds) { + return `${t("event_type")}: ${t("number_selected", { count: eventTypeIds.length })}`; + } + return `${t("event_type")}: ${t("all")}`; + }; - return eventTypes.status === "success" && isNotEmpty ? ( - -
+ return ( + +
{groupedEventTypes && + !isEmpty && Object.keys(groupedEventTypes).map((teamName) => ( -
+
{teamName === "user_own_event_types" ? t("individual") : teamName}
{groupedEventTypes[teamName].map((eventType) => ( -
+
{ @@ -80,7 +88,10 @@ export const EventTypeFilter = () => { ))} ))} + {isEmpty && ( +

{t("no_options_available")}

+ )}
- ) : null; + ); }; diff --git a/packages/features/bookings/components/FiltersContainer.tsx b/packages/features/bookings/components/FiltersContainer.tsx index b30604cf38..53ea6fa28e 100644 --- a/packages/features/bookings/components/FiltersContainer.tsx +++ b/packages/features/bookings/components/FiltersContainer.tsx @@ -1,51 +1,135 @@ -import type { ReactNode } from "react"; -import { Fragment } from "react"; +import { useState } from "react"; +import { shallow } from "zustand/shallow"; +import { useFilterQuery } from "@calcom/features/bookings/lib/useFilterQuery"; +import { + TeamsFilter, + FilterCheckboxFieldsContainer, + FilterCheckboxField, +} from "@calcom/features/filters/components/TeamsFilter"; +import { WEBAPP_URL } from "@calcom/lib/constants"; +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { trpc } from "@calcom/trpc/react"; +import { + Dropdown, + DropdownMenuContent, + DropdownMenuItem, + DropdownItem, + DropdownMenuTrigger, + AnimatedPopover, + Avatar, + FilterSearchField, + Tooltip, +} from "@calcom/ui"; +import { Plus } from "@calcom/ui/components/icon"; + +import { useBookingMultiFilterStore } from "../BookingMultiFiltersStore"; import { EventTypeFilter } from "./EventTypeFilter"; -import { PeopleFilter } from "./PeopleFilter"; -import { TeamsMemberFilter } from "./TeamFilter"; -type FilterTypes = "teams" | "people" | "eventType"; +const PeopleFilter = () => { + const { t } = useLocale(); + const { data: query, pushItemToKey, removeItemByKeyAndValue, removeByKey } = useFilterQuery(); + const [searchText, setSearchText] = useState(""); -type Filter = { - name: FilterTypes; - controllingQueryParams?: string[]; // this is what the filter controls - but also we show the filter if any of these query params are present - component: ReactNode; - showByDefault?: boolean; + const members = trpc.viewer.teams.listMembers.useQuery({}); + + const filteredMembers = members?.data + ?.filter((member) => member.accepted) + ?.filter((member) => + searchText.trim() !== "" + ? member?.name?.toLowerCase()?.includes(searchText.toLowerCase()) || + member?.username?.toLowerCase()?.includes(searchText.toLowerCase()) + : true + ); + + const getTextForPopover = () => { + const userIds = query.userIds; + if (userIds) { + return `${t("people")}: ${t("number_selected", { count: userIds.length })}`; + } + return `${t("people")}: ${t("all")}`; + }; + + return ( + + setSearchText(e.target.value)} placeholder={t("search")} /> + + {filteredMembers?.map((member) => ( + { + if (e.target.checked) { + pushItemToKey("userIds", member.id); + } else if (!e.target.checked) { + removeItemByKeyAndValue("userIds", member.id); + } + }} + icon={ + + } + /> + ))} + {filteredMembers?.length === 0 && ( +

{t("no_options_available")}

+ )} +
+
+ ); }; -const filters: Filter[] = [ - { - name: "teams", - component: , - controllingQueryParams: ["teamId"], - showByDefault: true, - }, - { - name: "people", - component: , - controllingQueryParams: ["usersId"], - showByDefault: true, - }, - { - name: "eventType", - component: , - controllingQueryParams: ["eventTypeId"], - showByDefault: true, - }, -]; - export function FiltersContainer() { + const { t } = useLocale(); + + const [addFilterOptions, toggleOption, isFilterActive] = useBookingMultiFilterStore((state) => [ + state.addFilterOptions, + state.toggleOption, + state.isFilterActive, + shallow, + ]); + + const isPeopleFilterActive = isFilterActive("people"); + const isEventTypeFilterActive = isFilterActive("event_type"); + return (
- {filters.map((filter) => { - if (!filter.showByDefault) { - // TODO: check if any of the controllingQueryParams are present in the query params and show the filter if so - // TODO: Also check state to see if the user has toggled the filter - return null; - } - return {filter.component}; - })} + {addFilterOptions.length > 0 && ( + + +
+ + +
{t("add_filter")}
+
+
+
+ + {addFilterOptions?.map((option) => ( + + { + toggleOption(option); + }}> + {t(option.label)} + + + ))} + +
+ )} + + {isPeopleFilterActive && } + {isEventTypeFilterActive && } + +
); } diff --git a/packages/features/bookings/components/PeopleFilter.tsx b/packages/features/bookings/components/PeopleFilter.tsx deleted file mode 100644 index 7691ec78c0..0000000000 --- a/packages/features/bookings/components/PeopleFilter.tsx +++ /dev/null @@ -1,82 +0,0 @@ -import { useState } from "react"; - -import { WEBAPP_URL } from "@calcom/lib/constants"; -import { useLocale } from "@calcom/lib/hooks/useLocale"; -import { trpc } from "@calcom/trpc/react"; -import { AnimatedPopover, Avatar } from "@calcom/ui"; -import { User } from "@calcom/ui/components/icon"; - -import { useFilterQuery } from "../lib/useFilterQuery"; - -export const PeopleFilter = () => { - const { t } = useLocale(); - const { data: query, pushItemToKey, removeItemByKeyAndValue, removeByKey } = useFilterQuery(); - const { data } = trpc.viewer.teams.listMembers.useQuery({}); - const [dropdownTitle, setDropdownTitle] = useState(t("all_users_filter_label")); - - if (!data || !data.length) return null; - - // Get user names from query - const userNames = data?.filter((user) => query.userIds?.includes(user.id)).map((user) => user.name); - - return ( - 0 ? `${userNames.join(", ")}` : dropdownTitle}> -
-
- -
- - - { - setDropdownTitle(t("all_users_filter_label")); - // Always clear userIds on toggle as this is the toggle box for all users. No params means we are currently selecting all users - removeByKey("userIds"); - }} - className="text-primary-600 focus:ring-primary-500 border-default inline-flex h-4 w-4 place-self-center justify-self-end rounded " - /> -
- {data && - data.map((user) => ( -
- - - - { - setDropdownTitle(user.name ?? "NamelessUser"); - if (e.target.checked) { - pushItemToKey("userIds", user.id); - } else if (!e.target.checked) { - removeItemByKeyAndValue("userIds", user.id); - } - }} - className="text-primary-600 focus:ring-primary-500 border-default inline-flex h-4 w-4 place-self-center justify-self-end rounded " - /> -
- ))} -
- ); -}; diff --git a/packages/features/bookings/components/TeamFilter.tsx b/packages/features/bookings/components/TeamFilter.tsx deleted file mode 100644 index b6b4c472ef..0000000000 --- a/packages/features/bookings/components/TeamFilter.tsx +++ /dev/null @@ -1,116 +0,0 @@ -import { useSession } from "next-auth/react"; -import { useState } from "react"; - -import { useLocale } from "@calcom/lib/hooks/useLocale"; -import { trpc } from "@calcom/trpc/react"; -import { AnimatedPopover, Avatar } from "@calcom/ui"; -import { Layers, User } from "@calcom/ui/components/icon"; - -import { useFilterQuery } from "../lib/useFilterQuery"; - -export const TeamsMemberFilter = () => { - const { t } = useLocale(); - const session = useSession(); - const { - data: query, - pushItemToKey, - removeItemByKeyAndValue, - removeByKey, - removeAllQueryParams, - } = useFilterQuery(); - const { data } = trpc.viewer.teams.list.useQuery(); - const [dropdownTitle, setDropdownTitle] = useState(t("all_bookings_filter_label")); - - if (!data || !data.length) return null; - - // get team names from query - const teamNames = data?.filter((team) => query.teamIds?.includes(team.id)).map((team) => team.name); - - return ( - 0 ? `${teamNames.join(", ")}` : dropdownTitle}> -
-
- -
- - - { - setDropdownTitle(t("all_bookings_filter_label")); - removeAllQueryParams(); - }} - className="text-primary-600 focus:ring-primary-500 border-default inline-flex h-4 w-4 place-self-center justify-self-end rounded " - /> -
-
-
- -
- - - { - setDropdownTitle(t("your_bookings_filter_label")); - if (e.target.checked) { - pushItemToKey("userIds", session.data?.user.id || 0); - } else if (!e.target.checked) { - removeItemByKeyAndValue("userIds", session.data?.user.id || 0); - } - }} - className="text-primary-600 focus:ring-primary-500 border-default inline-flex h-4 w-4 place-self-center justify-self-end rounded " - /> -
- {data && - data.map((team) => ( -
- - - - { - setDropdownTitle(team.name); - if (e.target.checked) { - pushItemToKey("teamIds", team.id); - } else if (!e.target.checked) { - removeItemByKeyAndValue("teamIds", team.id); - } - }} - className="text-primary-600 focus:ring-primary-500 border-default inline-flex h-4 w-4 place-self-center justify-self-end rounded " - /> -
- ))} -
- ); -}; diff --git a/packages/features/bookings/layout/BookingLayout.tsx b/packages/features/bookings/layout/BookingLayout.tsx index 218ad8fd03..76d02617c5 100644 --- a/packages/features/bookings/layout/BookingLayout.tsx +++ b/packages/features/bookings/layout/BookingLayout.tsx @@ -37,9 +37,9 @@ export default function BookingLayout({ return (
-
+
-
+
diff --git a/packages/features/filters/components/TeamsFilter.tsx b/packages/features/filters/components/TeamsFilter.tsx index 9d61dba0d1..dda8df3b9c 100644 --- a/packages/features/filters/components/TeamsFilter.tsx +++ b/packages/features/filters/components/TeamsFilter.tsx @@ -2,13 +2,14 @@ import { useSession } from "next-auth/react"; import type { ReactNode, InputHTMLAttributes } from "react"; import { forwardRef } from "react"; +import { classNames } from "@calcom/lib"; import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery"; import { teamMetadataSchema } from "@calcom/prisma/zod-utils"; import { trpc } from "@calcom/trpc/react"; import type { RouterOutputs } from "@calcom/trpc/react"; -import { AnimatedPopover, Avatar, Divider, VerticalDivider } from "@calcom/ui"; +import { AnimatedPopover, Avatar, Divider, Tooltip, VerticalDivider } from "@calcom/ui"; import { Layers, User } from "@calcom/ui/components/icon"; import { filterQuerySchema } from "../lib/getTeamsFiltersFromQuery"; @@ -68,7 +69,7 @@ export const TeamsFilter = ({ onChange={(e) => { removeAllQueryParams(); }} - label={t("all_apps")} + label={t("all")} /> { - return
{children}
; +export const FilterCheckboxFieldsContainer = ({ + children, + className, +}: { + children: ReactNode; + className?: string; +}) => { + return ( +
*:first-child]:mt-1 [&>*:last-child]:mb-1", className)}> + {children} +
+ ); }; type Props = InputHTMLAttributes & { @@ -127,15 +139,17 @@ type Props = InputHTMLAttributes & { export const FilterCheckboxField = forwardRef(({ label, icon, ...rest }, ref) => { return ( -
-