2023-02-28 04:15:33 -05:00
|
|
|
import { useTranslation, Trans } from 'react-i18next'
|
|
|
|
import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context'
|
|
|
|
import getMeta from '../../../../utils/meta'
|
|
|
|
import useAsync from '../../../../shared/hooks/use-async'
|
|
|
|
import { postJSON } from '../../../../infrastructure/fetch-json'
|
2024-09-30 05:49:18 -04:00
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
|
|
|
import OLFormGroup from '@/features/ui/components/ol/ol-form-group'
|
2023-02-28 04:15:33 -05:00
|
|
|
|
|
|
|
function PersonalSubscriptionRecurlySyncEmail() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { personalSubscription } = useSubscriptionDashboardContext()
|
2024-06-18 06:01:37 -04:00
|
|
|
const userEmail = getMeta('ol-usersEmail')
|
2023-02-28 04:15:33 -05:00
|
|
|
const { isLoading, isSuccess, runAsync } = useAsync()
|
|
|
|
|
|
|
|
const handleSubmit = (e: React.FormEvent) => {
|
|
|
|
e.preventDefault()
|
|
|
|
runAsync(postJSON('/user/subscription/account/email'))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!personalSubscription || !('recurly' in personalSubscription)) return null
|
|
|
|
|
|
|
|
const recurlyEmail = personalSubscription.recurly.account.email
|
|
|
|
|
|
|
|
if (!userEmail || recurlyEmail === userEmail) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<form onSubmit={handleSubmit}>
|
2024-09-30 05:49:18 -04:00
|
|
|
<OLFormGroup>
|
2023-02-28 04:15:33 -05:00
|
|
|
{isSuccess ? (
|
2024-09-30 05:49:18 -04:00
|
|
|
<OLNotification
|
|
|
|
type="success"
|
|
|
|
content={t('recurly_email_updated')}
|
|
|
|
/>
|
2023-02-28 04:15:33 -05:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<p>
|
|
|
|
<Trans
|
|
|
|
i18nKey="recurly_email_update_needed"
|
|
|
|
components={[<em />, <em />]} // eslint-disable-line react/jsx-key
|
|
|
|
values={{ recurlyEmail, userEmail }}
|
2023-10-19 04:27:45 -04:00
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
2023-02-28 04:15:33 -05:00
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<div>
|
2024-09-30 05:49:18 -04:00
|
|
|
<OLButton
|
|
|
|
variant="primary"
|
2023-02-28 04:15:33 -05:00
|
|
|
type="submit"
|
|
|
|
disabled={isLoading}
|
2024-09-30 05:49:18 -04:00
|
|
|
isLoading={isLoading}
|
|
|
|
bs3Props={{
|
|
|
|
loading: isLoading ? t('updating') + '…' : t('update'),
|
|
|
|
}}
|
2023-02-28 04:15:33 -05:00
|
|
|
>
|
2024-09-30 05:49:18 -04:00
|
|
|
{t('update')}
|
|
|
|
</OLButton>
|
2023-02-28 04:15:33 -05:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
2024-09-30 05:49:18 -04:00
|
|
|
</OLFormGroup>
|
2023-02-28 04:15:33 -05:00
|
|
|
</form>
|
|
|
|
<hr />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PersonalSubscriptionRecurlySyncEmail
|