|
|
@ -3,20 +3,25 @@ import { useSelector, useDispatch } from 'react-redux' |
|
|
|
import { Link, useParams, useHistory } from 'react-router-dom' |
|
|
|
import moment from 'moment' |
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' |
|
|
|
import { faDoorOpen, faCheckCircle, faPlusCircle, faIdCard, faEnvelope } from '@fortawesome/free-solid-svg-icons' |
|
|
|
import { faDoorOpen, faCheckCircle, faPlusCircle, faIdCard, faEnvelope, faUserShield } from '@fortawesome/free-solid-svg-icons' |
|
|
|
|
|
|
|
import { unauthenticate } from 'src/actions/authentication' |
|
|
|
import { initForm, initField, setFieldValue } from 'src/actions/forms' |
|
|
|
import { unauthenticate, updateSelf } from 'src/actions/authentication' |
|
|
|
import { initForm, initField } from 'src/actions/forms' |
|
|
|
import { getAuthenticated, getChecked, getAuthenticatedUser } from 'src/selectors/authentication' |
|
|
|
import { getForm } from 'src/selectors/forms' |
|
|
|
|
|
|
|
import { handleApiError } from 'src/api/errors' |
|
|
|
import { PRIVACY_OPTIONS } from 'src/constants' |
|
|
|
import { useAuthenticationCheck, useDeepCompareEffect } from 'src/hooks' |
|
|
|
import { setTitle } from 'src/utils' |
|
|
|
import { AppState, User, Tab } from 'src/types' |
|
|
|
import { setTitle, valueFromForm } from 'src/utils' |
|
|
|
import { AppState, User, Tab, Form } from 'src/types' |
|
|
|
|
|
|
|
import PageHeader from 'src/components/page-header' |
|
|
|
import Loading from 'src/components/pages/loading' |
|
|
|
import TextField from 'src/components/forms/text-field' |
|
|
|
import TextareaField from 'src/components/forms/textarea-field' |
|
|
|
import SelectField from 'src/components/forms/select-field' |
|
|
|
import CheckboxField from 'src/components/forms/checkbox-field' |
|
|
|
|
|
|
|
interface Params { |
|
|
|
tab: string |
|
|
@ -36,6 +41,7 @@ const Self: FC = () => { |
|
|
|
const checked = useSelector<AppState, boolean>(getChecked) |
|
|
|
const authenticated = useSelector<AppState, boolean>(getAuthenticated) |
|
|
|
const user = useSelector<AppState, User | undefined>(getAuthenticatedUser) |
|
|
|
const form = useSelector<AppState, Form>(getForm) |
|
|
|
|
|
|
|
useAuthenticationCheck(checked, authenticated, history) |
|
|
|
|
|
|
@ -45,15 +51,28 @@ const Self: FC = () => { |
|
|
|
window.location.href = '/' |
|
|
|
} |
|
|
|
|
|
|
|
const handleUpdate = () => { |
|
|
|
const name = valueFromForm<string>(form, 'name', '') |
|
|
|
const about = valueFromForm<string>(form, 'about', '') |
|
|
|
const requiresApproval = valueFromForm<boolean>(form, 'requiresApproval', true) |
|
|
|
const privacy = valueFromForm<string>(form, 'privacy', 'public') |
|
|
|
|
|
|
|
try { |
|
|
|
dispatch(updateSelf(name, about, requiresApproval, privacy)) |
|
|
|
} catch (err) { |
|
|
|
handleApiError(err, dispatch, history) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
useDeepCompareEffect(() => { |
|
|
|
if (user) { |
|
|
|
setTitle(`${user.name} (@${user.id})`) |
|
|
|
|
|
|
|
dispatch(initForm()) |
|
|
|
dispatch(initField('name')) |
|
|
|
dispatch(initField('about')) |
|
|
|
dispatch(setFieldValue('name', user.name as string)) |
|
|
|
dispatch(setFieldValue('about', user.about as string)) |
|
|
|
dispatch(initField('name', user.name)) |
|
|
|
dispatch(initField('about', user.about || '')) |
|
|
|
dispatch(initField('requiresApproval', user.requiresApproval)) |
|
|
|
dispatch(initField('privacy', user.privacy)) |
|
|
|
} |
|
|
|
}, [user]) |
|
|
|
|
|
|
@ -117,11 +136,16 @@ const Self: FC = () => { |
|
|
|
|
|
|
|
<TextField name="name" label="Name" placeholder="Your Display Name" /> |
|
|
|
<br /> |
|
|
|
|
|
|
|
<TextareaField name="about" label="About" placeholder="Your Bio" /> |
|
|
|
<br /> |
|
|
|
<SelectField name="privacy" label="Privacy" options={PRIVACY_OPTIONS} icon={faUserShield} /> |
|
|
|
<br /> |
|
|
|
<CheckboxField name="requiresApproval"> |
|
|
|
You must approve each Subscription request from other users. |
|
|
|
</CheckboxField> |
|
|
|
<br /><br /> |
|
|
|
|
|
|
|
<button className="button is-primary"> |
|
|
|
<button className="button is-primary" onClick={() => handleUpdate()}> |
|
|
|
<span className="icon is-small"> |
|
|
|
<FontAwesomeIcon icon={faCheckCircle} /> |
|
|
|
</span> |
|
|
@ -145,12 +169,12 @@ const Self: FC = () => { |
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|
<button className="button is-primary"> |
|
|
|
<Link to="/developers/create" className="button is-primary"> |
|
|
|
<span className="icon is-small"> |
|
|
|
<FontAwesomeIcon icon={faPlusCircle} /> |
|
|
|
</span> |
|
|
|
<span>Create a new App</span> |
|
|
|
</button> |
|
|
|
</Link> |
|
|
|
</div> |
|
|
|
} |
|
|
|
</div> |
|
|
|