1
0
Fork 0
freesewing/sites/org/components/account/bio/index.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

2023-01-26 19:31:23 +01:00
import { useState } from 'react'
import { useTranslation } from 'next-i18next'
import useBackend from 'site/hooks/useBackend.js'
import Link from 'next/link'
2023-01-27 21:09:44 +01:00
import { Icons, welcomeSteps } from '../shared.js'
2023-01-26 19:31:23 +01:00
import Popout from 'shared/components/popout.js'
import Markdown from 'react-markdown'
export const namespaces = ['bio']
const Tab = ({ id, activeTab, setActiveTab, t }) => (
<button
className={`text-xl font-bold capitalize tab tab-bordered grow
${activeTab === id ? 'tab-active' : ''}`}
onClick={() => setActiveTab(id)}
>
{t(id)}
</button>
)
const UsernameSettings = ({ app, title = false, welcome = false }) => {
const backend = useBackend(app)
const { t } = useTranslation(namespaces)
const [bio, setBio] = useState(app.account.bio)
const [activeTab, setActiveTab] = useState('edit')
const save = async () => {
2023-01-27 21:09:44 +01:00
await backend.updateAccount({ bio })
2023-01-26 19:31:23 +01:00
}
const nextHref =
welcomeSteps[app.account.control].length > 5
? '/welcome/' + welcomeSteps[app.account.control][6]
: '/docs/guide'
const tabProps = { activeTab, setActiveTab, t }
return (
<>
{title ? <h1 className="text-4xl">{t('title')}</h1> : null}
<div className="tabs w-full">
<Tab id="edit" {...tabProps} />
<Tab id="preview" {...tabProps} />
</div>
<div className="flex flex-row items-center mt-4">
{activeTab === 'edit' ? (
<textarea
rows="5"
className="textarea textarea-bordered textarea-lg w-full"
placeholder={t('placeholder')}
onChange={(evt) => setBio(evt.target.value)}
2023-01-27 21:09:44 +01:00
value={bio}
/>
2023-01-26 19:31:23 +01:00
) : (
<div className="text-left px-4 border w-full">
<Markdown>{bio}</Markdown>
</div>
)}
</div>
<button className={`btn btn-secondary mt-4 w-64`} onClick={save}>
{t('save')}
</button>
<Popout tip compact>
{t('mdSupport')}
</Popout>
{welcome ? (
<>
<Link href={nextHref} className="btn btn-primary w-full mt-12">
{t('continue')}
</Link>
{welcomeSteps[app.account.control].length > 0 ? (
<>
<progress
className="progress progress-primary w-full mt-12"
value={600 / welcomeSteps[app.account.control].length}
max="100"
></progress>
<span className="pt-4 text-sm font-bold opacity-50">
6 / {welcomeSteps[app.account.control].length}
</span>
<Icons
done={welcomeSteps[app.account.control].slice(0, 5)}
todo={welcomeSteps[app.account.control].slice(6)}
current="bio"
/>
</>
) : null}
</>
) : null}
</>
)
}
export default UsernameSettings