Skip to content

Commit

Permalink
Merge pull request #386 from mikefranze/disable-email-buttons
Browse files Browse the repository at this point in the history
Disable email buttons when not supported
  • Loading branch information
mikefranze authored Nov 21, 2023
2 parents 68d560e + ff690ca commit 3262a9d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
9 changes: 5 additions & 4 deletions frontend/src/components/Election/Admin/AddElectionRoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import Container from '@mui/material/Container';
import Box from '@mui/material/Box';
import { Checkbox, FormGroup, FormControlLabel } from '@mui/material';
import { usePostRolls } from "../../../hooks/useAPI";
import useElection from "../../ElectionContextProvider";


const AddElectionRoll = ({ election, onClose }) => {

const AddElectionRoll = ({ onClose }) => {
const { election } = useElection()
const [voterIDList, setVoterIDList] = useState('')
const postRoll = usePostRolls(election.election_id)
const [file, setFile] = useState()
const fileReader = new FileReader()
const [enableVoterID, setEnableVoterID] = useState(false)
const [enableEmail, setEnableEmail] = useState(true)
const [enableVoterID, setEnableVoterID] = useState(election.settings.voter_authentication.voter_id && election.settings.invitation !== 'email')
const [enableEmail, setEnableEmail] = useState(election.settings.voter_authentication.email || election.settings.invitation === 'email')
const [enablePrecinct, setEnablePrecinct] = useState(false)
const inputRef = useRef(null)

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Election/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Admin = ({ authSession, election, permissions, fetchElection }) => {
<Container>
<Routes>
<Route path='/' element={<AdminHome authSession={authSession}/>} />
<Route path='/voters' element={<ViewElectionRolls election={election} permissions={permissions} />} />
<Route path='/voters' element={<ViewElectionRolls />} />
<Route path='/roles' element={<EditRoles election={election} permissions={permissions} fetchElection={fetchElection} />} />
<Route path='/ballots' element={<ViewBallots election={election} permissions={permissions} />} />
</Routes>
Expand Down
24 changes: 15 additions & 9 deletions frontend/src/components/Election/Admin/EditElectionRoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import { Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow
import PermissionHandler from "../../PermissionHandler";
import { useApproveRoll, useFlagRoll, useInvalidateRoll, useSendInvite, useUnflagRoll } from "../../../hooks/useAPI";
import { formatDate } from "../../util";

const EditElectionRoll = ({ roll, onClose, fetchRolls, id, permissions }) => {
import useElection from "../../ElectionContextProvider";
import { ElectionRoll } from "../../../../../domain_model/ElectionRoll";
type Props = {
roll: ElectionRoll,
onClose: Function,
fetchRolls: Function,
}
const EditElectionRoll = ({ roll, onClose, fetchRolls }:Props) => {
const { election, permissions } = useElection()
const [updatedRoll, setUpdatedRoll] = useState(roll)

const approve = useApproveRoll(id)
const flag = useFlagRoll(id)
const unflag = useUnflagRoll(id)
const invalidate = useInvalidateRoll(id)
const sendInvite = useSendInvite(id, roll.voter_id)
const approve = useApproveRoll(election.election_id)
const flag = useFlagRoll(election.election_id)
const unflag = useUnflagRoll(election.election_id)
const invalidate = useInvalidateRoll(election.election_id)
const sendInvite = useSendInvite(election.election_id, roll.voter_id)

const onApprove = async () => {
if (!await approve.makeRequest({ electionRollEntry: roll })) { return }
Expand All @@ -39,7 +46,6 @@ const EditElectionRoll = ({ roll, onClose, fetchRolls, id, permissions }) => {

await fetchRolls()
}

return (
<Container>
{(approve.isPending || flag.isPending || unflag.isPending || invalidate.isPending) &&
Expand Down Expand Up @@ -69,7 +75,7 @@ const EditElectionRoll = ({ roll, onClose, fetchRolls, id, permissions }) => {
</Typography>
</Grid>

{roll.email &&
{election.settings.invitation === 'email' && roll.email &&
<>
{roll && !(roll.email_data && roll.email_data.inviteResponse) &&
<Grid item sm={12}>
Expand Down
45 changes: 27 additions & 18 deletions frontend/src/components/Election/Admin/ViewElectionRolls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import PermissionHandler from "../../PermissionHandler";
import { Typography } from "@mui/material";
import EnhancedTable, { HeadCell, TableData } from "./../../EnhancedTable";
import { useGetRolls, useSendInvites } from "../../../hooks/useAPI";
import useElection from "../../ElectionContextProvider";
import { ElectionRoll } from "../../../../../domain_model/ElectionRoll";

interface Data extends TableData {
voter_id: string;
Expand All @@ -20,13 +22,14 @@ interface Data extends TableData {
state: string;
}

const ViewElectionRolls = ({ election, permissions }) => {
const ViewElectionRolls = () => {
const { election, permissions } = useElection()
const { data, isPending, error, makeRequest: fetchRolls } = useGetRolls(election.election_id)
const sendInvites = useSendInvites(election.election_id)
useEffect(() => { fetchRolls() }, [])
const [isEditing, setIsEditing] = useState(false)
const [addRollPage, setAddRollPage] = useState(false)
const [editedRoll, setEditedRoll] = useState(null)
const [editedRoll, setEditedRoll] = useState<ElectionRoll|null>(null)

const onOpen = (voter) => {
setIsEditing(true)
Expand Down Expand Up @@ -108,13 +111,13 @@ const ViewElectionRolls = ({ election, permissions }) => {
},
];

if(process.env.REACT_APP_FF_PRECINCTS === 'true'){
if (process.env.REACT_APP_FF_PRECINCTS === 'true') {
headCells.push({
id: 'precinct',
numeric: false,
disablePadding: false,
label: 'Precinct',
filterType: 'search'
id: 'precinct',
numeric: false,
disablePadding: false,
label: 'Precinct',
filterType: 'search'
});
}

Expand Down Expand Up @@ -158,11 +161,15 @@ const ViewElectionRolls = ({ election, permissions }) => {
{isPending && <div> Loading Data... </div>}
{data && data.electionRoll && !isEditing && !addRollPage &&
<>
<PermissionHandler permissions={permissions} requiredPermission={'canAddToElectionRoll'}>
<Button variant='outlined' onClick={() => setAddRollPage(true)} > Add Voters </Button>
</PermissionHandler>
<Button variant='outlined' onClick={() => onSendInvites()} > Send Invites </Button>
{tableData.length == 0 && <p>This election doesn't have any voters on the roll yet</p>}
{election.settings.voter_access === 'closed' &&
<PermissionHandler permissions={permissions} requiredPermission={'canAddToElectionRoll'}>
<Button variant='outlined' onClick={() => setAddRollPage(true)} > Add Voters </Button>
</PermissionHandler>
}
{election.settings.invitation === 'email' &&
< Button variant='outlined' onClick={() => onSendInvites()} > Send Invites </Button>
}
{tableData.length == 0 && <p>This election doesn't have any voters yet</p>}
{tableData.length > 0 &&
<EnhancedTable
headCells={headCells}
Expand All @@ -174,13 +181,15 @@ const ViewElectionRolls = ({ election, permissions }) => {
}
</>
}
{isEditing && editedRoll &&
<EditElectionRoll roll={editedRoll} onClose={onClose} fetchRolls={onUpdate} id={election.election_id} permissions={permissions} />
{
isEditing && editedRoll &&
<EditElectionRoll roll={editedRoll} onClose={onClose} fetchRolls={onUpdate}/>
}
{addRollPage &&
<AddElectionRoll election={election} onClose={onClose} />
{
addRollPage &&
<AddElectionRoll onClose={onClose} />
}
</Container>
</Container >
)
}

Expand Down

0 comments on commit 3262a9d

Please sign in to comment.