webapp/src/components/Pages/profile/ProfileSettingsPage.tsx

187 lines
7.6 KiB
TypeScript
Raw Normal View History

2022-11-24 21:37:43 +00:00
import { PageWrap } from '../../_shared/PageWrap'
2022-12-01 08:37:04 +00:00
import { t } from '../../../utils/intl'
2022-11-24 21:37:43 +00:00
import type { PageProps } from '../../types'
import { Icon } from '../../_shared/Icon'
import ProfileSettingsNavigation from '../../Discours/ProfileSettingsNavigation'
2022-12-01 17:16:14 +00:00
import { For, createSignal, Show } from 'solid-js'
2022-12-01 08:37:04 +00:00
import { clsx } from 'clsx'
import styles from './Settings.module.scss'
2022-12-01 17:16:14 +00:00
import { useProfileForm } from '../../../context/profile'
2022-12-02 06:12:50 +00:00
import { createFileUploader } from '@solid-primitives/upload'
2022-11-24 21:37:43 +00:00
export const ProfileSettingsPage = (props: PageProps) => {
2022-12-01 17:16:14 +00:00
const [addLinkForm, setAddLinkForm] = createSignal<boolean>(false)
const { form, updateFormField, submit } = useProfileForm()
const handleChangeSocial = (value) => {
updateFormField('links', value)
setAddLinkForm(false)
}
const handleSubmit = (event: Event): void => {
event.preventDefault()
submit(form)
}
2022-12-02 06:12:50 +00:00
const { selectFiles: selectFilesAsync } = createFileUploader({ accept: 'image/*' })
const handleUpload = () => {
selectFilesAsync(async ([{ source, name, size, file }]) => {
try {
console.log({ source, name, size, file })
// DO UPLOAD STUFF HERE AND RETURN URL
} catch (error) {
console.log(error)
}
})
}
2022-11-24 21:37:43 +00:00
return (
<PageWrap>
2022-12-01 17:16:14 +00:00
<Show when={form}>
2022-12-01 08:37:04 +00:00
<div class="wide-container">
<div class="shift-content">
<div class="left-col">
<div class={clsx('left-navigation', styles.leftNavigation)}>
<ProfileSettingsNavigation />
</div>
</div>
2022-12-01 08:37:04 +00:00
<div class="row">
<div class="col-md-10 col-lg-9 col-xl-8">
<h1>{t('Profile settings')}</h1>
<p class="description">{t('Here you can customize your profile the way you want.')}</p>
2022-12-01 17:16:14 +00:00
<form onSubmit={handleSubmit}>
2022-12-01 08:37:04 +00:00
<h4>{t('Userpic')}</h4>
<div class="pretty-form__item">
<div class={styles.avatarContainer}>
2022-12-01 17:16:14 +00:00
<img class={styles.avatar} src={form.userpic} alt={form.name} />
2022-12-02 06:12:50 +00:00
<button type="button" class={styles.avatarInput} onClick={handleUpload} />
2022-12-01 08:37:04 +00:00
</div>
</div>
<h4>{t('Name')}</h4>
<p class="description">
{t(
'Your name will appear on your profile page and as your signature in publications, comments and responses.'
)}
</p>
<div class="pretty-form__item">
2022-11-24 21:37:43 +00:00
<input
2022-12-01 08:37:04 +00:00
type="text"
name="username"
id="username"
2022-12-01 17:16:14 +00:00
placeholder={t('Name')}
onChange={(event) => updateFormField('name', event.currentTarget.value)}
value={form.name}
2022-11-24 21:37:43 +00:00
/>
2022-12-02 06:40:26 +00:00
<label for="username">{t('Name')}</label>
2022-11-24 21:37:43 +00:00
</div>
2022-12-02 06:40:26 +00:00
<h4>{t('Address on Discourse')}</h4>
<div class="pretty-form__item">
<div class={styles.discoursName}>
<label for="user-address">https://new.discours.io/author/</label>
<div class={styles.discoursNameField}>
<input
type="text"
name="user-address"
id="user-address"
onChange={(event) => updateFormField('slug', event.currentTarget.value)}
value={form.slug}
class="nolabel"
/>
<p class="form-message form-message--error">
{t('Sorry, this address is already taken, please choose another one.')}
</p>
</div>
</div>
</div>
<h4>{t('Introduce')}</h4>
<div class="pretty-form__item">
<textarea name="presentation" id="presentation" placeholder={t('Introduce')}>
{form.bio}
</textarea>
<label for="presentation">{t('Introduce')}</label>
</div>
2022-11-24 21:37:43 +00:00
2022-12-01 08:37:04 +00:00
<h4>{t('About myself')}</h4>
<div class="pretty-form__item">
2022-12-01 17:16:14 +00:00
<textarea
name="about"
id="about"
placeholder={t('About myself')}
2022-12-02 06:40:26 +00:00
value={form.about}
onChange={(event) => updateFormField('about', event.currentTarget.value)}
2022-12-01 17:16:14 +00:00
/>
2022-12-01 08:37:04 +00:00
<label for="about">{t('About myself')}</label>
</div>
2022-11-24 21:37:43 +00:00
2022-12-01 17:16:14 +00:00
{/*Нет реализации полей на бэке*/}
{/*<h4>{t('How can I help/skills')}</h4>*/}
{/*<div class="pretty-form__item">*/}
{/* <input type="text" name="skills" id="skills" />*/}
{/*</div>*/}
{/*<h4>{t('Where')}</h4>*/}
{/*<div class="pretty-form__item">*/}
{/* <input type="text" name="location" id="location" placeholder="Откуда" />*/}
{/* <label for="location">{t('Where')}</label>*/}
{/*</div>*/}
2022-12-01 08:37:04 +00:00
2022-12-01 17:16:14 +00:00
{/*<h4>{t('Date of Birth')}</h4>*/}
{/*<div class="pretty-form__item">*/}
{/* <input*/}
{/* type="date"*/}
{/* name="birthdate"*/}
{/* id="birthdate"*/}
{/* placeholder="Дата рождения"*/}
{/* class="nolabel"*/}
{/* />*/}
{/*</div>*/}
2022-12-01 08:37:04 +00:00
<div class={clsx(styles.multipleControls, 'pretty-form__item')}>
<div class={styles.multipleControlsHeader}>
<h4>{t('Social networks')}</h4>
2022-12-01 17:16:14 +00:00
<button type="button" class="button" onClick={() => setAddLinkForm(!addLinkForm())}>
+
</button>
2022-12-01 08:37:04 +00:00
</div>
2022-12-01 17:16:14 +00:00
<Show when={addLinkForm()}>
<div class={styles.multipleControlsItem}>
<input
autofocus={true}
type="text"
name="link"
class="nolabel"
onChange={(event) => handleChangeSocial(event.currentTarget.value)}
/>
</div>
</Show>
<For each={form.links}>
2022-12-01 08:37:04 +00:00
{(link) => (
<div class={styles.multipleControlsItem}>
2022-12-01 17:16:14 +00:00
<input type="text" value={link} readonly={true} name="link" class="nolabel" />
<button type="button" onClick={() => updateFormField('links', link, true)}>
2022-12-01 08:37:04 +00:00
<Icon name="remove" class={styles.icon} />
</button>
</div>
)}
</For>
2022-11-24 21:37:43 +00:00
</div>
2022-12-01 08:37:04 +00:00
<br />
<p>
2022-12-01 17:16:14 +00:00
<button type="submit" class="button button--submit">
{t('Save settings')}
</button>
2022-12-01 08:37:04 +00:00
</p>
</form>
</div>
2022-11-24 21:37:43 +00:00
</div>
</div>
2022-12-01 17:16:14 +00:00
<pre>{JSON.stringify(form, null, 2)}</pre>
2022-11-24 21:37:43 +00:00
</div>
2022-12-01 08:37:04 +00:00
</Show>
2022-11-24 21:37:43 +00:00
</PageWrap>
)
}
// for lazy loading
export default ProfileSettingsPage