Dialog Api improvements (#5714)
This commit is contained in:
1 parent
26d675e162
commit
7ebea57602
33 files changed
+218
-312
No files matched your search
@@ -1,86 +0,0 @@
|
||||
/**
|
||||
* @deprecated file
|
||||
* All new changes should be made to the V2 file in
|
||||
* `/packages/ui/v2/core/ConfirmationDialogContent.tsx`
|
||||
*/
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import React, { PropsWithChildren, ReactNode } from "react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Button, DialogClose, DialogContent, Icon } from ".";
|
||||
|
||||
export type ConfirmationDialogContentProps = {
|
||||
confirmBtn?: ReactNode;
|
||||
confirmBtnText?: string;
|
||||
cancelBtnText?: string;
|
||||
isLoading?: boolean;
|
||||
loadingText?: string;
|
||||
onConfirm?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||
title: string;
|
||||
variety?: "danger" | "warning" | "success";
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated file
|
||||
* All new changes should be made to the V2 file in
|
||||
* `/packages/ui/v2/core/ConfirmationDialogContent.tsx`
|
||||
*/
|
||||
export default function ConfirmationDialogContent(props: PropsWithChildren<ConfirmationDialogContentProps>) {
|
||||
const { t } = useLocale();
|
||||
const {
|
||||
title,
|
||||
variety,
|
||||
confirmBtn = null,
|
||||
confirmBtnText = t("confirm"),
|
||||
cancelBtnText = t("cancel"),
|
||||
loadingText = t("loading"),
|
||||
isLoading = false,
|
||||
onConfirm,
|
||||
children,
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<div className="flex">
|
||||
{variety && (
|
||||
<div className="mt-0.5 ltr:mr-3">
|
||||
{variety === "danger" && (
|
||||
<div className="mx-auto rounded-full bg-red-100 p-2 text-center">
|
||||
<Icon.FiAlertCircle className="h-5 w-5 text-red-600" />
|
||||
</div>
|
||||
)}
|
||||
{variety === "warning" && (
|
||||
<div className="mx-auto rounded-full bg-orange-100 p-2 text-center">
|
||||
<Icon.FiAlertCircle className="h-5 w-5 text-orange-600" />
|
||||
</div>
|
||||
)}
|
||||
{variety === "success" && (
|
||||
<div className="mx-auto rounded-full bg-green-100 p-2 text-center">
|
||||
<Icon.FiCheck className="h-5 w-5 text-green-600" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<DialogPrimitive.Title className="font-cal text-xl text-gray-900">{title}</DialogPrimitive.Title>
|
||||
<DialogPrimitive.Description className="text-sm text-neutral-500">
|
||||
{children}
|
||||
</DialogPrimitive.Description>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 flex flex-row-reverse gap-x-2 sm:mt-8">
|
||||
<DialogClose disabled={isLoading} onClick={onConfirm} asChild>
|
||||
{confirmBtn || (
|
||||
<Button data-testid="confirm-button" color="primary" loading={isLoading}>
|
||||
{isLoading ? loadingText : confirmBtnText}
|
||||
</Button>
|
||||
)}
|
||||
</DialogClose>
|
||||
<DialogClose disabled={isLoading} asChild>
|
||||
<Button color="secondary">{cancelBtnText}</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
import { Dialog, DialogContent, showToast } from ".";
|
||||
import { DialogClose, DialogFooter } from "./Dialog";
|
||||
|
||||
export default function TimezoneChangeDialog() {
|
||||
const { t } = useLocale();
|
||||
@@ -58,20 +59,23 @@ export default function TimezoneChangeDialog() {
|
||||
|
||||
if (data?.user.impersonatedByUID) return null;
|
||||
|
||||
const ONE_DAY = 60 * 60 * 24; // 1 day in seconds (60 seconds * 60 minutes * 24 hours)
|
||||
const THREE_MONTHS = ONE_DAY * 90; // 90 days in seconds (90 days * 1 day in seconds)
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent
|
||||
title={t("update_timezone_question")}
|
||||
description={t("update_timezone_description", { formattedCurrentTz })}
|
||||
type="creation"
|
||||
actionText={t("update_timezone")}
|
||||
actionOnClick={() => updateTimezone()}
|
||||
closeText={t("dont_update")}
|
||||
onInteractOutside={() => onCancel(86400, false) /* 1 day expire */}
|
||||
actionOnClose={() => onCancel(7776000, true) /* 3 months expire */}>
|
||||
{/* todo: save this in db and auto-update when timezone changes (be able to disable??? if yes, /settings)
|
||||
onInteractOutside={() => onCancel(ONE_DAY, false) /* 1 day expire */}>
|
||||
{/* todo: save this in db and auto-update when timezone changes (be able to disable??? if yes, /settings)
|
||||
<Checkbox description="Always update timezone" />
|
||||
*/}
|
||||
<DialogFooter>
|
||||
<DialogClose onClick={() => onCancel(THREE_MONTHS, true)}>{t("dont_update")}</DialogClose>
|
||||
<DialogClose onClick={() => updateTimezone()}>{t("update_timezone")}</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function ConfirmationDialogContent(props: PropsWithChildren<Confi
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<DialogContent type="creation" useOwnActionButtons={true}>
|
||||
<DialogContent type="creation">
|
||||
<div className="flex">
|
||||
{variety && (
|
||||
<div className="mt-0.5 ltr:mr-3">
|
||||
@@ -62,16 +62,14 @@ export default function ConfirmationDialogContent(props: PropsWithChildren<Confi
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 flex flex-row-reverse gap-x-2 sm:mt-8">
|
||||
<DialogClose disabled={isLoading} onClick={onConfirm} asChild>
|
||||
{confirmBtn || (
|
||||
<Button color="primary" loading={isLoading}>
|
||||
{isLoading ? loadingText : confirmBtnText}
|
||||
</Button>
|
||||
)}
|
||||
</DialogClose>
|
||||
<DialogClose disabled={isLoading} asChild>
|
||||
<Button color="secondary">{cancelBtnText}</Button>
|
||||
</DialogClose>
|
||||
{confirmBtn ? (
|
||||
confirmBtn
|
||||
) : (
|
||||
<DialogClose color="primary" loading={isLoading} onClick={(e) => onConfirm && onConfirm(e)}>
|
||||
{isLoading ? loadingText : confirmBtnText}
|
||||
</DialogClose>
|
||||
)}
|
||||
<DialogClose disabled={isLoading}>{cancelBtnText}</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { useRouter } from "next/router";
|
||||
import React, { ReactNode, useState } from "react";
|
||||
import React, { forwardRef, HTMLProps, ReactNode, useState } from "react";
|
||||
import { Icon } from "react-feather";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Button } from "../../components/button";
|
||||
import { Button, ButtonProps } from "../../components/button";
|
||||
|
||||
export type DialogProps = React.ComponentProps<typeof DialogPrimitive["Root"]> & {
|
||||
name?: string;
|
||||
@@ -70,20 +70,11 @@ type DialogContentProps = React.ComponentProps<typeof DialogPrimitive["Content"]
|
||||
description?: string | JSX.Element | undefined;
|
||||
closeText?: string;
|
||||
actionDisabled?: boolean;
|
||||
actionText?: string;
|
||||
Icon?: Icon;
|
||||
// If this is set it allows you to overide the action buttons. Usefull if you need to use formcontext
|
||||
useOwnActionButtons?: boolean;
|
||||
actionOnClick?: (e: Event | React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||
actionOnClose?: () => void;
|
||||
actionProps?: React.ComponentProps<typeof Button>;
|
||||
};
|
||||
|
||||
export const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps>(
|
||||
(
|
||||
{ children, title, Icon, actionProps, useOwnActionButtons, type = "creation", ...props },
|
||||
forwardedRef
|
||||
) => {
|
||||
({ children, title, Icon, type = "creation", ...props }, forwardedRef) => {
|
||||
const { t } = useLocale();
|
||||
|
||||
return (
|
||||
@@ -125,31 +116,6 @@ export const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!useOwnActionButtons && (
|
||||
<DialogFooter>
|
||||
<div className="mt-2 flex space-x-2">
|
||||
<DialogClose asChild>
|
||||
{/* This will require the i18n string passed in */}
|
||||
<Button color="minimal" onClick={props.actionOnClose}>
|
||||
{props.closeText ?? t("close")}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
{props.actionOnClick ? (
|
||||
<Button
|
||||
color="primary"
|
||||
disabled={props.actionDisabled}
|
||||
onClick={props.actionOnClick}
|
||||
{...actionProps}>
|
||||
{props.actionText}
|
||||
</Button>
|
||||
) : (
|
||||
<Button color="primary" type="submit" disabled={props.actionDisabled} {...actionProps}>
|
||||
{props.actionText}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</DialogFooter>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPrimitive.Portal>
|
||||
);
|
||||
@@ -175,7 +141,7 @@ export function DialogHeader(props: DialogHeaderProps) {
|
||||
export function DialogFooter(props: { children: ReactNode }) {
|
||||
return (
|
||||
<div>
|
||||
<div className="mt-5 flex justify-end space-x-2 rtl:space-x-reverse">{props.children}</div>
|
||||
<div className="mt-7 flex justify-end space-x-2 rtl:space-x-reverse ">{props.children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -183,4 +149,24 @@ export function DialogFooter(props: { children: ReactNode }) {
|
||||
DialogContent.displayName = "DialogContent";
|
||||
|
||||
export const DialogTrigger = DialogPrimitive.Trigger;
|
||||
export const DialogClose = DialogPrimitive.Close;
|
||||
// export const DialogClose = DialogPrimitive.Close;
|
||||
|
||||
export function DialogClose(
|
||||
props: {
|
||||
dialogCloseProps?: React.ComponentProps<typeof DialogPrimitive["Close"]>;
|
||||
children?: ReactNode;
|
||||
onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||
disabled?: boolean;
|
||||
color?: ButtonProps["color"];
|
||||
} & React.ComponentProps<typeof Button>
|
||||
) {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<DialogPrimitive.Close asChild {...props.dialogCloseProps}>
|
||||
{/* This will require the i18n string passed in */}
|
||||
<Button color={props.color || "minimal"} {...props}>
|
||||
{props.children ? props.children : t("Close")}
|
||||
</Button>
|
||||
</DialogPrimitive.Close>
|
||||
);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ export default function ImageUploader({
|
||||
{buttonMsg}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent useOwnActionButtons>
|
||||
<DialogContent>
|
||||
<div className="mb-4 sm:flex sm:items-start">
|
||||
<div className="mt-3 text-center sm:mt-0 sm:text-left">
|
||||
<h3 className="font-cal text-lg leading-6 text-gray-900" id="modal-title">
|
||||
@@ -201,12 +201,8 @@ export default function ImageUploader({
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 flex flex-row-reverse gap-x-2 sm:mt-4">
|
||||
<DialogClose asChild>
|
||||
<Button onClick={() => showCroppedImage(croppedAreaPixels)}>{t("save")}</Button>
|
||||
</DialogClose>
|
||||
<DialogClose asChild>
|
||||
<Button color="secondary">{t("cancel")}</Button>
|
||||
</DialogClose>
|
||||
<DialogClose onClick={() => showCroppedImage(croppedAreaPixels)}>{t("save")}</DialogClose>
|
||||
<DialogClose color="secondary">{t("cancel")}</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@@ -205,7 +205,6 @@ export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
|
||||
<DialogContent
|
||||
type="creation"
|
||||
className="overflow-y-auto"
|
||||
useOwnActionButtons
|
||||
title={teamId ? t("add_new_team_event_type") : t("add_new_event_type")}
|
||||
description={t("new_event_type_to_book_description")}>
|
||||
<Form
|
||||
@@ -315,9 +314,7 @@ export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
|
||||
<Button type="submit" loading={createMutation.isLoading}>
|
||||
{t("continue")}
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button color="secondary">{t("cancel")}</Button>
|
||||
</DialogClose>
|
||||
<DialogClose />
|
||||
</div>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
|
||||
@@ -3,7 +3,17 @@ import { useState } from "react";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
import { Button, ButtonProps, Dialog, DialogContent, DialogTrigger, Icon, showToast } from "../../..";
|
||||
import {
|
||||
Button,
|
||||
ButtonProps,
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogTrigger,
|
||||
Icon,
|
||||
showToast,
|
||||
DialogFooter,
|
||||
DialogClose,
|
||||
} from "../../..";
|
||||
|
||||
export default function DisconnectIntegration({
|
||||
credentialId,
|
||||
@@ -52,10 +62,14 @@ export default function DisconnectIntegration({
|
||||
title={t("remove_app")}
|
||||
description={t("are_you_sure_you_want_to_remove_this_app")}
|
||||
type="confirmation"
|
||||
actionText={t("yes_remove_app")}
|
||||
Icon={Icon.FiAlertCircle}
|
||||
actionOnClick={() => mutation.mutate({ id: credentialId })}
|
||||
/>
|
||||
Icon={Icon.FiAlertCircle}>
|
||||
<DialogFooter>
|
||||
<DialogClose onClick={() => setModalOpen(false)} />
|
||||
<DialogClose color="primary" onClick={() => mutation.mutate({ id: credentialId })}>
|
||||
{t("yes_remove_app")}
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user