2023-03-24 16:33:14 +01:00
|
|
|
// Dependencies
|
|
|
|
import { useState } from 'react'
|
2023-02-19 20:49:15 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-03-24 16:33:14 +01:00
|
|
|
// Hooks
|
|
|
|
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-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']
|
|
|
|
|
|
|
|
export const ReloadAccount = ({ app, title = false }) => {
|
2023-03-24 16:33:14 +01:00
|
|
|
const { account, setAccount, token } = useAccount()
|
|
|
|
const backend = useBackend(token)
|
2023-02-19 20:49:15 +01:00
|
|
|
const { t } = useTranslation(ns)
|
|
|
|
const toast = useToast()
|
|
|
|
|
|
|
|
const reload = async () => {
|
|
|
|
app.startLoading()
|
|
|
|
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-02-19 20:49:15 +01:00
|
|
|
app.stopLoading()
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{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-03-24 16:33:14 +01:00
|
|
|
<BackToAccountButton loading={app.state.loading} />
|
2023-02-19 20:49:15 +01:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|