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
|
|
|
|
import { Link as WebLink } from '@freesewing/react/components/Link'
|
|
|
|
import { SaveIcon, RightIcon } from '@freesewing/react/components/Icon'
|
|
|
|
import { MarkdownInput } from '@freesewing/react/components/Input'
|
|
|
|
import { IconButton } from '@freesewing/react/components/Button'
|
|
|
|
import { WelcomeIcons } from './shared.mjs'
|
|
|
|
|
2025-05-09 17:46:51 +02:00
|
|
|
/**
|
|
|
|
* Component to manage the user's Bio
|
2025-04-01 16:15:20 +02:00
|
|
|
*
|
2025-05-09 17:46:51 +02:00
|
|
|
* @component
|
|
|
|
* @param {object} props - All component props
|
|
|
|
* @param {boolean} [props.welcome = false] - Set to true to render the welcome/onboarding flow
|
|
|
|
* @param {React.Component} props.Link - A framework specific Link component for client-side routing
|
|
|
|
* @returns {JSX.Element}
|
2025-04-01 16:15:20 +02:00
|
|
|
*/
|
|
|
|
export const Bio = ({ welcome = false, Link = false }) => {
|
|
|
|
if (!Link) Link = WebLink
|
|
|
|
|
|
|
|
// Hooks
|
|
|
|
const { account, setAccount } = useAccount()
|
|
|
|
const backend = useBackend()
|
|
|
|
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
|
|
|
|
|
|
|
// State
|
|
|
|
const [bio, setBio] = useState(account.bio)
|
|
|
|
|
|
|
|
// Helper method to save bio
|
|
|
|
const save = async () => {
|
|
|
|
setLoadingStatus([true, 'Saving bio'])
|
|
|
|
const [status, body] = await backend.updateAccount({ bio })
|
|
|
|
if (status === 200 && body.result === 'success') {
|
|
|
|
setAccount(body.account)
|
|
|
|
setLoadingStatus([true, 'Bio updated', true, true])
|
|
|
|
} else setLoadingStatus([true, 'Something went wrong. Please report this', true, true])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next step in the onboarding
|
|
|
|
const nextHref =
|
|
|
|
welcomeSteps[account.control].length > 5
|
|
|
|
? '/welcome/' + welcomeSteps[account.control][6]
|
|
|
|
: '/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
|
|
|
<h6>Tell people a little bit about yourself.</h6>
|
|
|
|
<MarkdownInput id="account-bio" label="Bio" update={setBio} current={bio} placeholder="Bio" />
|
2025-04-18 08:07:13 +00:00
|
|
|
<p className="tw:text-right">
|
2025-04-01 16:15:20 +02:00
|
|
|
<button
|
2025-04-18 08:07:13 +00:00
|
|
|
className="tw:daisy-btn tw:daisy-btn-primary tw:w-full tw:lg:w-auto tw:mt-8"
|
2025-04-01 16:15:20 +02:00
|
|
|
onClick={save}
|
|
|
|
>
|
|
|
|
<SaveIcon /> Save Bio
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
{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={600 / 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
|
|
|
6 / {welcomeSteps[account.control].length}
|
|
|
|
</span>
|
|
|
|
<WelcomeIcons
|
|
|
|
done={welcomeSteps[account.control].slice(0, 5)}
|
|
|
|
todo={welcomeSteps[account.control].slice(6)}
|
|
|
|
current="bio"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|