This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
website/components/Application/ConfirmPopup/ConfirmPopup.tsx

74 lines
2.1 KiB
TypeScript
Raw Normal View History

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