2023-10-23 23:33:39 +02:00
|
|
|
import Image from "next/image"
|
|
|
|
import { useState } from "react"
|
|
|
|
import useTranslation from "next-translate/useTranslation"
|
|
|
|
import classNames from "clsx"
|
2022-03-05 18:22:30 +01:00
|
|
|
|
2023-10-23 23:33:39 +02:00
|
|
|
import { Loader } from "../../design/Loader"
|
2022-02-09 23:27:54 +01:00
|
|
|
|
2022-04-09 13:48:48 +02:00
|
|
|
export interface ConfirmPopupProps {
|
2022-02-09 23:27:54 +01:00
|
|
|
className?: string
|
2022-04-09 13:48:48 +02:00
|
|
|
title: string
|
2022-03-05 18:22:30 +01:00
|
|
|
handleYes: () => void | Promise<void>
|
|
|
|
handleNo: () => void | Promise<void>
|
2022-02-09 23:27:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-09 13:48:48 +02:00
|
|
|
export const ConfirmPopup: React.FC<ConfirmPopupProps> = ({ ...props }) => {
|
2022-03-16 11:25:44 +01:00
|
|
|
const { t } = useTranslation()
|
2022-03-05 18:22:30 +01:00
|
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
|
|
|
|
|
|
const handleYesLoading = async (): Promise<void> => {
|
2022-08-31 21:44:33 +02:00
|
|
|
setIsLoading((isLoading) => {
|
|
|
|
return !isLoading
|
|
|
|
})
|
2022-03-16 11:25:44 +01:00
|
|
|
await props.handleYes()
|
2022-03-05 18:22:30 +01:00
|
|
|
}
|
2022-02-09 23:27:54 +01:00
|
|
|
|
|
|
|
return (
|
2022-03-16 11:25:44 +01:00
|
|
|
<div className={props.className}>
|
|
|
|
<Loader
|
2022-04-09 13:48:48 +02:00
|
|
|
className={classNames(
|
2023-10-23 23:33:39 +02:00
|
|
|
"absolute left-1/2 top-1/2 scale-0 transition-all",
|
2022-04-09 13:48:48 +02:00
|
|
|
{
|
2023-10-23 23:33:39 +02:00
|
|
|
"scale-100": isLoading,
|
|
|
|
},
|
2022-04-09 13:48:48 +02:00
|
|
|
)}
|
2022-03-16 11:25:44 +01:00
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2023-10-23 23:33:39 +02:00
|
|
|
"visible flex flex-col items-center opacity-100 transition-all",
|
2022-03-16 11:25:44 +01:00
|
|
|
{
|
2023-10-23 23:33:39 +02:00
|
|
|
"invisible opacity-0": isLoading,
|
|
|
|
},
|
2022-03-16 11:25:44 +01:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Image
|
2022-04-07 16:54:05 +02:00
|
|
|
quality={100}
|
2023-10-23 23:33:39 +02:00
|
|
|
src="/images/svg/design/join-guild.svg"
|
|
|
|
alt="Illustration"
|
2022-03-16 11:25:44 +01:00
|
|
|
height={150}
|
|
|
|
width={150}
|
|
|
|
/>
|
2023-10-23 23:33:39 +02:00
|
|
|
<div className="mt-8 flex flex-col">
|
|
|
|
<h1 className="mb-6 text-center text-xl">{props.title}</h1>
|
|
|
|
<div className="flex gap-7">
|
2022-03-16 11:25:44 +01:00
|
|
|
<button
|
2023-10-23 23:33:39 +02:00
|
|
|
className="rounded-3xl bg-success px-8 py-2 text-white transition hover:brightness-125 dark:text-black hover:dark:brightness-75"
|
2022-03-16 11:25:44 +01:00
|
|
|
onClick={handleYesLoading}
|
2023-10-23 23:33:39 +02:00
|
|
|
data-cy="confirm-popup-yes-button"
|
2022-03-16 11:25:44 +01:00
|
|
|
>
|
2023-10-23 23:33:39 +02:00
|
|
|
{t("common:yes")}
|
2022-03-16 11:25:44 +01:00
|
|
|
</button>
|
|
|
|
<button
|
2023-10-23 23:33:39 +02:00
|
|
|
className="rounded-3xl bg-error px-8 py-2 text-white transition hover:brightness-125 dark:text-black hover:dark:brightness-75"
|
2022-03-16 11:25:44 +01:00
|
|
|
onClick={props.handleNo}
|
2023-10-23 23:33:39 +02:00
|
|
|
data-cy="confirm-popup-no-button"
|
2022-03-16 11:25:44 +01:00
|
|
|
>
|
2023-10-23 23:33:39 +02:00
|
|
|
{t("common:no")}
|
2022-03-16 11:25:44 +01:00
|
|
|
</button>
|
2022-03-05 18:22:30 +01:00
|
|
|
</div>
|
2022-03-16 11:25:44 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-09 23:27:54 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|