2022-11-19 14:21:26 +00:00
|
|
|
import React from "react";
|
|
|
|
// hooks
|
2023-01-26 18:12:20 +00:00
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// icons
|
2023-04-28 06:07:52 +00:00
|
|
|
import { LinkIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
|
|
|
import { ErrorIcon, SuccessIcon } from "components/icons";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
const ToastAlerts = () => {
|
|
|
|
const { alerts, removeAlert } = useToast();
|
|
|
|
|
|
|
|
if (!alerts) return null;
|
|
|
|
|
|
|
|
return (
|
2023-04-28 06:07:52 +00:00
|
|
|
<div className="pointer-events-none fixed top-5 right-5 z-50 h-full w-96 space-y-5 overflow-hidden rounded-md">
|
2022-11-19 14:21:26 +00:00
|
|
|
{alerts.map((alert) => (
|
2023-04-28 06:07:52 +00:00
|
|
|
<div
|
|
|
|
className="relative flex flex-col items-center justify-center gap-2 overflow-hidden rounded-md border-[2px] border-brand-surface-2 bg-brand-base px-4 py-3 text-sm text-brand-base shadow-md"
|
|
|
|
key={alert.id}
|
|
|
|
>
|
2022-11-19 14:21:26 +00:00
|
|
|
<div className="absolute top-1 right-1">
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-28 06:07:52 +00:00
|
|
|
className="pointer-events-auto inline-flex rounded-md p-1.5 text-brand-secondary"
|
2022-11-19 14:21:26 +00:00
|
|
|
onClick={() => removeAlert(alert.id)}
|
|
|
|
>
|
|
|
|
<span className="sr-only">Dismiss</span>
|
2023-04-28 06:07:52 +00:00
|
|
|
<XMarkIcon className="h-4 w-4" aria-hidden="true" />
|
2022-11-19 14:21:26 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2023-04-28 06:07:52 +00:00
|
|
|
{alert.type !== "info" ? (
|
|
|
|
<>
|
|
|
|
<div className="flex w-full items-center gap-2.5">
|
2022-11-19 14:21:26 +00:00
|
|
|
{alert.type === "success" ? (
|
2023-04-28 06:07:52 +00:00
|
|
|
<SuccessIcon className="h-4 w-4" />
|
2022-11-19 14:21:26 +00:00
|
|
|
) : alert.type === "error" ? (
|
2023-04-28 06:07:52 +00:00
|
|
|
<ErrorIcon className="h-4 w-4" />
|
2022-11-19 14:21:26 +00:00
|
|
|
) : (
|
2023-04-28 06:07:52 +00:00
|
|
|
""
|
2022-11-19 14:21:26 +00:00
|
|
|
)}
|
2023-04-28 06:07:52 +00:00
|
|
|
<p
|
|
|
|
className={`font-medium ${
|
|
|
|
alert.type === "success"
|
|
|
|
? "text-brand-base"
|
|
|
|
: alert.type === "error"
|
2023-04-28 07:10:31 +00:00
|
|
|
? "text-[#ef476f]"
|
2023-04-28 06:07:52 +00:00
|
|
|
: alert.type === "warning"
|
2023-04-28 07:10:31 +00:00
|
|
|
? "text-[#e98601]"
|
|
|
|
: "text-[#1B9aaa]"
|
2023-04-28 06:07:52 +00:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{alert.title}
|
|
|
|
</p>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2023-04-28 06:07:52 +00:00
|
|
|
<div className="flex w-full items-center justify-start text-brand-secondary">
|
|
|
|
<p className="text-left">{alert.message}</p>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2023-04-28 06:07:52 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<div className="flex w-full items-center justify-center gap-2.5 py-2 text-brand-secondary">
|
|
|
|
{alert.iconType === "copy" && (
|
|
|
|
<span>
|
|
|
|
<LinkIcon className="h-4 w-4" />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
<p className="font-medium italic">{alert.title}</p>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2023-04-28 06:07:52 +00:00
|
|
|
)}
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ToastAlerts;
|