Files
calendar/packages/ui/components/list/List.tsx
T
84a2e55125 chore: App router migration - general settings (#16312)
* added lockedSMS to future routes

* add orgMigrations routes to future

* correct metadata

* small fix

* add orgMigrations to future

* Move components to client components

* Remove tRPC element from edit user RSC

* Get username for meta

* Remove suspense query

* Remove orgMigrations from app router

* Type fix

* Revert "Remove suspense query"

This reverts commit eadd814f6e4a5d6856d9218342b7909c22fe62c6.

* Handle suspenseQuery in app router

* User edit page, fetch data server side

* Update yarn.lock

* Export getFixedT

* Set PageWrapper as root layout for settings

* Settings Layout accepts strings for shell heading

* Add OOO to app router settings

* Refactor layout for my-account pages

* Remove instances of pages router from my-account

* Refactor security pages

* Add billing to app router

* Add admin API link to layout

* Add api keys page

* Webhooks WIP

* Refactor SettingsHeader to client component

* Add webhook pages

* Refactor API keys page

* Add admin app page

* Type fix

* fix types

* fix developer/webhooks/[id] param value type error

* remove unnecessary code

* do not pass t prop to CreateNewWebhookButton

* fix type errors in webhook-edit-view

* fix the remaining type errors

* do not use prisma directly in generateMetadata

* remove use client if unnecessary

* Remove unused shell heading from SettingsLayoutAppDir

* improve metadata

* fix billing page

* fix import in settings/teams

* Use next `notFound()`

* fix type check

* fix type check

* remove unused code

* Fix calendar setting page

* Separate settings pages into route groups

* Refactor admin settings pages

* Remove meta instance from billing page route

* Update settings layoutAppDir

* Refactor developer settings pages

* Refactor out of office

* Refactor my account settings

* Refactor admin api page

* Refactor security pages

* Type fix

* fix styling in settings layout

---------

Co-authored-by: Somay Chauhan <somaychauhan98@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: Benny Joo <sldisek783@gmail.com>
2024-09-09 01:15:03 -04:00

148 lines
4.3 KiB
TypeScript

import Link from "next/link";
import { createElement } from "react";
import classNames from "@calcom/lib/classNames";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Badge } from "../badge";
export type ListProps = {
roundContainer?: boolean;
// @TODO: Do we still need this? Coming from old v2 component. Prefer to delete it :)
noBorderTreatment?: boolean;
} & JSX.IntrinsicElements["ul"];
export function List(props: ListProps) {
return (
<ul
data-testid="list"
{...props}
className={classNames(
"mx-0 rounded-sm sm:overflow-hidden ",
// Add rounded top and bottome if roundContainer is true
props.roundContainer && "[&>*:first-child]:rounded-t-md [&>*:last-child]:rounded-b-md ",
!props.noBorderTreatment &&
"border-subtle divide-subtle divide-y rounded-md border border-l border-r ",
props.className
)}>
{props.children}
</ul>
);
}
export type ListItemProps = { expanded?: boolean; rounded?: boolean } & ({
href?: never;
} & JSX.IntrinsicElements["li"]);
export function ListItem(props: ListItemProps) {
const { href, expanded, rounded = true, ...passThroughProps } = props;
const elementType = href ? "a" : "li";
const element = createElement(
elementType,
{
...passThroughProps,
className: classNames(
"items-center bg-default min-w-0 flex-1 flex border-neutral-200 p-4 sm:mx-0 md:border md:p-4 xl:mt-0 border-subtle",
expanded ? "my-2 border" : "border -mb-px last:mb-0",
// Pass rounded false to not round the corners -> Usefull when used in list we can use roundedContainer to create the right design
rounded ? "rounded-md" : "rounded-none",
props.className,
(props.onClick || href) && "hover:bg-muted"
),
"data-testid": "list-item",
},
props.children
);
return href ? (
<Link passHref href={href} legacyBehavior>
{element}
</Link>
) : (
element
);
}
export type ListLinkItemProps = {
href: string;
heading: string;
subHeading: string;
disabled?: boolean;
actions?: JSX.Element;
} & JSX.IntrinsicElements["li"];
export function ListLinkItem(props: ListLinkItemProps) {
const { href, heading = "", children, disabled = false, actions = <div />, className = "" } = props;
const { t } = useLocale();
let subHeading = props.subHeading;
if (!subHeading) {
subHeading = "";
}
return (
<li
data-testid="list-link-item"
className={classNames(
"group flex w-full items-center justify-between p-5 pb-4",
className,
disabled ? "hover:bg-muted" : ""
)}>
<Link
passHref
href={href}
className={classNames(
"text-default flex-grow truncate text-sm",
disabled ? "pointer-events-none cursor-not-allowed opacity-30" : ""
)}>
<div className="flex items-center">
<h1 className="text-sm font-semibold leading-none">{heading}</h1>
{disabled && (
<Badge data-testid="badge" variant="gray" className="ml-2">
{t("readonly")}
</Badge>
)}
</div>
<h2 className="min-h-4 mt-2 text-sm font-normal leading-none text-neutral-600">
{subHeading.substring(0, 100)}
{subHeading.length > 100 && "..."}
</h2>
<div className="mt-2">{children}</div>
</Link>
{actions}
</li>
);
}
export function ListItemTitle<TComponent extends keyof JSX.IntrinsicElements = "span">(
props: JSX.IntrinsicElements[TComponent] & { component?: TComponent }
) {
const { component = "span", ...passThroughProps } = props;
return createElement(
component,
{
...passThroughProps,
className: classNames("text-sm font-medium text-emphasis truncate", props.className),
"data-testid": "list-item-title",
},
props.children
);
}
export function ListItemText<TComponent extends keyof JSX.IntrinsicElements = "span">(
props: JSX.IntrinsicElements[TComponent] & { component?: TComponent }
) {
const { component = "span", ...passThroughProps } = props;
return createElement(
component,
{
...passThroughProps,
className: classNames("text-sm text-subtle truncate prose", props.className),
"data-testid": "list-item-text",
},
props.children
);
}