1
0
Fork 0
freesewing/sites/shared/components/account/reload.mjs

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-09-04 08:40:05 +02:00
// Context
import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs'
2023-03-24 16:33:14 +01:00
// Hooks
2023-09-04 12:18:52 +02:00
import { useTranslation } from 'next-i18next'
import { useContext } from 'react'
2023-03-24 16:33:14 +01:00
import { useAccount } from 'shared/hooks/use-account.mjs'
import { useBackend } from 'shared/hooks/use-backend.mjs'
// Components
2023-02-19 20:58:06 +01:00
import { BackToAccountButton } from './shared.mjs'
2023-08-19 18:01:22 +02:00
export const ns = ['account', 'status']
export const ReloadAccount = ({ title = false }) => {
// Hooks
2023-08-20 18:48:40 +02:00
const { setAccount } = useAccount()
const backend = useBackend()
const { t } = useTranslation(ns)
2023-09-04 08:40:05 +02:00
const { setLoadingStatus } = useContext(LoadingStatusContext)
// Helper method to reload account
const reload = async () => {
2023-08-19 18:01:22 +02:00
setLoadingStatus([true, 'processingUpdate'])
const result = await backend.reloadAccount()
2023-03-24 16:33:14 +01:00
if (result.success) {
setAccount(result.data.account)
2023-08-19 18:01:22 +02:00
setLoadingStatus([true, 'nailedIt', true, true])
} else setLoadingStatus([true, 'backendError', true, false])
}
return (
<div className="max-w-xl">
{title ? <h2>{t('reloadMsg1')}</h2> : null}
<p>{t('reloadMsg2')}</p>
<button className="btn btn-primary capitalize w-full my-2" onClick={reload}>
{t('reload')}
</button>
2023-08-19 18:01:22 +02:00
<BackToAccountButton />
</div>
)
}