import { PageLayout } from '../../components/_shared/PageLayout' import { Icon } from '../../components/_shared/Icon' import ProfileSettingsNavigation from '../../components/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 } from '@solid-primitives/upload' import { Loading } from '../../components/_shared/Loading' import { useSession } from '../../context/session' import { Button } from '../../components/_shared/Button' import { useSnackbar } from '../../context/snackbar' import { useLocalize } from '../../context/localize' import { Image } from '../../components/_shared/Image' import { handleFileUpload } from '../../utils/handleFileUpload' export const ProfileSettingsPage = () => { const { t } = useLocalize() 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 result = await handleFileUpload(uploadFile) updateFormField('userpic', result.url) setIsUserpicUpdating(false) } catch (error) { console.error('[upload avatar] error', error) } }) } const [hostname, setHostname] = createSignal(null) onMount(() => setHostname(window?.location.host)) return (

{t('Profile settings')}

{t('Here you can customize your profile the way you want.')}

{t('Userpic')}

}> {form.name}

{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('Address on Discourse')}

updateFormField('slug', event.currentTarget.value)} value={form.slug} class="nolabel" />

{t(`${slugError()}`)}

{t('Introduce')}