// group-invitations.tsx // Copyright (C) 2020 Dwayne Harris // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . 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