2025-04-01 16:15:20 +02:00
|
|
|
// Dependencies
|
|
|
|
import { welcomeSteps } from './shared.mjs'
|
|
|
|
// Context
|
|
|
|
import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus'
|
|
|
|
// Hooks
|
|
|
|
import React, { useState, useContext } from 'react'
|
|
|
|
import { useAccount } from '@freesewing/react/hooks/useAccount'
|
|
|
|
import { useBackend } from '@freesewing/react/hooks/useBackend'
|
|
|
|
// Components
|
2025-05-30 11:29:55 +02:00
|
|
|
import { NoIcon, OkIcon, RightIcon } from '@freesewing/react/components/Icon'
|
2025-04-01 16:15:20 +02:00
|
|
|
import { ListInput } from '@freesewing/react/components/Input'
|
|
|
|
import { IconButton } from '@freesewing/react/components/Button'
|
|
|
|
import { WelcomeIcons } from './shared.mjs'
|
|
|
|
|
|
|
|
const strings = {
|
|
|
|
yes: {
|
|
|
|
title: 'Yes, in case it may help me',
|
|
|
|
desc:
|
|
|
|
'Allowing us to compare your measurments to a baseline or others measurements sets ' +
|
|
|
|
'allows us to detect potential problems in your measurements or patterns.',
|
|
|
|
},
|
|
|
|
no: {
|
|
|
|
title: 'No, never compare',
|
|
|
|
desc:
|
|
|
|
'We get it, comparison is the thief of joy. Just be aware that this limits our ability ' +
|
|
|
|
'to warn you about potential problems in your measurements sets or patterns.',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-05-09 17:46:51 +02:00
|
|
|
/**
|
|
|
|
* A component to manage the user's compare setting
|
2025-04-01 16:15:20 +02:00
|
|
|
*
|
2025-05-09 17:46:51 +02:00
|
|
|
* @component
|
|
|
|
* @params {bool} [props.welcome = false] - Set to true to render the welcome/onboarding view
|
|
|
|
* @returns {JSX.Element}
|
2025-04-01 16:15:20 +02:00
|
|
|
*/
|
|
|
|
export const Compare = ({ welcome = false }) => {
|
|
|
|
// Hooks
|
|
|
|
const { account, setAccount } = useAccount()
|
|
|
|
const backend = useBackend()
|
|
|
|
|
|
|
|
// State
|
|
|
|
const [selection, setSelection] = useState(account?.compare ? 'yes' : 'no')
|
|
|
|
|
|
|
|
// Context
|
|
|
|
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
|
|
|
|
|
|
|
// Helper method to update the account
|
|
|
|
const update = async (val) => {
|
|
|
|
if (val !== selection) {
|
|
|
|
setLoadingStatus([true, 'Saving preferences'])
|
|
|
|
const [status, body] = await backend.updateAccount({
|
|
|
|
compare: val === 'yes' ? true : false,
|
|
|
|
})
|
|
|
|
if (status === 200) {
|
|
|
|
setLoadingStatus([true, 'Preferences saved', true, true])
|
|
|
|
setAccount(body.account)
|
|
|
|
setSelection(val)
|
|
|
|
} else setLoadingStatus([true, 'An error occured. Please report this.', true, true])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link to the next onboarding step
|
|
|
|
const nextHref =
|
|
|
|
welcomeSteps[account?.control].length > 3
|
|
|
|
? '/welcome/' + welcomeSteps[account?.control][4]
|
|
|
|
: '/docs/about/guide'
|
|
|
|
|
|
|
|
return (
|
2025-04-18 08:07:13 +00:00
|
|
|
<div className="tw:w-full">
|
2025-04-01 16:15:20 +02:00
|
|
|
<ListInput
|
|
|
|
id="account-compare"
|
|
|
|
label="Are you comfortable with your measurements sets being compared?"
|
|
|
|
list={['yes', 'no'].map((val) => ({
|
|
|
|
val,
|
|
|
|
label: (
|
2025-04-18 08:07:13 +00:00
|
|
|
<div className="tw:flex tw:flex-row tw:items-center tw:w-full tw:justify-between">
|
2025-04-01 16:15:20 +02:00
|
|
|
<span>{strings[val].title}</span>
|
|
|
|
{val === 'yes' ? (
|
2025-04-18 08:07:13 +00:00
|
|
|
<OkIcon className="tw:w-8 h-8 tw:text-success" stroke={4} />
|
2025-04-01 16:15:20 +02:00
|
|
|
) : (
|
2025-04-18 08:07:13 +00:00
|
|
|
<NoIcon className="tw:w-8 h-8 tw:text-error" stroke={3} />
|
2025-04-01 16:15:20 +02:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
desc: strings[val].desc,
|
|
|
|
}))}
|
|
|
|
current={selection}
|
|
|
|
update={update}
|
|
|
|
/>
|
|
|
|
{welcome ? (
|
|
|
|
<>
|
2025-04-18 08:07:13 +00:00
|
|
|
<IconButton href={nextHref} className="tw:mt-4">
|
2025-04-01 16:15:20 +02:00
|
|
|
<RightIcon stroke={3} /> Continue
|
|
|
|
</IconButton>
|
|
|
|
{welcomeSteps[account?.control].length > 0 ? (
|
|
|
|
<>
|
|
|
|
<progress
|
2025-04-18 08:07:13 +00:00
|
|
|
className="tw:daisy-progress tw:daisy-progress-primary tw:w-full tw:mt-12"
|
2025-04-01 16:15:20 +02:00
|
|
|
value={400 / welcomeSteps[account?.control].length}
|
|
|
|
max="100"
|
|
|
|
></progress>
|
2025-04-18 08:07:13 +00:00
|
|
|
<span className="tw:pt-4 tw:text-sm tw:font-bold tw:opacity-50">
|
2025-04-01 16:15:20 +02:00
|
|
|
4 / {welcomeSteps[account?.control].length}
|
|
|
|
</span>
|
|
|
|
<WelcomeIcons
|
|
|
|
done={welcomeSteps[account?.control].slice(0, 3)}
|
|
|
|
todo={welcomeSteps[account?.control].slice(4)}
|
|
|
|
current="compare"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|