2021-08-10 22:25:26 +00:00
|
|
|
import { ExclamationIcon } from "@heroicons/react/outline";
|
2021-09-30 23:42:08 +00:00
|
|
|
import { CheckIcon } from "@heroicons/react/solid";
|
2021-09-22 19:52:38 +00:00
|
|
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
2021-08-27 14:22:49 +00:00
|
|
|
import React, { PropsWithChildren } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
|
|
|
|
2021-09-22 19:52:38 +00:00
|
|
|
import { DialogClose, DialogContent } from "@components/Dialog";
|
2021-08-27 14:22:49 +00:00
|
|
|
import { Button } from "@components/ui/Button";
|
2021-08-10 22:25:26 +00:00
|
|
|
|
2021-08-27 14:22:49 +00:00
|
|
|
export type ConfirmationDialogContentProps = {
|
|
|
|
confirmBtnText?: string;
|
|
|
|
cancelBtnText?: string;
|
2021-09-30 23:42:08 +00:00
|
|
|
onConfirm?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
2021-08-27 14:22:49 +00:00
|
|
|
title: string;
|
2021-09-30 23:42:08 +00:00
|
|
|
variety?: "danger" | "warning" | "success";
|
2021-08-27 14:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function ConfirmationDialogContent(props: PropsWithChildren<ConfirmationDialogContentProps>) {
|
2021-10-12 13:11:33 +00:00
|
|
|
const { t } = useLocale();
|
2021-10-08 11:43:48 +00:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
variety,
|
|
|
|
confirmBtnText = t("confirm"),
|
|
|
|
cancelBtnText = t("cancel"),
|
|
|
|
onConfirm,
|
|
|
|
children,
|
|
|
|
} = props;
|
2021-08-10 22:25:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<DialogContent>
|
|
|
|
<div className="flex">
|
2021-08-27 14:22:49 +00:00
|
|
|
{variety && (
|
2021-08-10 22:25:26 +00:00
|
|
|
<div className="mr-3 mt-0.5">
|
2021-08-27 14:22:49 +00:00
|
|
|
{variety === "danger" && (
|
2021-08-10 22:25:26 +00:00
|
|
|
<div className="text-center p-2 rounded-full mx-auto bg-red-100">
|
|
|
|
<ExclamationIcon className="w-5 h-5 text-red-600" />
|
|
|
|
</div>
|
|
|
|
)}
|
2021-09-30 23:42:08 +00:00
|
|
|
{variety === "warning" && (
|
|
|
|
<div className="text-center p-2 rounded-full mx-auto bg-orange-100">
|
|
|
|
<ExclamationIcon className="w-5 h-5 text-orange-600" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{variety === "success" && (
|
|
|
|
<div className="text-center p-2 rounded-full mx-auto bg-green-100">
|
|
|
|
<CheckIcon className="w-5 h-5 text-green-600" />
|
|
|
|
</div>
|
|
|
|
)}
|
2021-08-10 22:25:26 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div>
|
2021-09-24 11:28:57 +00:00
|
|
|
<DialogPrimitive.Title className="font-cal text-xl font-bold text-gray-900">
|
|
|
|
{title}
|
|
|
|
</DialogPrimitive.Title>
|
2021-08-10 22:25:26 +00:00
|
|
|
<DialogPrimitive.Description className="text-neutral-500">{children}</DialogPrimitive.Description>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-27 14:22:49 +00:00
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-x-2">
|
2021-09-13 11:28:17 +00:00
|
|
|
<DialogClose onClick={onConfirm} asChild>
|
|
|
|
<Button color="primary">{confirmBtnText}</Button>
|
2021-08-10 22:25:26 +00:00
|
|
|
</DialogClose>
|
2021-09-13 11:28:17 +00:00
|
|
|
<DialogClose asChild>
|
|
|
|
<Button color="secondary">{cancelBtnText}</Button>
|
2021-08-27 14:22:49 +00:00
|
|
|
</DialogClose>
|
2021-08-10 22:25:26 +00:00
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
);
|
|
|
|
}
|