You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
6.4 KiB
163 lines
6.4 KiB
import React, { FC } from 'react'
|
|
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 { unauthenticate } from 'src/actions/authentication'
|
|
import { initForm, initField, setFieldValue } from 'src/actions/forms'
|
|
import { getAuthenticated, getChecked, getAuthenticatedUser } from 'src/selectors/authentication'
|
|
|
|
import { useAuthenticationCheck, useDeepCompareEffect } from 'src/hooks'
|
|
import { setTitle } from 'src/utils'
|
|
import { AppState, User, Tab } 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'
|
|
|
|
interface Params {
|
|
tab: string
|
|
}
|
|
|
|
const tabs: Tab[] = [
|
|
{ id: '', label: 'Posts' },
|
|
{ id: 'settings', label: 'Settings' },
|
|
{ id: 'apps', label: 'Apps' },
|
|
]
|
|
|
|
const Self: FC = () => {
|
|
const { tab = '' } = useParams<Params>()
|
|
const dispatch = useDispatch()
|
|
const history = useHistory()
|
|
|
|
const checked = useSelector<AppState, boolean>(getChecked)
|
|
const authenticated = useSelector<AppState, boolean>(getAuthenticated)
|
|
const user = useSelector<AppState, User | undefined>(getAuthenticatedUser)
|
|
|
|
useAuthenticationCheck(checked, authenticated, history)
|
|
|
|
const handleLogout = () => {
|
|
localStorage.clear()
|
|
dispatch(unauthenticate())
|
|
window.location.href = '/'
|
|
}
|
|
|
|
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))
|
|
}
|
|
}, [user])
|
|
|
|
if (!user) return <Loading />
|
|
|
|
return (
|
|
<div>
|
|
<PageHeader title={user.name || user.id} subtitle={`@${user.id}`} />
|
|
|
|
<div className="main-content">
|
|
<nav className="level">
|
|
<div className="level-item has-text-centered">
|
|
<div>
|
|
<div className="heading">Joined</div>
|
|
<div className="title">{moment(user.created).format('MMMM Do YYYY')}</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div className="centered-content">
|
|
<div className="tabs is-large">
|
|
<ul>
|
|
{tabs.map(t => (
|
|
<li key={t.id} className={tab === t.id ? 'is-active': ''}>
|
|
<Link to={`/self/${t.id}`}>
|
|
{t.label}
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
|
|
<div className="container">
|
|
{tab === '' &&
|
|
<p>No Posts.</p>
|
|
}
|
|
|
|
{tab === 'settings' &&
|
|
<div>
|
|
<div className="field">
|
|
<label className="label">ID</label>
|
|
<div className="control has-icons-left">
|
|
<input className="input" type="text" value={user.id} readOnly />
|
|
<span className="icon is-small is-left">
|
|
<FontAwesomeIcon icon={faIdCard} />
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<br />
|
|
|
|
<div className="field">
|
|
<label className="label">Email</label>
|
|
<div className="control has-icons-left">
|
|
<input className="input" type="email" value={user.email} readOnly />
|
|
<span className="icon is-small is-left">
|
|
<FontAwesomeIcon icon={faEnvelope} />
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<br />
|
|
|
|
<TextField name="name" label="Name" placeholder="Your Display Name" />
|
|
<br />
|
|
|
|
<TextareaField name="about" label="About" placeholder="Your Bio" />
|
|
<br />
|
|
|
|
<button className="button is-primary">
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faCheckCircle} />
|
|
</span>
|
|
<span>Save</span>
|
|
</button>
|
|
|
|
<hr />
|
|
|
|
<button className="button is-danger" onClick={() => handleLogout()}>
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faDoorOpen} />
|
|
</span>
|
|
<span>Log Out</span>
|
|
</button>
|
|
</div>
|
|
}
|
|
|
|
{tab === 'apps' &&
|
|
<div>
|
|
<p>No Apps.</p>
|
|
|
|
<br />
|
|
|
|
<button className="button is-primary">
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faPlusCircle} />
|
|
</span>
|
|
<span>Create a new App</span>
|
|
</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Self
|