Files
calendar/packages/features/shell/navigation/Navigation.tsx
T
d6546c3107 feat: upgrade tailwind v4 (#24598)
* chore: refactor config files to prevent migration tool errors

* refactor: upgrade with the tailwind migration tool

* chore: restore pre-commit command + mc

* refactor(wip): update dependencies and migrate to Tailwind CSS v4 (mainly web)

* chore: resolve Tailwind v4 migration conflicts from merging main

* chore: remove unused Tailwind packages from config and update dependencies for v4 migration

* chore: uncomment Tailwind CSS utility classes in globals.css

* fix: resolve token conflicts between calcom and coss ui

* fix: textarea scrollbar

* Fix CUI-16

* fix: added @tailwindcss/forms plugin and cleaned up CSS classes in various components to remove unnecessary dark mode styles

* fix: selects and inputs of different sizes

* fix: remove unnecessary leading-20 class from modal titles in various components

* fix: update Checkbox component styles to remove unnecessary border on checked state

* fix: clean up styles in RequiresConfirmationController, Checkbox, and Radio components to enhance consistency

* fix: update button and filter component styles to remove unnecessary rounded classes for consistency

* fix: calendar

* fix: update KBarSearch

* fix: refine styles in Empty and Checkbox components for improved consistency

* Fix focus state email input

* fix: update button hover and active states to use 'not-disabled' instead of 'enabled'

* fix: line-height issues

* fix: update class name for muted background in BookingListItem component

* fix: sidebar spacing

* chore: update class names to use new Tailwind CSS color utilities

* fix embed

* chore: upgrade Tailwind CSS to version 4.1.16 and update related dependencies

* Map css variables and add a playground test for heavy css customization

* suggestion for coss-ui

* refactor: update CSS variable usage and clean up styles

- Replace instances of `--cal-brand-color` with `--cal-brand` in embed-related HTML files.
- Remove the now-unnecessary `addAppCssVars` function from the embed core.
- Import theme tokens in the embed core styles for better consistency.
- Clean up whitespace and formatting in CSS files for improved readability.
- Add a comment in `tokens.css` regarding its usage in both embed and webapp contexts.

* Handle within tokens.css instead of fixing coss-ui

* Remove initial, not needed. Also, remove tailwind.config.js as tailwidn scans the html automaically

* fix: examples app breaking

* fix: modal not resizing correctly

* feat: upgrade atoms to tailwind v4

* fix: atoms build breaking

* fix: atoms build breaking

* chore: upgrate examples/base to tailwind 4

* chore: update globals.css

* fix: add missing scheduler css variables

* fix: PlatformAdditionalCalendarSelector

* chore: update global styles

* chore: update tailwindcss and postcss dependencies to stable versions

* chore: remove unneeded class

* fix: dialog and toast animation

* fix: replace flex-shrink-0 with shrink-0 for consistent styling in various components

* fix: dialog modal for Apple connect

* add margin in SaveFilterSegmentButton

* Fix radix button nested states

* add cursor pointer to buttons but keep dsabled state

* Fix commandK selectors and adds cursor pointer

* Fix teams filter

* fix - round checkboxes

* fix filter checkbox

* fix select indicator's margin

* command group font size

* style: fix badge and tooltip radius

* chore: remove unneeded files

* Delete PR_REVIEW_MANAGED_EVENT_REASSIGNMENT.md

* remove ui-playground leftover

* fix: add missing react phone input styles in atoms

* Delete managed-event-reassignment-flow-and-architecture.mermaid

* fix: inter font not loading

* Add theme to skeleton container so that it can support dark mode

* fix: create custom stack-y-* utilities post tw4 upgrade

* fix: typo

* fix: atoms stack class + remove unused css file

* fix default radius valiue

* fix space-y in embed

* fix skeleton background

* Hardcode radius values to match production

* fix border in embed

* add missing externalThemeClass

* feat: create a custom stack-y-* utility

* fix: add stack utility to atom global css

* fix: Skeleton loader class modalbox

* Add stack-y utility in embed

* fix: add missing stack utilities in atoms globals.css

* update yarn.lock

* add popover portla

* update

---------

Co-authored-by: Sean Brydon <sean@cal.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Ryukemeister <sahalrajiv6900@gmail.com>
Co-authored-by: cal.com <morgan@cal.com>
Co-authored-by: Eunjae Lee <hey@eunjae.dev>
Co-authored-by: Anik Dhabal Babu <adhabal2002@gmail.com>
2025-11-25 17:32:28 -03:00

299 lines
8.6 KiB
TypeScript

import { useSession } from "next-auth/react";
import { useMemo } from "react";
import { useIsEmbed } from "@calcom/embed-core/embed-iframe";
import UnconfirmedBookingBadge from "@calcom/features/bookings/UnconfirmedBookingBadge";
import {
useOrgBranding,
type OrganizationBranding,
} from "@calcom/features/ee/organizations/context/provider";
import { KBarTrigger } from "@calcom/features/kbar/Kbar";
import classNames from "@calcom/ui/classNames";
import { TeamInviteBadge } from "../TeamInviteBadge";
import type { NavigationItemType } from "./NavigationItem";
import { NavigationItem, MobileNavigationItem, MobileNavigationMoreItem } from "./NavigationItem";
export const MORE_SEPARATOR_NAME = "more";
const preserveBookingsQueryParams = ({
prevPathname,
nextPathname,
}: {
prevPathname: string | null;
nextPathname: string;
}) => Boolean(prevPathname?.startsWith("/bookings/")) && nextPathname.startsWith("/bookings/");
const getNavigationItems = (orgBranding: OrganizationBranding): NavigationItemType[] => [
{
name: "event_types_page_title",
href: "/event-types",
icon: "link",
},
{
name: "bookings",
href: "/bookings/upcoming",
icon: "calendar",
badge: <UnconfirmedBookingBadge />,
isCurrent: ({ pathname }) => pathname?.startsWith("/bookings") ?? false,
child: [
{
name: "upcoming",
href: "/bookings/upcoming",
preserveQueryParams: preserveBookingsQueryParams,
isCurrent: ({ pathname }) => pathname === "/bookings/upcoming",
},
{
name: "unconfirmed",
href: "/bookings/unconfirmed",
preserveQueryParams: preserveBookingsQueryParams,
isCurrent: ({ pathname }) => pathname === "/bookings/unconfirmed",
},
{
name: "recurring",
href: "/bookings/recurring",
preserveQueryParams: preserveBookingsQueryParams,
isCurrent: ({ pathname }) => pathname === "/bookings/recurring",
},
{
name: "past",
href: "/bookings/past",
preserveQueryParams: preserveBookingsQueryParams,
isCurrent: ({ pathname }) => pathname === "/bookings/past",
},
{
name: "cancelled",
href: "/bookings/cancelled",
preserveQueryParams: preserveBookingsQueryParams,
isCurrent: ({ pathname }) => pathname === "/bookings/cancelled",
},
],
},
{
name: "availability",
href: "/availability",
icon: "clock",
},
...(orgBranding
? [
{
name: "members",
href: `/settings/organizations/${orgBranding.slug}/members`,
icon: "building",
moreOnMobile: true,
} satisfies NavigationItemType,
]
: []),
{
name: "teams",
href: "/teams",
icon: "users",
badge: <TeamInviteBadge />,
moreOnMobile: true,
},
{
name: "apps",
href: "/apps",
icon: "grid-3x3",
moreOnMobile: true,
isCurrent: ({ pathname: path, item }) => {
// During Server rendering path is /v2/apps but on client it becomes /apps(weird..)
return (path?.startsWith(item.href) ?? false) && !(path?.includes("routing-forms/") ?? false);
},
child: [
{
name: "app_store",
href: "/apps",
isCurrent: ({ pathname: path, item }) => {
// During Server rendering path is /v2/apps but on client it becomes /apps(weird..)
return (
(path?.startsWith(item.href) ?? false) &&
!(path?.includes("routing-forms/") ?? false) &&
!(path?.includes("/installed") ?? false)
);
},
},
{
name: "installed_apps",
href: "/apps/installed/calendar",
isCurrent: ({ pathname: path }) =>
(path?.startsWith("/apps/installed/") ?? false) ||
(path?.startsWith("/v2/apps/installed/") ?? false),
},
],
},
{
name: MORE_SEPARATOR_NAME,
href: "/more",
icon: "ellipsis",
},
{
name: "routing",
href: "/routing",
icon: "split",
isCurrent: ({ pathname }) => pathname?.startsWith("/routing") ?? false,
moreOnMobile: true,
},
{
name: "workflows",
href: "/workflows",
icon: "zap",
moreOnMobile: true,
},
{
name: "insights",
href: "/insights",
icon: "chart-bar",
isCurrent: ({ pathname: path, item }) => path?.startsWith(item.href) ?? false,
moreOnMobile: true,
child: [
{
name: "bookings",
href: "/insights",
isCurrent: ({ pathname: path }) => path === "/insights",
},
{
name: "routing",
href: "/insights/routing",
isCurrent: ({ pathname: path }) => path?.startsWith("/insights/routing") ?? false,
},
{
name: "router_position",
href: "/insights/router-position",
isCurrent: ({ pathname: path }) => path?.startsWith("/insights/router-position") ?? false,
},
{
name: "call_history",
href: "/insights/call-history",
// icon: "phone",
isCurrent: ({ pathname: path }) => path?.startsWith("/insights/call-history") ?? false,
},
],
},
];
const platformNavigationItems: NavigationItemType[] = [
{
name: "Dashboard",
href: "/settings/platform/",
icon: "layout-dashboard",
},
{
name: "Documentation",
href: "https://docs.cal.com/docs/platform",
icon: "chart-bar",
target: "_blank",
},
{
name: "API reference",
href: "https://api.cal.com/v2/docs#/",
icon: "terminal",
target: "_blank",
},
{
name: "Atoms",
href: "https://docs.cal.com/docs/platform#atoms",
icon: "atom",
target: "_blank",
},
{
name: MORE_SEPARATOR_NAME,
href: "https://docs.cal.com/docs/platform/faq",
icon: "ellipsis",
target: "_blank",
},
{
name: "Billing",
href: "/settings/platform/billing",
icon: "credit-card",
moreOnMobile: true,
},
{
name: "Members",
href: "/settings/platform/members",
icon: "users",
moreOnMobile: true,
},
{
name: "Managed Users",
href: "/settings/platform/managed-users",
icon: "users",
moreOnMobile: true,
},
];
const useNavigationItems = (isPlatformNavigation = false) => {
const orgBranding = useOrgBranding();
return useMemo(() => {
const items = !isPlatformNavigation ? getNavigationItems(orgBranding) : platformNavigationItems;
const desktopNavigationItems = items.filter((item) => item.name !== MORE_SEPARATOR_NAME);
const mobileNavigationBottomItems = items.filter(
(item) => (!item.moreOnMobile && !item.onlyDesktop) || item.name === MORE_SEPARATOR_NAME
);
const mobileNavigationMoreItems = items.filter(
(item) => item.moreOnMobile && !item.onlyDesktop && item.name !== MORE_SEPARATOR_NAME
);
return { desktopNavigationItems, mobileNavigationBottomItems, mobileNavigationMoreItems };
}, [isPlatformNavigation, orgBranding]);
};
export const Navigation = ({ isPlatformNavigation = false }: { isPlatformNavigation?: boolean }) => {
const { desktopNavigationItems } = useNavigationItems(isPlatformNavigation);
return (
<nav className="mt-2 flex-1 md:px-2 lg:mt-4 lg:px-0">
{desktopNavigationItems.map((item) => (
<NavigationItem key={item.name} item={item} />
))}
<div className="text-subtle mt-0.5 lg:hidden">
<KBarTrigger />
</div>
</nav>
);
};
export function MobileNavigationContainer({
isPlatformNavigation = false,
}: {
isPlatformNavigation?: boolean;
}) {
const { status } = useSession();
if (status !== "authenticated") return null;
return <MobileNavigation isPlatformNavigation={isPlatformNavigation} />;
}
const MobileNavigation = ({ isPlatformNavigation = false }: { isPlatformNavigation?: boolean }) => {
const isEmbed = useIsEmbed();
const { mobileNavigationBottomItems } = useNavigationItems(isPlatformNavigation);
return (
<>
<nav
className={classNames(
"pwa:pb-[max(0.25rem,env(safe-area-inset-bottom))] pwa:-mx-2 bg-cal-muted/40 border-subtle fixed bottom-0 left-0 z-30 flex w-full border-t px-1 shadow backdrop-blur-md md:hidden",
isEmbed && "hidden"
)}>
{mobileNavigationBottomItems.map((item) => (
<MobileNavigationItem key={item.name} item={item} />
))}
</nav>
{/* add padding to content for mobile navigation*/}
<div className="block pt-12 md:hidden" />
</>
);
};
export const MobileNavigationMoreItems = () => {
const { mobileNavigationMoreItems } = useNavigationItems();
return (
<ul className="border-subtle mt-2 rounded-md border">
{mobileNavigationMoreItems.map((item) => (
<MobileNavigationMoreItem key={item.name} item={item} />
))}
</ul>
);
};