import { PageWrap } from '../../_shared/PageWrap' import { t } from '../../../utils/intl' import { Icon } from '../../_shared/Icon' import ProfileSettingsNavigation from '../../Discours/ProfileSettingsNavigation' import { For, createSignal, Show, onMount } from 'solid-js' import { clsx } from 'clsx' import styles from './Settings.module.scss' import { useProfileForm } from '../../../context/profile' import validateUrl from '../../../utils/validateUrl' import { createFileUploader, UploadFile } from '@solid-primitives/upload' import { Loading } from '../../Loading' import { useSession } from '../../../context/session' import Button from '../../_shared/Button' import { useSnackbar } from '../../../context/snackbar' const handleFileUpload = async (uploadFile: UploadFile) => { const formData = new FormData() formData.append('file', uploadFile.file, uploadFile.name) const response = await fetch('/api/upload', { method: 'POST', body: formData }) return response.json() } export const ProfileSettingsPage = () => { const [addLinkForm, setAddLinkForm] = createSignal(false) const [incorrectUrl, setIncorrectUrl] = createSignal(false) const [isSubmitting, setIsSubmitting] = createSignal(false) const [isUserpicUpdating, setIsUserpicUpdating] = createSignal(false) const { actions: { showSnackbar } } = useSnackbar() const { actions: { loadSession } } = useSession() const { form, updateFormField, submit, slugError } = useProfileForm() const handleChangeSocial = (value: string) => { if (validateUrl(value)) { updateFormField('links', value) setAddLinkForm(false) } else { setIncorrectUrl(true) } } const handleSubmit = async (event: Event) => { event.preventDefault() setIsSubmitting(true) try { await submit(form) showSnackbar({ body: ` ${t('Profile successfully saved')}` }) } catch { showSnackbar({ type: 'error', body: t('Error') }) } loadSession() setIsSubmitting(false) } const { selectFiles } = createFileUploader({ multiple: false, accept: 'image/*' }) const handleAvatarClick = async () => { await selectFiles(async ([uploadFile]) => { try { setIsUserpicUpdating(true) const fileUrl = await handleFileUpload(uploadFile) updateFormField('userpic', fileUrl) setIsUserpicUpdating(false) } catch (error) { console.error('[upload avatar] error', error) } }) } const [hostname, setHostname] = createSignal('new.discours.io') onMount(() => setHostname(window?.location.host)) return ( {t('Profile settings')} {t('Here you can customize your profile the way you want.')} {t('Userpic')} }> {t('Name')} {t( 'Your name will appear on your profile page and as your signature in publications, comments and responses.' )} updateFormField('name', event.currentTarget.value)} value={form.name} /> {t('Name')} {t('Address on Discourse')} https://{hostname()}/author/ updateFormField('slug', event.currentTarget.value)} value={form.slug} class="nolabel" /> {t(`${slugError()}`)} {t('Introduce')} {form.bio} {t('Introduce')} {t('About myself')} updateFormField('about', event.currentTarget.value)} /> {t('About myself')} {/*Нет реализации полей на бэке*/} {/*{t('How can I help/skills')}*/} {/**/} {/* */} {/**/} {/*{t('Where')}*/} {/**/} {/* */} {/* {t('Where')}*/} {/**/} {/*{t('Date of Birth')}*/} {/**/} {/* */} {/**/} {t('Social networks')} setAddLinkForm(!addLinkForm())}> + handleChangeSocial(event.currentTarget.value)} /> {t('It does not look like url')} {(link) => ( updateFormField('links', link, true)}> )} ) } // for lazy loading export default ProfileSettingsPage
{t('Here you can customize your profile the way you want.')}
{t( 'Your name will appear on your profile page and as your signature in publications, comments and responses.' )}
{t(`${slugError()}`)}
{t('It does not look like url')}