85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
![]() |
import { useTranslation } from 'next-i18next'
|
||
|
import Link from 'next/link'
|
||
|
import { PageLink } from 'shared/components/page-link.mjs'
|
||
|
import { freeSewingConfig as conf } from 'site/freesewing.config.mjs'
|
||
|
|
||
|
export const ns = ['account']
|
||
|
|
||
|
const Li = ({ children }) => <li className="inline">{children}</li>
|
||
|
const Spacer = () => <li className="inline px-1 opacity-60"> | </li>
|
||
|
|
||
|
const LinkList = ({ items, t, control, first = false }) => {
|
||
|
const output = []
|
||
|
if (first)
|
||
|
output.push(
|
||
|
<li key="first" className="inline pr-2">
|
||
|
<b>{first}:</b>
|
||
|
</li>
|
||
|
)
|
||
|
for (const [item, cscore] of Object.entries(items)) {
|
||
|
if (cscore <= control)
|
||
|
output.push(
|
||
|
<Li key={`${item}-li`}>
|
||
|
<PageLink href={`/account/${item}`} txt={t(item)} className="capitalize" />
|
||
|
</Li>,
|
||
|
<Spacer key={`${item}-spacer`} />
|
||
|
)
|
||
|
}
|
||
|
|
||
|
return output.length > 1 ? <ul className="mt-4">{output.slice(0, -1)}</ul> : null
|
||
|
}
|
||
|
|
||
|
const actions = {
|
||
|
reloadAccount: 4,
|
||
|
exportData: 3,
|
||
|
reviewContent: 4,
|
||
|
restrictProcessing: 4,
|
||
|
disableAccount: 4,
|
||
|
removeAccount: 2,
|
||
|
}
|
||
|
|
||
|
export const AccountLinks = ({ account }) => {
|
||
|
const { t } = useTranslation(ns)
|
||
|
|
||
|
const lprops = { t, control: account.control }
|
||
|
|
||
|
return (
|
||
|
<div className="w-full max-w-md">
|
||
|
<Link className="btn btn-primary mb-2 w-full capitalize" href="/create">
|
||
|
{t('newPattern')}
|
||
|
</Link>
|
||
|
<div className="flex flex-row gap-2">
|
||
|
<Link className="btn btn-secondary grow capitalize" href="/create">
|
||
|
{t('newSet')}
|
||
|
</Link>
|
||
|
<Link className="btn btn-warning btnoutline mb-2 capitalize" href="/logout">
|
||
|
{t('logout')}
|
||
|
</Link>
|
||
|
</div>
|
||
|
|
||
|
<ul className="mt-8">
|
||
|
<li className="inline pr-2">
|
||
|
<b>Quick links:</b>
|
||
|
</li>
|
||
|
<Li>
|
||
|
<PageLink href="/profile" txt={t('yourProfile')} />{' '}
|
||
|
</Li>
|
||
|
<Spacer />
|
||
|
<Li>
|
||
|
<PageLink href="/account/patterns" txt={t('yourPatterns')} />{' '}
|
||
|
</Li>
|
||
|
<Spacer />
|
||
|
<Li>
|
||
|
<PageLink href="/account/sets" txt={t('yourSets')} />{' '}
|
||
|
</Li>
|
||
|
</ul>
|
||
|
|
||
|
{Object.keys(conf.account.fields).map((section) => (
|
||
|
<LinkList items={conf.account.fields[section]} first={t(section)} {...lprops} />
|
||
|
))}
|
||
|
|
||
|
<LinkList items={actions} first={t('actions')} {...lprops} />
|
||
|
</div>
|
||
|
)
|
||
|
}
|