* refactor: migrate UnconfirmedBookingBadge from features to apps/web Move UnconfirmedBookingBadge.tsx from packages/features/bookings/ to apps/web/modules/bookings/components/ as part of the architectural refactor to remove trpc client imports from the features layer. Also removes unused preserveBookingsQueryParams function from Navigation.tsx. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor: move shell navigation and badges to apps/web Move shell navigation components and trpc-using badges from packages/features to apps/web/modules to fix circular dependency: - Move navigation folder to apps/web/modules/shell/navigation/ - Move TeamInviteBadge.tsx to apps/web/modules/shell/ - Create Shell wrapper in apps/web that provides MobileNavigationContainer - Update all Shell imports in apps/web to use the new wrapper - Remove MobileNavigationContainer default from features Shell.tsx - Fix pre-existing lint warnings in touched files This establishes the pattern for migrating React components that use trpc hooks from the features layer to the web app layer, ensuring proper dependency direction: apps/web imports from packages/features, never the reverse. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: move SideBar.tsx to apps/web to fix build error SideBar.tsx was importing Navigation from the moved navigation folder, causing a build error. Moving SideBar.tsx to apps/web and updating the features Shell to not have a default SidebarContainer fixes this. The web Shell wrapper now provides both the default SidebarContainer and MobileNavigationContainer, maintaining the injection pattern. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * revert * revert * revert * wip * wip * wip * wip * wip * wip * not used anywhere * wip * wip * wip * wip * fix * fix * wip * wip * wip * wip * wip * fix * fix * fix * fix * migrate * migrate admin-adpi * wip * feat: migrate organization settings components from packages/features to apps/web/modules - Migrate profile.tsx, appearance.tsx, general.tsx, privacy.tsx, guest-notifications.tsx, delegationCredential.tsx, other-team-members-view.tsx, other-team-profile-view.tsx - Migrate attributes directory (AttributesForm.tsx, DeleteAttributeModal.tsx, ListSkeleton.tsx, attributes-create-view.tsx, attributes-edit-view.tsx, attributes-list-view.tsx) - Migrate admin directory (AdminOrgEditPage.tsx, AdminOrgPage.tsx, WorkspacePlatformPage.tsx) - Update all page imports to use new paths from ~/settings/organizations/ - Update relative imports in migrated files to use @calcom/features paths - Fix lint warnings in migrated files Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update test import path after migration Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: remove unnecessary test-setup import (already in vitest config) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * wip * refactor: delete original files after migration to apps/web/modules Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix * wip * refactor more * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * mv * update import paths * wip * wip * fix * fix * fix * fix * fix * fix * fix * mv * mv * mv * fix * wip * wip * fix * fix * fix * fix: make test mocks resilient to vi.resetAllMocks() Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: fix AttributeForm test failures Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * fix * refactor: move ee files to apps/web/modules/ee/ folder - Move teams, workflows, and organizations folders to apps/web/modules/ee/ - Add LICENSE file to apps/web/modules/ee/ - Update all import paths from ~/teams/ to ~/ee/teams/ - Update all import paths from ~/settings/organizations/ to ~/ee/organizations/ - Remove duplicate MemberInvitationModal copy.tsx file Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: move useHasPaidPlan and dependent files to apps/web/modules - Move useHasPaidPlan.ts from packages/features/billing/hooks to apps/web/modules/billing/hooks - Move intercom files from packages/features/ee/support to apps/web/modules/ee/support - Move ContactMenuItem.tsx and dependencies (freshchat, helpscout, zendesk) to apps/web/modules/ee/support - Move ViewRecordingsDialog.tsx and RecordingListSkeleton to apps/web/modules/ee/video - Move CalVideoSettings.tsx to apps/web/modules/eventtypes/components/locations - Move CreateOrEditOutOfOfficeModal.tsx to apps/web/modules/settings/outOfOffice - Refactor UpgradeTeamsBadge to accept props and create wrapper in apps/web/modules/billing - Update all callers to use new file locations - Add eslint-disable comments for pre-existing lint warnings This fixes the tRPC server build failure caused by circular dependency where the server build was traversing into packages/features and pulling in React hooks that depend on @calcom/trpc/react types. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: correct UpgradeTeamsBadge import path to use package export Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix * fix * fix * fix * fix: pass plan state through SelectProps to UpgradeTeamsBadge - Add upgradeTeamsBadgeProps field to ExtendedOption type in Select component - Update OptionComponent to spread upgradeTeamsBadgeProps to UpgradeTeamsBadge - Update getOptions.ts to accept PlanState object and include upgradeTeamsBadgeProps - Update WorkflowStepContainer.tsx to pass planState to getWorkflowTriggerOptions/getWorkflowTemplateOptions - Update WorkflowDetailsPage.tsx to pass upgradeTeamsBadgeProps in transformed action options - Update AddActionDialog.tsx interface and mapping to include upgradeTeamsBadgeProps - Add eslint-disable comments for pre-existing React Hook dependency warnings This fixes the UpgradeTeamsBadge refactoring issue where the badge was always showing 'upgrade' text instead of the correct text based on plan state (trial_mode, inactive_team_plan, etc.) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update import paths to use /ee/ folder for workflows and organizations Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update workflow component imports to use /ee/ folder Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing types.ts for LocationInput.tsx Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: extract BookingRedirectForm type to shared location Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * wip * wip * fix: update BookingRedirectForm import to use local types file Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * wip * fix * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
334 lines
13 KiB
TypeScript
334 lines
13 KiB
TypeScript
import Link from "next/link";
|
|
import { usePathname } from "next/navigation";
|
|
import posthog from "posthog-js";
|
|
import React, { Fragment, useState, useEffect } from "react";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
|
|
import { sessionStorage } from "@calcom/lib/webstorage";
|
|
import classNames from "@calcom/ui/classNames";
|
|
import { Badge } from "@calcom/ui/components/badge";
|
|
import { Icon } from "@calcom/ui/components/icon";
|
|
import type { IconName } from "@calcom/ui/components/icon";
|
|
import { SkeletonText } from "@calcom/ui/components/skeleton";
|
|
import { Tooltip } from "@calcom/ui/components/tooltip";
|
|
|
|
import { useShouldDisplayNavigationItem } from "./useShouldDisplayNavigationItem";
|
|
|
|
const usePersistedExpansionState = (itemName: string) => {
|
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const stored = sessionStorage.getItem(`nav-expansion-${itemName}`);
|
|
if (stored !== null) {
|
|
setIsExpanded(JSON.parse(stored));
|
|
}
|
|
}, [itemName]);
|
|
|
|
const setPersistedExpansion = (expanded: boolean) => {
|
|
setIsExpanded(expanded);
|
|
sessionStorage.setItem(`nav-expansion-${itemName}`, JSON.stringify(expanded));
|
|
};
|
|
|
|
return [isExpanded, setPersistedExpansion] as const;
|
|
};
|
|
|
|
const trackNavigationClick = (itemName: string, parentItemName?: string) => {
|
|
posthog.capture("navigation_item_clicked", {
|
|
item_name: itemName,
|
|
parent_name: parentItemName,
|
|
});
|
|
};
|
|
|
|
export type NavigationItemType = {
|
|
name: string;
|
|
href: string;
|
|
isLoading?: boolean;
|
|
onClick?: React.MouseEventHandler<HTMLAnchorElement | HTMLButtonElement>;
|
|
target?: HTMLAnchorElement["target"];
|
|
badge?: React.ReactNode;
|
|
icon?: IconName;
|
|
child?: NavigationItemType[];
|
|
pro?: true;
|
|
onlyMobile?: boolean;
|
|
onlyDesktop?: boolean;
|
|
moreOnMobile?: boolean;
|
|
isCurrent?: ({
|
|
item,
|
|
isChild,
|
|
pathname,
|
|
}: {
|
|
item: Pick<NavigationItemType, "href">;
|
|
isChild?: boolean;
|
|
pathname: string | null;
|
|
}) => boolean;
|
|
};
|
|
|
|
const defaultIsCurrent: NavigationItemType["isCurrent"] = ({ isChild, item, pathname }) => {
|
|
return isChild ? item.href === pathname : item.href ? pathname?.startsWith(item.href) ?? false : false;
|
|
};
|
|
|
|
export const NavigationItem: React.FC<{
|
|
index?: number;
|
|
item: NavigationItemType;
|
|
isChild?: boolean;
|
|
}> = (props) => {
|
|
const { item, isChild } = props;
|
|
const { t, isLocaleReady } = useLocale();
|
|
const pathname = usePathname();
|
|
const isCurrent: NavigationItemType["isCurrent"] = item.isCurrent || defaultIsCurrent;
|
|
const current = isCurrent({ isChild: !!isChild, item, pathname });
|
|
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
|
const [isExpanded, setIsExpanded] = usePersistedExpansionState(item.name);
|
|
|
|
const isTablet = useMediaQuery("(max-width: 1024px)");
|
|
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
|
|
|
|
if (!shouldDisplayNavigationItem) return null;
|
|
|
|
const hasChildren = item.child && item.child.length > 0;
|
|
const hasActiveChild =
|
|
hasChildren && item.child?.some((child) => isCurrent({ isChild: true, item: child, pathname }));
|
|
const shouldShowChildren = isExpanded || hasActiveChild || isCurrent({ pathname, isChild, item });
|
|
const shouldShowChevron = hasChildren && !hasActiveChild;
|
|
const isParentNavigationItem = hasChildren && !isChild;
|
|
|
|
return (
|
|
<Fragment>
|
|
{isParentNavigationItem ? (
|
|
<Tooltip
|
|
side="right"
|
|
open={isTooltipOpen}
|
|
content={
|
|
hasChildren ? (
|
|
<div className="stack-y-1 pointer-events-auto flex flex-col p-1">
|
|
<span className="text-subtle px-2 text-xs font-semibold uppercase tracking-wide">
|
|
{t(item.name)}
|
|
</span>
|
|
<div className="flex flex-col gap-1">
|
|
{item.child?.map((childItem) => {
|
|
const childIsCurrent =
|
|
typeof childItem.isCurrent === "function"
|
|
? childItem.isCurrent({ isChild: true, item: childItem, pathname })
|
|
: defaultIsCurrent({ isChild: true, item: childItem, pathname });
|
|
return (
|
|
<Link
|
|
key={childItem.name}
|
|
href={childItem.href}
|
|
aria-current={childIsCurrent ? "page" : undefined}
|
|
onClick={() => {
|
|
setIsTooltipOpen(false);
|
|
trackNavigationClick(childItem.name, item.name);
|
|
}}
|
|
className={classNames(
|
|
"group relative block rounded-md px-3 py-1 text-sm font-medium",
|
|
childIsCurrent
|
|
? "bg-emphasis text-white"
|
|
: "hover:bg-emphasis text-mute hover:text-emphasis"
|
|
)}>
|
|
{t(childItem.name)}
|
|
</Link>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
t(item.name)
|
|
)
|
|
}
|
|
className="lg:hidden">
|
|
<button
|
|
data-test-id={item.name}
|
|
aria-label={t(item.name)}
|
|
aria-expanded={isExpanded}
|
|
aria-current={current ? "page" : undefined}
|
|
onClick={() => {
|
|
setIsExpanded(!isExpanded);
|
|
if (isTablet && hasChildren) {
|
|
setIsTooltipOpen(!isTooltipOpen);
|
|
}
|
|
}}
|
|
className={classNames(
|
|
"todesktop:py-[7px] text-default group flex w-full items-center rounded-md px-2 py-1.5 text-sm font-medium transition",
|
|
"aria-[aria-current='page']:bg-transparent!",
|
|
"[&[aria-current='page']]:text-emphasis mt-0.5 text-sm",
|
|
isLocaleReady
|
|
? "hover:bg-subtle todesktop:[&[aria-current='page']]:bg-emphasis todesktop:hover:bg-transparent hover:text-emphasis"
|
|
: ""
|
|
)}>
|
|
{item.icon && (
|
|
<Icon
|
|
name={item.isLoading ? "rotate-cw" : item.icon}
|
|
className={classNames(
|
|
"todesktop:!text-blue-500 mr-2 h-4 w-4 shrink-0 rtl:ml-2 md:ltr:mx-auto lg:ltr:mr-2",
|
|
item.isLoading && "animate-spin"
|
|
)}
|
|
aria-hidden="true"
|
|
/>
|
|
)}
|
|
{isLocaleReady ? (
|
|
<span
|
|
className="hidden w-full justify-between truncate text-ellipsis lg:flex"
|
|
data-testid={`${item.name}-test`}>
|
|
{t(item.name)}
|
|
{item.badge && item.badge}
|
|
</span>
|
|
) : (
|
|
<SkeletonText className="h-[20px] w-full" />
|
|
)}
|
|
{shouldShowChevron && (
|
|
<Icon name={isExpanded ? "chevron-up" : "chevron-down"} className="ml-auto h-4 w-4" />
|
|
)}
|
|
</button>
|
|
</Tooltip>
|
|
) : (
|
|
<Tooltip side="right" content={t(item.name)} className="lg:hidden">
|
|
<Link
|
|
data-test-id={item.name}
|
|
onClick={() => trackNavigationClick(item.name)}
|
|
href={item.href}
|
|
aria-label={t(item.name)}
|
|
target={item.target}
|
|
className={classNames(
|
|
"todesktop:py-[7px] text-default group flex items-center rounded-md px-2 py-1.5 text-sm font-medium transition",
|
|
item.child
|
|
? `aria-[aria-current='page']:bg-transparent!`
|
|
: `[&[aria-current='page']]:bg-emphasis`,
|
|
isChild
|
|
? `[&[aria-current='page']]:text-emphasis [&[aria-current='page']]:bg-emphasis hidden h-8 pl-16 lg:flex lg:pl-11 ${
|
|
props.index === 0 ? "mt-0" : "mt-1 hover:mt-1 [&[aria-current='page']]:mt-1"
|
|
}`
|
|
: "[&[aria-current='page']]:text-emphasis mt-0.5 text-sm",
|
|
isLocaleReady
|
|
? "hover:bg-subtle todesktop:[&[aria-current='page']]:bg-emphasis todesktop:hover:bg-transparent hover:text-emphasis"
|
|
: ""
|
|
)}
|
|
aria-current={current ? "page" : undefined}>
|
|
{item.icon && (
|
|
<Icon
|
|
name={item.isLoading ? "rotate-cw" : item.icon}
|
|
className={classNames(
|
|
"todesktop:!text-blue-500 mr-2 h-4 w-4 shrink-0 aria-[aria-current='page']:text-inherit rtl:ml-2 md:ltr:mx-auto lg:ltr:mr-2",
|
|
item.isLoading && "animate-spin"
|
|
)}
|
|
aria-hidden="true"
|
|
aria-current={current ? "page" : undefined}
|
|
/>
|
|
)}
|
|
{isLocaleReady ? (
|
|
<span
|
|
className="hidden w-full justify-between truncate text-ellipsis lg:flex"
|
|
data-testid={`${item.name}-test`}>
|
|
{t(item.name)}
|
|
{item.badge && item.badge}
|
|
</span>
|
|
) : (
|
|
<SkeletonText className="h-[20px] w-full" />
|
|
)}
|
|
{item.name === "workflows" && (
|
|
<Badge startIcon="sparkles" variant="purple">
|
|
Cal.ai
|
|
</Badge>
|
|
)}
|
|
</Link>
|
|
</Tooltip>
|
|
)}
|
|
{item.child &&
|
|
shouldShowChildren &&
|
|
item.child.map((item, index) => <NavigationItem index={index} key={item.name} item={item} isChild />)}
|
|
</Fragment>
|
|
);
|
|
};
|
|
|
|
export const MobileNavigationItem: React.FC<{
|
|
item: NavigationItemType;
|
|
isChild?: boolean;
|
|
}> = (props) => {
|
|
const { item, isChild } = props;
|
|
const pathname = usePathname();
|
|
const { t, isLocaleReady } = useLocale();
|
|
const isCurrent: NavigationItemType["isCurrent"] = item.isCurrent || defaultIsCurrent;
|
|
const current = isCurrent({ isChild: !!isChild, item, pathname });
|
|
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
|
|
|
if (!shouldDisplayNavigationItem) return null;
|
|
return (
|
|
<Link
|
|
key={item.name}
|
|
href={item.href}
|
|
target={item.target}
|
|
className="[&[aria-current='page']]:text-emphasis hover:text-default text-muted bg-transparent! relative my-2 min-w-0 flex-1 overflow-hidden rounded-md p-1 text-center text-xs font-medium focus:z-10 sm:text-sm"
|
|
aria-current={current ? "page" : undefined}>
|
|
{item.badge && <div className="absolute right-1 top-1">{item.badge}</div>}
|
|
{item.icon && (
|
|
<Icon
|
|
name={item.icon}
|
|
className="[&[aria-current='page']]:text-emphasis mx-auto mb-1 block h-5 w-5 shrink-0 text-center text-inherit"
|
|
aria-hidden="true"
|
|
aria-current={current ? "page" : undefined}
|
|
/>
|
|
)}
|
|
{isLocaleReady ? <span className="block truncate">{t(item.name)}</span> : <SkeletonText />}
|
|
</Link>
|
|
);
|
|
};
|
|
|
|
export const MobileNavigationMoreItem: React.FC<{
|
|
item: NavigationItemType;
|
|
isChild?: boolean;
|
|
}> = (props) => {
|
|
const { item } = props;
|
|
const { t, isLocaleReady } = useLocale();
|
|
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
|
const [isExpanded, setIsExpanded] = usePersistedExpansionState(item.name);
|
|
|
|
if (!shouldDisplayNavigationItem) return null;
|
|
|
|
const hasChildren = item.child && item.child.length > 0;
|
|
|
|
return (
|
|
<li className="border-subtle border-b last:border-b-0" key={item.name}>
|
|
{hasChildren ? (
|
|
<>
|
|
<button
|
|
onClick={() => setIsExpanded(!isExpanded)}
|
|
className="hover:bg-subtle flex w-full items-center justify-between p-5 text-left transition">
|
|
<span className="text-default flex items-center font-semibold">
|
|
{item.icon && (
|
|
<Icon name={item.icon} className="h-5 w-5 shrink-0 ltr:mr-3 rtl:ml-3" aria-hidden="true" />
|
|
)}
|
|
{isLocaleReady ? t(item.name) : <SkeletonText />}
|
|
</span>
|
|
<Icon name={isExpanded ? "chevron-up" : "chevron-down"} className="text-subtle h-5 w-5" />
|
|
</button>
|
|
{isExpanded && item.child && (
|
|
<ul className="bg-subtle">
|
|
{item.child.map((childItem) => (
|
|
<li key={childItem.name} className="border-subtle border-t">
|
|
<Link
|
|
href={childItem.href}
|
|
className="hover:bg-cal-muted flex items-center p-4 pl-12 transition">
|
|
<span className="text-default font-medium">
|
|
{isLocaleReady ? t(childItem.name) : <SkeletonText />}
|
|
</span>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</>
|
|
) : (
|
|
<Link href={item.href} className="hover:bg-subtle flex items-center justify-between p-5 transition">
|
|
<span className="text-default flex items-center font-semibold ">
|
|
{item.icon && (
|
|
<Icon name={item.icon} className="h-5 w-5 shrink-0 ltr:mr-3 rtl:ml-3" aria-hidden="true" />
|
|
)}
|
|
{isLocaleReady ? t(item.name) : <SkeletonText />}
|
|
</span>
|
|
<Icon name="arrow-right" className="text-subtle h-5 w-5" />
|
|
</Link>
|
|
)}
|
|
</li>
|
|
);
|
|
};
|