2023-05-05 19:56:51 +02:00
|
|
|
import { useContext } from 'react'
|
2023-05-17 17:32:19 +02:00
|
|
|
import { validateEmail, validateTld } from 'shared/utils.mjs'
|
2023-02-12 18:35:54 +01:00
|
|
|
import { Spinner } from 'shared/components/spinner.mjs'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-03-19 19:03:51 +01:00
|
|
|
import { EmailIcon, RightIcon, WarningIcon } from 'shared/components/icons.mjs'
|
|
|
|
import { FlexButtonText } from './flex-button-text.mjs'
|
2023-05-05 19:56:51 +02:00
|
|
|
// Context
|
|
|
|
import { LoadingContext } from 'shared/context/loading-context.mjs'
|
2023-02-12 18:35:54 +01:00
|
|
|
|
2023-05-05 19:56:51 +02:00
|
|
|
export const EmailValidButton = ({ email, validText, invalidText, btnProps = {} }) => {
|
|
|
|
// Context
|
|
|
|
const { loading } = useContext(LoadingContext)
|
2023-02-12 18:35:54 +01:00
|
|
|
const { t } = useTranslation(['signup'])
|
|
|
|
const emailValid = (validateEmail(email) && validateTld(email)) || false
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
style={{
|
|
|
|
backgroundColor: emailValid ? '' : 'hsl(var(--wa) / var(--tw-border-opacity))',
|
|
|
|
opacity: emailValid ? 1 : 0.8,
|
|
|
|
}}
|
|
|
|
className={`btn mt-4 capitalize w-full
|
2023-05-05 19:56:51 +02:00
|
|
|
${emailValid ? (loading ? 'btn-accent' : 'btn-primary') : 'btn-warning'}`}
|
2023-02-12 18:35:54 +01:00
|
|
|
tabIndex="-1"
|
|
|
|
role="button"
|
|
|
|
aria-disabled={!emailValid}
|
|
|
|
{...btnProps}
|
|
|
|
>
|
2023-03-19 19:03:51 +01:00
|
|
|
<FlexButtonText>
|
|
|
|
{emailValid ? (
|
2023-05-05 19:56:51 +02:00
|
|
|
loading ? (
|
2023-02-12 18:35:54 +01:00
|
|
|
<>
|
|
|
|
<Spinner />
|
|
|
|
<span>{t('processing')}</span>
|
2023-03-19 19:03:51 +01:00
|
|
|
<Spinner />
|
2023-02-12 18:35:54 +01:00
|
|
|
</>
|
|
|
|
) : (
|
2023-03-19 19:03:51 +01:00
|
|
|
<>
|
|
|
|
<EmailIcon />
|
|
|
|
<span>{validText}</span>
|
|
|
|
<RightIcon />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<EmailIcon />
|
|
|
|
<span>{invalidText}</span>
|
|
|
|
<WarningIcon />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</FlexButtonText>
|
2023-02-12 18:35:54 +01:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|