2023-03-24 16:33:14 +01:00
|
|
|
// Dependencies
|
2023-02-19 20:49:15 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-03-24 16:33:14 +01:00
|
|
|
// Hooks
|
2023-04-28 21:23:06 +02:00
|
|
|
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'
|
|
|
|
import { useToast } from 'shared/hooks/use-toast.mjs'
|
2023-04-28 21:23:06 +02:00
|
|
|
// Context
|
|
|
|
import { LoadingContext } from 'shared/context/loading-context.mjs'
|
2023-02-19 20:49:15 +01:00
|
|
|
// Components
|
2023-02-19 20:58:06 +01:00
|
|
|
import { BackToAccountButton } from './shared.mjs'
|
2023-02-19 20:49:15 +01:00
|
|
|
|
|
|
|
export const ns = ['account', 'toast']
|
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
export const ReloadAccount = ({ title = false }) => {
|
|
|
|
// Context
|
|
|
|
const { loading, startLoading, stopLoading } = useContext(LoadingContext)
|
|
|
|
|
|
|
|
// Hooks
|
2023-04-16 17:13:18 +02:00
|
|
|
const { setAccount, token } = useAccount()
|
2023-03-24 16:33:14 +01:00
|
|
|
const backend = useBackend(token)
|
2023-02-19 20:49:15 +01:00
|
|
|
const { t } = useTranslation(ns)
|
|
|
|
const toast = useToast()
|
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
// Helper method to reload account
|
2023-02-19 20:49:15 +01:00
|
|
|
const reload = async () => {
|
2023-04-28 21:23:06 +02:00
|
|
|
startLoading()
|
2023-02-19 20:49:15 +01:00
|
|
|
const result = await backend.reloadAccount()
|
2023-03-24 16:33:14 +01:00
|
|
|
if (result.success) {
|
|
|
|
setAccount(result.data.account)
|
|
|
|
toast.success(<span>{t('nailedIt')}</span>)
|
|
|
|
} else toast.for.backendError()
|
2023-04-28 21:23:06 +02:00
|
|
|
stopLoading()
|
2023-02-19 20:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-04-28 21:23:06 +02:00
|
|
|
<div className="max-w-xl">
|
2023-02-19 20:49:15 +01:00
|
|
|
{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-04-28 21:23:06 +02:00
|
|
|
<BackToAccountButton loading={loading} />
|
|
|
|
</div>
|
2023-02-19 20:49:15 +01:00
|
|
|
)
|
|
|
|
}
|