2023-01-29 16:44:02 +01:00
|
|
|
// Hooks
|
2023-01-23 20:23:53 +01:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-01-29 16:44:02 +01:00
|
|
|
import { useBackend } from 'site/hooks/useBackend.mjs'
|
|
|
|
// Components
|
2023-01-23 20:23:53 +01:00
|
|
|
import Link from 'next/link'
|
2023-01-29 16:44:02 +01:00
|
|
|
import { Choice, Icons, welcomeSteps } from '../shared.mjs'
|
2023-01-23 20:23:53 +01:00
|
|
|
|
2023-01-28 18:10:29 +01:00
|
|
|
export const ns = ['compare']
|
2023-01-23 20:23:53 +01:00
|
|
|
|
|
|
|
export const CompareSettings = ({ app, title = false, welcome = false }) => {
|
|
|
|
const backend = useBackend(app)
|
2023-01-28 18:10:29 +01:00
|
|
|
const { t } = useTranslation(ns)
|
2023-01-23 20:23:53 +01:00
|
|
|
const [selection, setSelection] = useState(app.account?.compare ? 'yes' : 'no')
|
|
|
|
|
|
|
|
const update = async (val) => {
|
|
|
|
if (val !== selection) {
|
|
|
|
const result = await backend.updateAccount({ compare: val === 'yes' ? true : false })
|
|
|
|
if (result) setSelection(val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 19:31:23 +01:00
|
|
|
const nextHref =
|
2023-01-27 21:09:44 +01:00
|
|
|
welcomeSteps[app.account?.control].length > 3
|
|
|
|
? '/welcome/' + welcomeSteps[app.account?.control][4]
|
2023-01-26 19:31:23 +01:00
|
|
|
: '/docs/guide'
|
|
|
|
|
2023-01-23 20:23:53 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{title ? <h1 className="text-4xl">{t('title')}</h1> : null}
|
|
|
|
{['yes', 'no'].map((val) => (
|
2023-01-27 21:09:44 +01:00
|
|
|
<Choice val={val} t={t} update={update} current={selection} bool key={val}>
|
2023-01-23 20:23:53 +01:00
|
|
|
<span className="block text-lg leading-5">
|
|
|
|
{selection === 1 && val === 2 ? t('showMore') : t(`${val}`)}
|
|
|
|
</span>
|
|
|
|
<span className="block text-xs font-light normal-case pt-1">{t(`${val}d`)}</span>
|
|
|
|
</Choice>
|
|
|
|
))}
|
|
|
|
{welcome ? (
|
|
|
|
<>
|
2023-01-26 19:31:23 +01:00
|
|
|
<Link href={nextHref} className="btn btn-primary w-full mt-12">
|
2023-01-23 20:23:53 +01:00
|
|
|
{t('continue')}
|
|
|
|
</Link>
|
2023-01-27 21:09:44 +01:00
|
|
|
{welcomeSteps[app.account?.control].length > 0 ? (
|
2023-01-23 20:23:53 +01:00
|
|
|
<>
|
|
|
|
<progress
|
|
|
|
className="progress progress-primary w-full mt-12"
|
2023-01-27 21:09:44 +01:00
|
|
|
value={400 / welcomeSteps[app.account?.control].length}
|
2023-01-23 20:23:53 +01:00
|
|
|
max="100"
|
|
|
|
></progress>
|
|
|
|
<span className="pt-4 text-sm font-bold opacity-50">
|
2023-01-27 21:09:44 +01:00
|
|
|
4 / {welcomeSteps[app.account?.control].length}
|
2023-01-23 20:23:53 +01:00
|
|
|
</span>
|
2023-01-26 19:31:23 +01:00
|
|
|
<Icons
|
2023-01-27 21:09:44 +01:00
|
|
|
done={welcomeSteps[app.account?.control].slice(0, 3)}
|
|
|
|
todo={welcomeSteps[app.account?.control].slice(4)}
|
2023-01-26 19:31:23 +01:00
|
|
|
current="compare"
|
|
|
|
/>
|
2023-01-23 20:23:53 +01:00
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CompareSettings
|