Scheduling infrastructure for absolutely everyone.
Chor/v2 UI tidy - Dialog & Toasts (#6307)
sean-brydon112d50414895
diff --git a/packages/ui/TimezoneChangeDialog.tsx b/packages/features/settings/TimezoneChangeDialog.tsxsimilarity index 96%rename from packages/ui/TimezoneChangeDialog.tsxrename to packages/features/settings/TimezoneChangeDialog.tsxindex 1eb436681b5..d6da7baf9e7 100644--- a/packages/ui/TimezoneChangeDialog.tsx+++ b/packages/features/settings/TimezoneChangeDialog.tsx@@ -4,9 +4,7 @@ import { useEffect, useState } from "react";import dayjs from "@calcom/dayjs";import { useLocale } from "@calcom/lib/hooks/useLocale";import { trpc } from "@calcom/trpc/react";--import { showToast } from ".";-import { Dialog, DialogClose, DialogContent, DialogFooter } from "../ui/v2";+import { Dialog, DialogClose, DialogContent, DialogFooter, showToast } from "@calcom/ui";export default function TimezoneChangeDialog() {const { t } = useLocale();diff --git a/packages/ui/components/apps/AppCard.tsx b/packages/ui/components/apps/AppCard.tsxindex a4e78211552..2285fb04148 100644--- a/packages/ui/components/apps/AppCard.tsx+++ b/packages/ui/components/apps/AppCard.tsx@@ -7,8 +7,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";import { AppFrontendPayload as App } from "@calcom/types/App";import type { CredentialFrontendPayload as Credential } from "@calcom/types/Credential";-import { Button, Icon } from "../..";-import { showToast } from "../../v2/core/notifications";+import { Button, Icon, showToast } from "../..";interface AppCardProps {app: App;diff --git a/packages/ui/v2/core/ConfirmationDialogContent.tsx b/packages/ui/components/dialog/ConfirmationDialogContent.tsxsimilarity index 93%rename from packages/ui/v2/core/ConfirmationDialogContent.tsxrename to packages/ui/components/dialog/ConfirmationDialogContent.tsxindex 1593884072f..68fbe634c51 100644--- a/packages/ui/v2/core/ConfirmationDialogContent.tsx+++ b/packages/ui/components/dialog/ConfirmationDialogContent.tsx@@ -3,7 +3,7 @@ import React, { PropsWithChildren, ReactNode } from "react";import { useLocale } from "@calcom/lib/hooks/useLocale";-import { Icon } from "../../components/icon";+import { Icon } from "../icon";import { DialogClose, DialogContent } from "./Dialog";export type ConfirmationDialogContentProps = {@@ -17,7 +17,7 @@ export type ConfirmationDialogContentProps = {variety?: "danger" | "warning" | "success";};-export default function ConfirmationDialogContent(props: PropsWithChildren<ConfirmationDialogContentProps>) {+export function ConfirmationDialogContent(props: PropsWithChildren<ConfirmationDialogContentProps>) {const { t } = useLocale();const {title,diff --git a/packages/ui/v2/core/Dialog.tsx b/packages/ui/components/dialog/Dialog.tsxsimilarity index 100%rename from packages/ui/v2/core/Dialog.tsxrename to packages/ui/components/dialog/Dialog.tsxdiff --git a/packages/ui/components/dialog/index.ts b/packages/ui/components/dialog/index.tsnew file mode 100644index 00000000000..498f50b4be8--- /dev/null+++ b/packages/ui/components/dialog/index.ts@@ -0,0 +1,4 @@+export { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTrigger } from "./Dialog";+export { ConfirmationDialogContent } from "./ConfirmationDialogContent";+export type { ConfirmationDialogContentProps } from "./ConfirmationDialogContent";+export type { DialogProps } from "./Dialog";diff --git a/packages/ui/components/index.ts b/packages/ui/components/index.tsindex 4ae298f8590..0c144554728 100644--- a/packages/ui/components/index.ts+++ b/packages/ui/components/index.ts@@ -56,3 +56,14 @@ export { List, ListItem, ListItemText, ListItemTitle, ListLinkItem } from "./lisexport type { ListItemProps, ListProps } from "./list";export { HeadSeo } from "./head-seo";export { Skeleton, SkeletonAvatar, SkeletonButton, SkeletonContainer, SkeletonText } from "./skeleton";+export {+ Dialog,+ DialogClose,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTrigger,+ ConfirmationDialogContent,+} from "./dialog";+export type { DialogProps, ConfirmationDialogContentProps } from "./dialog";+export { showToast } from "./toast"; // We don't export the toast components as they are only used in local storybook filediff --git a/packages/ui/components/toast/index.tsx b/packages/ui/components/toast/index.tsxnew file mode 100644index 00000000000..817b1a9e97b--- /dev/null+++ b/packages/ui/components/toast/index.tsx@@ -0,0 +1 @@+export { DefaultToast, ErrorToast, SuccessToast, WarningToast, showToast } from "./showToast";diff --git a/packages/ui/components/toast/showToast.tsx b/packages/ui/components/toast/showToast.tsxnew file mode 100644index 00000000000..7b2b5e8761a--- /dev/null+++ b/packages/ui/components/toast/showToast.tsx@@ -0,0 +1,76 @@+import classNames from "classnames";+import toast from "react-hot-toast";++import { Icon } from "@calcom/ui";++type IToast = {+ message: string;+ toastVisible: boolean;+};++export const SuccessToast = ({ message, toastVisible }: IToast) => (+ <div+ className={classNames(+ "data-testid-toast-success bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md rtl:space-x-reverse",+ toastVisible && "animate-fade-in-up"+ )}>+ <Icon.FiCheck className="h-4 w-4" />+ <p>{message}</p>+ </div>+);++export const ErrorToast = ({ message, toastVisible }: IToast) => (+ <div+ className={classNames(+ "animate-fade-in-up mb-2 flex h-9 items-center space-x-2 rounded-md bg-red-100 p-3 text-sm font-semibold text-red-900 shadow-md rtl:space-x-reverse",+ toastVisible && "animate-fade-in-up"+ )}>+ <Icon.FiInfo className="h-4 w-4" />+ <p>{message}</p>+ </div>+);++export const WarningToast = ({ message, toastVisible }: IToast) => (+ <div+ className={classNames(+ "animate-fade-in-up bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md rtl:space-x-reverse",+ toastVisible && "animate-fade-in-up"+ )}>+ <Icon.FiInfo className="h-4 w-4" />+ <p>{message}</p>+ </div>+);++export const DefaultToast = ({ message, toastVisible }: IToast) => (+ <div+ className={classNames(+ "animate-fade-in-up bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md rtl:space-x-reverse",+ toastVisible && "animate-fade-in-up"+ )}>+ <Icon.FiCheck className="h-4 w-4" />+ <p>{message}</p>+ </div>+);++const TOAST_VISIBLE_DURATION = 6000;++export function showToast(+ message: string,+ variant: "success" | "warning" | "error",+ duration = TOAST_VISIBLE_DURATION+) {+ switch (variant) {+ case "success":+ toast.custom((t) => <SuccessToast message={message} toastVisible={t.visible} />, { duration });+ break;+ case "error":+ toast.custom((t) => <ErrorToast message={message} toastVisible={t.visible} />, { duration });+ break;+ case "warning":+ toast.custom((t) => <WarningToast message={message} toastVisible={t.visible} />, { duration });+ break;+ default:+ toast.custom((t) => <DefaultToast message={message} toastVisible={t.visible} />, { duration });+ break;+ }+}diff --git a/packages/ui/components/toast/toast.stories.mdx b/packages/ui/components/toast/toast.stories.mdxnew file mode 100644index 00000000000..da6edd501dd--- /dev/null+++ b/packages/ui/components/toast/toast.stories.mdx@@ -0,0 +1,33 @@+import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';+import { Examples, Example, Note, Title, VariantsTable, VariantColumn, RowTitles, CustomArgsTable} from '@calcom/storybook/components'+import { Icon } from "@calcom/ui";++import { SuccessToast,ErrorToast,WarningToast,DefaultToast } from './';++<Meta title="UI/Toasts" component={DefaultToast} />++<Title title="Toasts" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>+++## Definition+Toasts are used to show an action has had a impact. If a user submits a form a toast should be shown to notify the user there has been a success++## Structure++<CustomArgsTable of={DefaultToast} />+++<Examples title="Toasts" >+ <Example title="Default">+ <DefaultToast message="Default Toast" toastVisible={true}/>+ </Example>+ <Example title="Success">+ <SuccessToast message="Success Toast" toastVisible={true}/>+ </Example>+ <Example title="Warning">+ <WarningToast message="Warning Toast" toastVisible={true}/>+ </Example>+ <Example title="Error">+ <ErrorToast message="Error Toast" toastVisible={true}/>+ </Example>+</Examples>diff --git a/packages/ui/form/fields.tsx b/packages/ui/form/fields.tsxindex 7830aa1ecac..8e1cb4d0dd8 100644--- a/packages/ui/form/fields.tsx+++ b/packages/ui/form/fields.tsx@@ -6,8 +6,7 @@ import classNames from "@calcom/lib/classNames";import { getErrorFromUnknown } from "@calcom/lib/errors";import { useLocale } from "@calcom/lib/hooks/useLocale";-import { Alert } from "../components/alert";-import { showToast } from "../v2/core/notifications";+import { Alert, showToast } from "../components";type InputProps = Omit<JSX.IntrinsicElements["input"], "name"> & { name: string };diff --git a/packages/ui/index.tsx b/packages/ui/index.tsxindex 51af1629be7..69e9a82445b 100644--- a/packages/ui/index.tsx+++ b/packages/ui/index.tsx@@ -57,6 +57,14 @@ export {AppStoreCategories,Slider,useShouldShowArrows,+ Dialog,+ DialogClose,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTrigger,+ ConfirmationDialogContent,+ showToast,} from "./components";export type {ActionType,@@ -65,6 +73,8 @@ export type {BadgeProps,ButtonBaseProps,ButtonProps,+ DialogProps,+ ConfirmationDialogContentProps,ITimezone,ITimezoneOption,ListItemProps,@@ -77,12 +87,10 @@ export { default as AddressInput } from "./form/AddressInputLazy";export { default as PhoneInput } from "./form/PhoneInputLazy";export { UnstyledSelect } from "./form/Select";export { default as Loader } from "./v2/core/Loader";-export { default as TimezoneChangeDialog } from "./TimezoneChangeDialog";export {HorizontalTabs,SettingsToggle,- showToast,Swatch,Switch,Card,@@ -94,16 +102,6 @@ export type { HorizontalTabItemProps, VerticalTabItemProps } from "./v2";export { default as Shell, ShellMain, MobileNavigationMoreItems, ShellSubHeading } from "./v2/core/Shell";export { default as ColorPicker } from "./v2/core/colorpicker";-export { default as ConfirmationDialogContent } from "./v2/core/ConfirmationDialogContent";-export {- Dialog,- DialogClose,- DialogContent,- DialogFooter,- DialogHeader,- DialogTrigger,-} from "./v2/core/Dialog";-export type { DialogProps } from "./v2/core/Dialog";export {Dropdown,DropdownItem,diff --git a/packages/ui/v2/core/Shell.tsx b/packages/ui/v2/core/Shell.tsxindex 8909da9200b..3ed241f4d96 100644--- a/packages/ui/v2/core/Shell.tsx+++ b/packages/ui/v2/core/Shell.tsx@@ -12,6 +12,7 @@ import LicenseRequired from "@calcom/features/ee/common/components/v2/LicenseReqimport ImpersonatingBanner from "@calcom/features/ee/impersonation/components/ImpersonatingBanner";import HelpMenuItem from "@calcom/features/ee/support/components/HelpMenuItem";import { TeamsUpgradeBanner } from "@calcom/features/ee/teams/components";+import TimezoneChangeDialog from "@calcom/features/settings/TimezoneChangeDialog";import { Tips } from "@calcom/features/tips";import AdminPasswordBanner from "@calcom/features/users/components/AdminPasswordBanner";import CustomBranding from "@calcom/lib/CustomBranding";@@ -32,7 +33,6 @@ import {DropdownMenuSeparator,DropdownMenuTrigger,showToast,- TimezoneChangeDialog,} from "../..";import { Logo, ErrorBoundary } from "../../components";import { Credits } from "../../components/credits";diff --git a/packages/ui/v2/core/index.ts b/packages/ui/v2/core/index.tsindex 12170000c0b..e64580de636 100644--- a/packages/ui/v2/core/index.ts+++ b/packages/ui/v2/core/index.ts@@ -1,8 +1,6 @@export { Card } from "./Card";export type { BaseCardProps } from "./Card";export { default as ColorPicker } from "./colorpicker";-export { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTrigger } from "./Dialog";-export type { DialogProps } from "./Dialog";export {ButtonOrLink,Dropdown,@@ -27,7 +25,6 @@ export type { HorizontalTabItemProps } from "./navigation/tabs/HorizontalTabItemexport { default as HorizontalTabs, HorizontalTabItem } from "./navigation/tabs/HorizontalTabs";export type { VerticalTabItemProps } from "./navigation/tabs/VerticalTabItem";export { default as VerticalTabs, VerticalTabItem } from "./navigation/tabs/VerticalTabs";-export { default as showToast } from "./notifications";export { default as SettingsToggle } from "./SettingsToggle";export { default as Shell } from "./Shell";export { default as Stepper } from "./Stepper";diff --git a/packages/ui/v2/core/notifications.tsx b/packages/ui/v2/core/notifications.tsxdeleted file mode 100644index 8eae80cf0fe..00000000000--- a/packages/ui/v2/core/notifications.tsx+++ /dev/null@@ -1,70 +0,0 @@-import classNames from "classnames";-import toast from "react-hot-toast";--import { Icon } from "@calcom/ui";--export function showToast(message: string, variant: "success" | "warning" | "error") {- switch (variant) {- case "success":- toast.custom(- (t) => (- <div- className={classNames(- "data-testid-toast-success bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md rtl:space-x-reverse",- t.visible && "animate-fade-in-up"- )}>- <Icon.FiCheck className="h-4 w-4" />- <p>{message}</p>- </div>- ),- { duration: 6000 }- );- break;- case "error":- toast.custom(- (t) => (- <div- className={classNames(- "animate-fade-in-up mb-2 flex h-9 items-center space-x-2 rounded-md bg-red-100 p-3 text-sm font-semibold text-red-900 shadow-md rtl:space-x-reverse",- t.visible && "animate-fade-in-up"- )}>- <Icon.FiInfo className="h-4 w-4" />- <p>{message}</p>- </div>- ),- { duration: 6000 }- );- break;- case "warning":- toast.custom(- (t) => (- <div- className={classNames(- "animate-fade-in-up bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md rtl:space-x-reverse",- t.visible && "animate-fade-in-up"- )}>- <Icon.FiInfo className="h-4 w-4" />- <p>{message}</p>- </div>- ),- { duration: 6000 }- );- break;- default:- toast.custom(- (t) => (- <div- className={classNames(- "animate-fade-in-up bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md rtl:space-x-reverse",- t.visible && "animate-fade-in-up"- )}>- <Icon.FiCheck className="h-4 w-4" />- <p>{message}</p>- </div>- ),- { duration: 6000 }- );- break;- }-}-export default showToast;