feat(org/backend): Added account data export
This commit is contained in:
parent
ac5a441d7b
commit
5d1249c419
11 changed files with 220 additions and 19 deletions
|
@ -4,25 +4,20 @@ import { useTranslation } from 'next-i18next'
|
|||
// 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'
|
||||
// Context
|
||||
import { LoadingContext } from 'shared/context/loading-context.mjs'
|
||||
import { useLoadingStatus } from 'shared/hooks/use-loading-status.mjs'
|
||||
// Components
|
||||
import { BackToAccountButton } from './shared.mjs'
|
||||
import { SaveSettingsButton } from 'shared/components/buttons/save-settings-button.mjs'
|
||||
import { Popout } from 'shared/components/popout/index.mjs'
|
||||
|
||||
export const ns = ['account', 'toast']
|
||||
|
||||
export const GithubSettings = ({ title = false, welcome = false }) => {
|
||||
// Context
|
||||
const { loading, startLoading, stopLoading } = useContext(LoadingContext)
|
||||
export const ns = ['account', 'status']
|
||||
|
||||
export const GithubSettings = () => {
|
||||
// Hooks
|
||||
const { account, setAccount, token } = useAccount()
|
||||
const backend = useBackend(token)
|
||||
const { t } = useTranslation(ns)
|
||||
const toast = useToast()
|
||||
const { setLoadingStatus, LoadingStatus } = useLoadingStatus()
|
||||
|
||||
// State
|
||||
const [githubUsername, setGithubUsername] = useState(account.data.githubUsername || '')
|
||||
|
@ -30,18 +25,18 @@ export const GithubSettings = ({ title = false, welcome = false }) => {
|
|||
|
||||
// Helper method to save changes
|
||||
const save = async () => {
|
||||
startLoading()
|
||||
setLoadingStatus([true, 'processingUpdate'])
|
||||
const result = await backend.updateAccount({ data: { githubUsername, githubEmail } })
|
||||
if (result.success) {
|
||||
setAccount(result.data.account)
|
||||
toast.for.settingsSaved()
|
||||
} else toast.for.backendError()
|
||||
stopLoading()
|
||||
setLoadingStatus([true, 'settingsSaved', true, true])
|
||||
} else setLoadingStatus([true, 'backendError', true, false])
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-xl">
|
||||
{title ? <h2 className="text-4xl">{t('githubTitle')}</h2> : null}
|
||||
<LoadingStatus />
|
||||
<h2 className="text-4xl">{t('githubTitle')}</h2>
|
||||
<label className="font-bold">{t('username')}</label>
|
||||
<div className="flex flex-row items-center mb-4">
|
||||
<input
|
||||
|
@ -63,7 +58,7 @@ export const GithubSettings = ({ title = false, welcome = false }) => {
|
|||
/>
|
||||
</div>
|
||||
<SaveSettingsButton btnProps={{ onClick: save }} />
|
||||
{!welcome && <BackToAccountButton loading={loading} />}
|
||||
<BackToAccountButton />
|
||||
<Popout note>
|
||||
<p className="text-sm font-bold">{t('githubWhy1')}</p>
|
||||
<p className="text-sm">{t('githubWhy2')}</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue