import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Avatar, Button, Dropdown, DropdownItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@calcom/ui"; import { Plus } from "@calcom/ui/components/icon"; export interface Option { teamId: number | null | undefined; // if undefined, then it's a profile label: string | null; image?: string | null; slug: string | null; } export type CreateBtnProps = { options: Option[]; createDialog?: () => JSX.Element; createFunction?: (teamId?: number) => void; subtitle?: string; buttonText?: string; isLoading?: boolean; disableMobileButton?: boolean; "data-testid"?: string; }; /** * @deprecated use CreateButtonWithTeamsList instead */ export function CreateButton(props: CreateBtnProps) { const { t } = useLocale(); const router = useRouter(); const searchParams = useSearchParams(); const pathname = usePathname(); const bookerUrl = useBookerUrl(); const { createDialog, options, isLoading, createFunction, buttonText, disableMobileButton, subtitle, ...restProps } = props; const CreateDialog = createDialog ? createDialog() : null; const hasTeams = !!options.find((option) => option.teamId); // inject selection data into url for correct router history const openModal = (option: Option) => { const _searchParams = new URLSearchParams(searchParams); function setParamsIfDefined(key: string, value: string | number | boolean | null | undefined) { if (value !== undefined && value !== null) _searchParams.set(key, value.toString()); } setParamsIfDefined("dialog", "new"); setParamsIfDefined("eventPage", option.slug); setParamsIfDefined("teamId", option.teamId); if (!option.teamId) { _searchParams.delete("teamId"); } router.push(`${pathname}?${_searchParams.toString()}`); }; return ( <> {!hasTeams ? ( ) : (
{subtitle}
{options.map((option, idx) => ( ( )} onClick={() => !!CreateDialog ? openModal(option) : createFunction ? createFunction(option.teamId || undefined) : null }> {" "} {/*improve this code */} {option.label} ))}
)} {searchParams.get("dialog") === "new" && CreateDialog} ); }