* Copy changes
* Move search bar inline with new button
* Get rid of no more results message
* Change hidden badge to (hidden)
* Remove Cal.ai badge from sidebar
* Add dropdown to create button when there is multiple options
* Fix delete dialog
* Saved filters updates
* More string fixes
* Switch members table to use names
* Fix member spacing
* Fix routing form identifier field
* Fix routing forms stuff
* Only show SMS hint on SMS options
* Make workflow delete button minimal
* Fix padding on workflow steps
* Remove min width on workflow title
* Fix delete workflow PR
* Fix org profile buttons
* Fix org profile screen partially scrolled down
* Improve logos & banner uploads
* Personal profile fixes
* Fix settings general view stuff
* Sentence case consistency
* Fix stuff I broke
* Fix fab
* Fix hidden translation string
* Fix text fields
* Make button small for solo users too
* fix: update E2E tests to match sentence case labels in routing forms
* fix: update tests to match sentence case label changes
- insights.e2e.ts: chart titles (14 strings)
- event-types.e2e.ts: Organizer phone number location
- EditLocationDialog.test.tsx: phone number labels
* fix: address Cubic AI review feedback (confidence 9+)
- Replace hardcoded text-gray-500 with text-muted in TextField.tsx hint section
- Replace text locator with data-testid in E2E test for location select
Co-Authored-By: unknown <>
* fix: update E2E tests for sentence case label changes
- Use data-testid selectors for location options (more reliable than text)
- Update field identifiers in routing-forms tests to match new labels
- Fix Long text selector in manage-booking-questions test
* fix: replace text locator with data-testid in manage-booking-questions E2E test
Replace fragile text="Long text" locator with resilient
page.getByTestId("select-option-textarea") selector per E2E best practices.
Addresses Cubic AI review feedback (confidence 9/10).
Co-Authored-By: unknown <>
* fix: use .last() for multiple location select items
---------
Co-authored-by: Pedro Castro <pedro@cal.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
179 lines
5.5 KiB
TypeScript
179 lines
5.5 KiB
TypeScript
"use client";
|
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
|
|
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import classNames from "@calcom/ui/classNames";
|
|
import { Avatar } from "@calcom/ui/components/avatar";
|
|
import type { ButtonColor } from "@calcom/ui/components/button";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import {
|
|
Dropdown,
|
|
DropdownItem,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuTrigger,
|
|
} from "@calcom/ui/components/dropdown";
|
|
|
|
export interface Option {
|
|
platform?: boolean;
|
|
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, platform?: boolean) => void;
|
|
subtitle?: string;
|
|
buttonText?: string;
|
|
isPending?: boolean;
|
|
disableMobileButton?: boolean;
|
|
"data-testid"?: string;
|
|
color?: ButtonColor;
|
|
className?: string;
|
|
};
|
|
|
|
/**
|
|
* @deprecated use CreateButtonWithTeamsList instead
|
|
*/
|
|
export function CreateButton(props: CreateBtnProps) {
|
|
const { t } = useLocale();
|
|
const router = useRouter();
|
|
const searchParams = useCompatSearchParams();
|
|
const pathname = usePathname();
|
|
|
|
const {
|
|
createDialog,
|
|
options,
|
|
isPending,
|
|
createFunction,
|
|
buttonText,
|
|
disableMobileButton,
|
|
subtitle,
|
|
className,
|
|
...restProps
|
|
} = props;
|
|
const CreateDialog = createDialog ? createDialog() : null;
|
|
|
|
const hasTeams = !!options.find((option) => option.teamId);
|
|
const platform = !!options.find((option) => option.platform);
|
|
const hasMultipleOptions = options.length > 1;
|
|
const isFabVariant = !disableMobileButton;
|
|
// On FAB variant, EndIcon shows as "plus" on mobile, so we remove StartIcon to avoid duplicate
|
|
// On button variant, both icons work correctly
|
|
const startIcon = isFabVariant && hasMultipleOptions ? undefined : "plus";
|
|
const endIcon = hasMultipleOptions ? "chevron-down" : undefined;
|
|
|
|
// inject selection data into url for correct router history
|
|
const openModal = (option: Option) => {
|
|
const _searchParams = new URLSearchParams(searchParams.toString());
|
|
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 && !platform ? (
|
|
<Button
|
|
onClick={() =>
|
|
CreateDialog
|
|
? openModal(options[0])
|
|
: createFunction
|
|
? createFunction(options[0].teamId || undefined)
|
|
: null
|
|
}
|
|
data-testid="create-button"
|
|
StartIcon={startIcon}
|
|
EndIcon={endIcon}
|
|
size="sm"
|
|
loading={isPending}
|
|
variant={disableMobileButton ? "button" : "fab"}
|
|
className={classNames(
|
|
disableMobileButton && "md:min-h-min md:min-w-min",
|
|
className
|
|
)}
|
|
{...restProps}
|
|
>
|
|
{buttonText ? buttonText : t("new")}
|
|
</Button>
|
|
) : (
|
|
<Dropdown>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant={disableMobileButton ? "button" : "fab"}
|
|
StartIcon={startIcon}
|
|
EndIcon={endIcon}
|
|
size="sm"
|
|
data-testid="create-button-dropdown"
|
|
loading={isPending}
|
|
className={classNames(
|
|
disableMobileButton && "md:min-h-min md:min-w-min",
|
|
className
|
|
)}
|
|
{...restProps}
|
|
>
|
|
{buttonText ? buttonText : t("new")}
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
sideOffset={14}
|
|
align="end"
|
|
className="scroll-bar max-h-60 overflow-y-auto"
|
|
>
|
|
<DropdownMenuLabel>
|
|
<div className="w-48 text-left text-xs">{subtitle}</div>
|
|
</DropdownMenuLabel>
|
|
{options.map((option, idx) => (
|
|
<DropdownMenuItem key={option.label}>
|
|
<DropdownItem
|
|
type="button"
|
|
data-testid={`option${option.teamId ? "-team" : ""}-${idx}`}
|
|
CustomStartIcon={
|
|
<Avatar
|
|
alt={option.label || ""}
|
|
imageSrc={option.image}
|
|
size="sm"
|
|
/>
|
|
}
|
|
onClick={() =>
|
|
CreateDialog
|
|
? openModal(option)
|
|
: createFunction
|
|
? createFunction(
|
|
option.teamId || undefined,
|
|
option.platform
|
|
)
|
|
: null
|
|
}
|
|
>
|
|
{" "}
|
|
{/*improve this code */}
|
|
<span>{option.label}</span>
|
|
</DropdownItem>
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</Dropdown>
|
|
)}
|
|
{searchParams?.get("dialog") === "new" && CreateDialog}
|
|
</>
|
|
);
|
|
}
|