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.
106 lines
3.8 KiB
106 lines
3.8 KiB
import React, { FC, useEffect } from 'react'
|
|
import { useSelector, useDispatch } from 'react-redux'
|
|
import { Link, useParams, useHistory } from 'react-router-dom'
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|
import { faEdit, faUserCheck, faBan } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { handleApiError } from 'src/api/errors'
|
|
import { fetchGroup } from 'src/actions/groups'
|
|
import { getEntity } from 'src/selectors/entities'
|
|
|
|
import { useDeepCompareEffect, useConfig } from 'src/hooks'
|
|
import { setTitle, urlForBlob } from 'src/utils'
|
|
import { AppState, EntityType, Group, GroupMembershipType, AppThunkDispatch } from 'src/types'
|
|
|
|
import PageHeader from 'src/components/page-header'
|
|
import GroupInfo from 'src/components/group-info'
|
|
import Loading from 'src/components/pages/loading'
|
|
|
|
interface Params {
|
|
id: string
|
|
}
|
|
|
|
const ViewGroup: FC = () => {
|
|
const { id } = useParams<Params>()
|
|
const group = useSelector<AppState, Group | undefined>(state => getEntity<Group>(state, EntityType.Group, id))
|
|
const dispatch = useDispatch<AppThunkDispatch>()
|
|
const config = useConfig()
|
|
const history = useHistory()
|
|
|
|
useEffect(() => {
|
|
try {
|
|
dispatch(fetchGroup(id))
|
|
} catch (err) {
|
|
handleApiError(err, dispatch, history)
|
|
}
|
|
}, [])
|
|
|
|
useDeepCompareEffect(() => {
|
|
if (group) setTitle(group.name)
|
|
}, [group])
|
|
|
|
if (!group) return <Loading />
|
|
|
|
const isAdmin = group.membership === GroupMembershipType.Admin
|
|
const imageUrl = group.imageUrl ? urlForBlob(config, group.imageUrl) : undefined
|
|
|
|
return (
|
|
<div>
|
|
<PageHeader title={group.name} />
|
|
|
|
<div className="main-content">
|
|
<GroupInfo group={group} />
|
|
|
|
<div className="centered-content">
|
|
<article className="media">
|
|
{imageUrl &&
|
|
<figure className="media-left">
|
|
<p className="image is-32x32">
|
|
<img src={imageUrl} style={{ width: 128 }} />
|
|
</p>
|
|
</figure>
|
|
}
|
|
<div className="media-content">
|
|
<div className="content">
|
|
<h1 className="is-size-3 has-text-primary">{group.name}</h1>
|
|
<br />
|
|
|
|
<p>{group.about}</p>
|
|
</div>
|
|
</div>
|
|
</article>
|
|
<br />
|
|
|
|
<div className="buttons">
|
|
<Link to={`/c/${group.id}/register`} className="button is-success">
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faUserCheck} />
|
|
</span>
|
|
<span>Create an Account</span>
|
|
</Link>
|
|
|
|
<button className="button is-danger">
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faBan} />
|
|
</span>
|
|
<span>Block</span>
|
|
</button>
|
|
|
|
{isAdmin &&
|
|
<Link to={`/c/${group.id}/admin/`} className="button is-warning">
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faEdit} />
|
|
</span>
|
|
<span>Edit {group.name}</span>
|
|
</Link>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ViewGroup
|