42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
![]() |
// Hooks
|
||
|
import { useState } from 'react'
|
||
|
import { useTranslation } from 'next-i18next'
|
||
|
import { useBackend } from 'site/hooks/useBackend.mjs'
|
||
|
import { useToast } from 'site/hooks/useToast.mjs'
|
||
|
// Components
|
||
|
import { BackToAccountButton, updateAccount, Choice } from './shared.mjs'
|
||
|
import { SaveSettingsButton } from 'site/components/buttons/save-settings-button.mjs'
|
||
|
// Config
|
||
|
import { freeSewingConfig as conf } from 'site/freesewing.config.mjs'
|
||
|
|
||
|
export const ns = ['account', 'locales', 'toast']
|
||
|
|
||
|
export const LanguageSettings = ({ app }) => {
|
||
|
const backend = useBackend(app)
|
||
|
const toast = useToast()
|
||
|
const { t } = useTranslation(ns)
|
||
|
const [language, setLanguage] = useState(app.account.language || 'en')
|
||
|
|
||
|
const update = async (lang) => {
|
||
|
if (lang !== language) {
|
||
|
app.startLoading()
|
||
|
setLanguage(lang)
|
||
|
const result = await backend.updateAccount({ language: lang })
|
||
|
if (result === true) toast.for.settingsSaved()
|
||
|
else toast.for.backendError()
|
||
|
app.stopLoading()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
{conf.languages.map((val) => (
|
||
|
<Choice val={val} t={t} update={update} current={language} key={val}>
|
||
|
<span className="block text-lg leading-5">{t(`locales:${val}`)}</span>
|
||
|
</Choice>
|
||
|
))}
|
||
|
<BackToAccountButton loading={app.loading} />
|
||
|
</>
|
||
|
)
|
||
|
}
|