2023-03-24 16:33:14 +01:00
|
|
|
// Dependencies
|
2023-08-20 18:48:40 +02:00
|
|
|
import { useState } from 'react'
|
2023-01-23 20:23:53 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-03-24 16:33:14 +01:00
|
|
|
// Hooks
|
|
|
|
import { useAccount } from 'shared/hooks/use-account.mjs'
|
|
|
|
import { useBackend } from 'shared/hooks/use-backend.mjs'
|
2023-08-19 18:01:22 +02:00
|
|
|
import { useLoadingStatus } from 'shared/hooks/use-loading-status.mjs'
|
2023-01-29 16:44:02 +01:00
|
|
|
// Components
|
2023-08-26 09:06:51 +02:00
|
|
|
import { Icons, welcomeSteps, BackToAccountButton } from './shared.mjs'
|
2023-05-17 17:32:19 +02:00
|
|
|
import { ContinueButton } from 'shared/components/buttons/continue-button.mjs'
|
2023-08-25 17:18:24 +02:00
|
|
|
import { ListInput } from 'shared/components/inputs.mjs'
|
|
|
|
import { OkIcon, NoIcon } from 'shared/components/icons.mjs'
|
|
|
|
import { DynamicOrgDocs } from 'shared/components/dynamic-docs/org.mjs'
|
2023-01-23 20:23:53 +01:00
|
|
|
|
2023-08-19 18:01:22 +02:00
|
|
|
export const ns = ['account', 'status']
|
2023-01-23 20:23:53 +01:00
|
|
|
|
2023-08-26 09:15:28 +02:00
|
|
|
export const CompareSettings = ({ welcome = false }) => {
|
2023-04-28 21:23:06 +02:00
|
|
|
// Hooks
|
2023-08-20 18:48:40 +02:00
|
|
|
const { account, setAccount } = useAccount()
|
|
|
|
const backend = useBackend()
|
2023-08-19 18:01:22 +02:00
|
|
|
const { setLoadingStatus, LoadingStatus } = useLoadingStatus()
|
2023-08-25 17:18:24 +02:00
|
|
|
const { t, i18n } = useTranslation(ns)
|
2023-04-28 21:23:06 +02:00
|
|
|
|
|
|
|
// State
|
2023-03-24 16:33:14 +01:00
|
|
|
const [selection, setSelection] = useState(account?.compare ? 'yes' : 'no')
|
2023-01-23 20:23:53 +01:00
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
// Helper method to update the account
|
2023-01-23 20:23:53 +01:00
|
|
|
const update = async (val) => {
|
|
|
|
if (val !== selection) {
|
2023-08-19 18:01:22 +02:00
|
|
|
setLoadingStatus([true, 'processingUpdate'])
|
2023-04-28 21:23:06 +02:00
|
|
|
const result = await backend.updateAccount({
|
|
|
|
compare: val === 'yes' ? true : false,
|
|
|
|
})
|
2023-03-24 16:33:14 +01:00
|
|
|
if (result.success) {
|
2023-08-19 18:01:22 +02:00
|
|
|
setLoadingStatus([true, 'settingsSaved', true, true])
|
2023-03-24 16:33:14 +01:00
|
|
|
setAccount(result.data.account)
|
2023-02-12 18:35:54 +01:00
|
|
|
setSelection(val)
|
2023-08-19 18:01:22 +02:00
|
|
|
} else setLoadingStatus([true, 'backendError', true, true])
|
2023-01-23 20:23:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
// Link to the next onboarding step
|
2023-01-26 19:31:23 +01:00
|
|
|
const nextHref =
|
2023-03-24 16:33:14 +01:00
|
|
|
welcomeSteps[account?.control].length > 3
|
|
|
|
? '/welcome/' + welcomeSteps[account?.control][4]
|
2023-01-26 19:31:23 +01:00
|
|
|
: '/docs/guide'
|
|
|
|
|
2023-01-23 20:23:53 +01:00
|
|
|
return (
|
2023-03-27 19:21:27 +02:00
|
|
|
<div className="max-w-xl">
|
2023-08-19 18:01:22 +02:00
|
|
|
<LoadingStatus />
|
2023-08-25 17:18:24 +02:00
|
|
|
<ListInput
|
2023-08-26 09:27:27 +02:00
|
|
|
id="account-compare"
|
2023-08-25 17:18:24 +02:00
|
|
|
label={t('compareTitle')}
|
|
|
|
list={['yes', 'no'].map((val) => ({
|
|
|
|
val,
|
|
|
|
label: (
|
|
|
|
<div className="flex flex-row items-center w-full justify-between">
|
|
|
|
<span>{t(val === 'yes' ? 'compareYes' : 'compareNo')}</span>
|
|
|
|
{val === 'yes' ? (
|
|
|
|
<OkIcon className="w-8 h-8 text-success" stroke={4} />
|
|
|
|
) : (
|
|
|
|
<NoIcon className="w-8 h-8 text-error" stroke={3} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
desc: t(val === 'yes' ? 'compareYesd' : 'compareNod'),
|
|
|
|
}))}
|
|
|
|
current={selection}
|
|
|
|
update={update}
|
|
|
|
docs={<DynamicOrgDocs language={i18n.language} path={`site/account/compare`} />}
|
|
|
|
/>
|
2023-01-23 20:23:53 +01:00
|
|
|
{welcome ? (
|
|
|
|
<>
|
2023-04-28 21:23:06 +02:00
|
|
|
<ContinueButton btnProps={{ href: nextHref }} link />
|
2023-03-24 16:33:14 +01:00
|
|
|
{welcomeSteps[account?.control].length > 0 ? (
|
2023-01-23 20:23:53 +01:00
|
|
|
<>
|
|
|
|
<progress
|
|
|
|
className="progress progress-primary w-full mt-12"
|
2023-03-24 16:33:14 +01:00
|
|
|
value={400 / welcomeSteps[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-03-24 16:33:14 +01:00
|
|
|
4 / {welcomeSteps[account?.control].length}
|
2023-01-23 20:23:53 +01:00
|
|
|
</span>
|
2023-01-26 19:31:23 +01:00
|
|
|
<Icons
|
2023-03-24 16:33:14 +01:00
|
|
|
done={welcomeSteps[account?.control].slice(0, 3)}
|
|
|
|
todo={welcomeSteps[account?.control].slice(4)}
|
2023-01-26 19:31:23 +01:00
|
|
|
current="compare"
|
|
|
|
/>
|
2023-01-23 20:23:53 +01:00
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</>
|
2023-02-18 16:11:02 +01:00
|
|
|
) : (
|
2023-08-19 18:01:22 +02:00
|
|
|
<BackToAccountButton />
|
2023-02-18 16:11:02 +01:00
|
|
|
)}
|
2023-03-27 19:21:27 +02:00
|
|
|
</div>
|
2023-01-23 20:23:53 +01:00
|
|
|
)
|
|
|
|
}
|