81 lines
3.7 KiB
TypeScript
81 lines
3.7 KiB
TypeScript
import { Fragment, useEffect, useState } from "react";
|
|
import { Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react";
|
|
import clsx from "clsx";
|
|
import { useTranslation } from "react-i18next";
|
|
import { CheckCircleIcon } from "~/components/ui/icons/vendor";
|
|
|
|
interface Props {
|
|
title: string;
|
|
description: string;
|
|
closeText?: string;
|
|
open: boolean;
|
|
onClose: () => void;
|
|
className?: string;
|
|
}
|
|
|
|
export default function OpenSuccessModal({ title, description, closeText, open, onClose, className }: Props) {
|
|
const { t } = useTranslation();
|
|
const [data, setData] = useState<{ title: string; description: string; closeText?: string }>();
|
|
|
|
useEffect(() => {
|
|
if (title && description) {
|
|
setData({ title, description, closeText });
|
|
}
|
|
}, [title, description, closeText]);
|
|
return (
|
|
<Transition show={open} as={Fragment}>
|
|
<Dialog as="div" className={clsx(className, "fixed inset-0 z-50 overflow-y-auto")} onClose={onClose}>
|
|
<div className="flex min-h-screen items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
|
|
<TransitionChild
|
|
as={Fragment}
|
|
enter="ease-out duration-300"
|
|
enterFrom="opacity-0"
|
|
enterTo="opacity-100"
|
|
leave="ease-in duration-200"
|
|
leaveFrom="opacity-100"
|
|
leaveTo="opacity-0"
|
|
>
|
|
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
|
</TransitionChild>
|
|
|
|
{/* This element is to trick the browser into centering the modal contents. */}
|
|
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
|
​
|
|
</span>
|
|
<TransitionChild
|
|
as={Fragment}
|
|
enter="ease-out duration-300"
|
|
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
|
leave="ease-in duration-200"
|
|
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
|
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
>
|
|
{/* Subframe ResultDialog layout: flex-col items-center gap-6, rounded-lg, px-6 py-8, icon badge h-14 w-14 rounded-round, content gap-2, full-width button. */}
|
|
<DialogPanel className="bg-surface-neutral-modal flex w-full max-w-full transform flex-col items-center gap-6 overflow-hidden rounded-lg px-6 py-8 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-96 sm:align-middle">
|
|
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-green-100">
|
|
<CheckCircleIcon className="h-6 w-6 text-green-600" />
|
|
</div>
|
|
<div className="flex w-full flex-col items-center gap-2 text-center">
|
|
<DialogTitle as="h3" className="text-text-neutral-primary text-lg font-medium leading-6">
|
|
{data?.title}
|
|
</DialogTitle>
|
|
<p className="text-text-neutral-tertiary text-sm">{data?.description}</p>
|
|
</div>
|
|
<div className="w-full">
|
|
<button
|
|
type="button"
|
|
className="bg-brand-brand-surface-solid-default text-text-neutral-on-solid hover:bg-brand-brand-surface-solid-hover mt-0 inline-flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium shadow-2xs focus:outline-hidden focus:shadow-focus"
|
|
onClick={onClose}
|
|
>
|
|
{data?.closeText ?? t("shared.close")}
|
|
</button>
|
|
</div>
|
|
</DialogPanel>
|
|
</TransitionChild>
|
|
</div>
|
|
</Dialog>
|
|
</Transition>
|
|
);
|
|
}
|