2023-05-17 17:32:19 +02:00
|
|
|
import { validateEmail, validateTld } from 'shared/utils.mjs'
|
2023-03-19 19:03:51 +01:00
|
|
|
import { Spinner } from 'shared/components/spinner.mjs'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import { EmailIcon, RightIcon, WarningIcon } from 'shared/components/icons.mjs'
|
|
|
|
|
|
|
|
export const FlexButtonText = ({ children }) => (
|
|
|
|
<div className="flex flex-row items-center justify-between w-full">{children}</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
export const EmailValidButton = ({ email, app, validText, invalidText, btnProps = {} }) => {
|
|
|
|
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-03-24 21:30:04 +01:00
|
|
|
${emailValid ? (app.state.loading ? 'btn-accent' : 'btn-primary') : 'btn-warning'}`}
|
2023-03-19 19:03:51 +01:00
|
|
|
tabIndex="-1"
|
|
|
|
role="button"
|
|
|
|
aria-disabled={!emailValid}
|
|
|
|
{...btnProps}
|
|
|
|
>
|
|
|
|
<FlexButtonText>
|
|
|
|
{emailValid ? (
|
2023-03-24 21:30:04 +01:00
|
|
|
app.state.loading ? (
|
2023-03-19 19:03:51 +01:00
|
|
|
<>
|
|
|
|
<Spinner />
|
|
|
|
<span>{t('processing')}</span>
|
|
|
|
<Spinner />
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<EmailIcon />
|
|
|
|
<span>{validText}</span>
|
|
|
|
<RightIcon />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<EmailIcon />
|
|
|
|
<span>{invalidText}</span>
|
|
|
|
<WarningIcon />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</FlexButtonText>
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|