import React, { FC, useEffect } from 'react' import { useSelector, useDispatch } from 'react-redux' import { Link, useHistory } from 'react-router-dom' import { faCheckCircle, faStopwatch, faPauseCircle } from '@fortawesome/free-solid-svg-icons' import moment from 'moment' import { useTheme } from '../hooks' import { handleApiError } from '../api/errors' import { fetchInvitations, createInvitation } from '../actions/groups' import { getInvitations } from '../selectors/groups' import { getFieldValue } from '../selectors/forms' import { AppState, AppThunkDispatch } from '../types' import PrimaryButton from '../components/controls/primary-button' import Subtitle from '../components/subtitle' import SelectField from '../components/controls/select-field' interface Props { group: string } const GroupInvitations: FC = ({ group }) => { const theme = useTheme() const invitations = useSelector(getInvitations) const expiration = useSelector(state => getFieldValue(state, 'expiration', '0')) const limit = useSelector(state => getFieldValue(state, 'limit', '0')) const dispatch = useDispatch() const history = useHistory() const handleCreateInvitation = async () => { try { await dispatch(createInvitation(moment().add(expiration, 'day').valueOf(), parseInt(limit, 10))) await dispatch(fetchInvitations()) } catch (err) { handleApiError(err, dispatch, history) } } useEffect(() => { if (invitations.length === 0) { try { dispatch(fetchInvitations()) } catch (err) { handleApiError(err, dispatch, history) } } }, [group]) const expirationOptions = { '0': 'No Expiration', '1': '1 Day', '7': '1 Week', '30': '1 Month', } const limitOptions = { '0': 'No Limit', '1': '1', '5': '5', '20': '20', } return (
Invitations

Create an invitation for someone to create a new account in this Community.

handleCreateInvitation()} />
{invitations.length > 0 && {invitations.map(invitation => ( ))}
Code Created By Uses Limit Expires Created
{invitation.id} {invitation.user.id} {invitation.uses ?? 0} {invitation.limit ?? 'None'} {invitation.expiration ?? 'Never'} {moment(invitation.created).format('MMMM Do YYYY, h:mm:ss a')}
}
) } export default GroupInvitations