From 8184e5a9978deb1826a904d01ecbc55ee6feb537 Mon Sep 17 00:00:00 2001
From: eznarf <41272412+eznarf@users.noreply.github.com>
Date: Sun, 5 Nov 2023 17:21:14 -0800
Subject: [PATCH] Cleaning up sections, removing top paper component
---
.../components/Election/Admin/AdminHome.tsx | 408 ++++++++----------
1 file changed, 173 insertions(+), 235 deletions(-)
diff --git a/frontend/src/components/Election/Admin/AdminHome.tsx b/frontend/src/components/Election/Admin/AdminHome.tsx
index 422c6246..3becbfd2 100644
--- a/frontend/src/components/Election/Admin/AdminHome.tsx
+++ b/frontend/src/components/Election/Admin/AdminHome.tsx
@@ -27,7 +27,7 @@ const Section = ({ Description, Button }: SectionProps) => {
return (
<>
-
+
{Description}
@@ -39,7 +39,7 @@ const Section = ({ Description, Button }: SectionProps) => {
}
const EditRolesSection = ({ election, permissions }: { election: Election, permissions: string[] }) => {
- if(process.env.REACT_APP_FF_METHOD_PLURALITY !== 'true') return <>>;
+ if (process.env.REACT_APP_FF_METHOD_PLURALITY !== 'true') return <>>;
return
@@ -129,48 +129,15 @@ const EditElectionSection = ({ election, permissions }: { election: Election, pe
/>
}
-const AddVotersSection = ({ election, permissions }: { election: Election, permissions: string[] }) => {
+const VotersSection = ({ election, permissions }: { election: Election, permissions: string[] }) => {
return
- Add voters to your election
+ {election.state === 'draft' ? 'Add voters to your election' : 'View voters'}
- Add voters who are approved to vote in your election
-
-
- Voter access must be set to closed
-
- {!hasPermission(permissions, 'canViewElectionRoll') &&
-
- You do not have the correct permissions for this action
-
- }
- >)}
- Button={(<>
-
-
- Add voters
-
-
-
- >)}
- />
-}
-
-const ViewVotersSection = ({ election, permissions }: { election: Election, permissions: string[] }) => {
- return
-
- View Voters
+ {election.state === 'draft' ? 'Add voters who are approved to vote in your election' : 'View the status of your voters'}
{!hasPermission(permissions, 'canViewElectionRoll') &&
@@ -187,7 +154,7 @@ const ViewVotersSection = ({ election, permissions }: { election: Election, perm
component={Link} to={`/Election/${election.election_id}/admin/voters`}
>
- View voters
+ {election.state === 'draft' ? 'Add voters' : 'View voters'}
@@ -356,6 +323,124 @@ const ShareSection = ({ election, permissions }: { election: Election, permissio
/>
}
+const HeaderSection = ({ election, permissions }: { election: Election, permissions: string[] }) => {
+ return (
+ <>
+ {election.state === 'finalized' &&
+ <>
+
+
+ Your election is finalized
+
+
+ {election.settings.invitation &&
+
+
+ Invitations have been sent to your voters
+
+
+ }
+ {election.start_time &&
+
+
+ {`Your election will open on ${formatDate(election.start_time, election.settings.time_zone)}`}
+
+ }
+ >
+ }
+ {election.state === 'open' &&
+ <>
+
+
+ Your election is open
+
+
+ {election.settings.invitation &&
+
+
+ Invitations have been sent to your voters
+
+
+ }
+ {election.end_time &&
+
+
+ {`Your election will end on ${formatDate(election.end_time, election.settings.time_zone)}`}
+
+ }
+ >
+ }
+ {election.state === 'closed' &&
+ <>
+
+
+ Your election is closed
+
+
+ {election.end_time &&
+
+
+ {`Your election ended on ${formatDate(election.end_time, election.settings.time_zone)}`}
+
+ }
+ >
+ }
+ {election.state === 'archived' &&
+ <>
+
+
+ This election has been archived
+
+
+ {election.end_time &&
+
+
+ {`Your election ended on ${formatDate(election.end_time, election.settings.time_zone)}`}
+
+ }
+ >
+ }
+
+
+ >)
+}
+
+const FinalizeSection = ({ election, permissions, finalizeElection }: { election: Election, permissions: string[], finalizeElection: Function }) => {
+ return (
+ <>
+
+
+ {/* {`If you're finished setting up your election you can finalize it. This will prevent future edits ${election.settings.invitation ? ', send out invitations, ' : ''} and open the election for voters to submit ballots${election.start_time ? ' after your specified start time' : ''}.`} */}
+ {`When finished setting up your election, finalize it. Once final, it can't be edited. Voting begins ${election.start_time ? 'after your specified start time.' : 'immediately.'}`}
+
+ {election.settings.invitation &&
+
+ Invitations will be sent to your voters
+
+ }
+ {!hasPermission(permissions, 'canEditElectionState') &&
+
+ You do not have the correct permissions for this action
+
+ }
+
+
+ finalizeElection()}
+ >
+
+ Finalize Election
+
+
+
+ >)
+}
+
+
const AdminHome = () => {
const { election, refreshElection: fetchElection, permissions } = useElection()
const { makeRequest } = useSetPublicResults(election.election_id)
@@ -371,9 +456,9 @@ const AdminHome = () => {
const finalizeElection = async () => {
console.log("finalizing election")
-const confirmed = await confirm(
+ const confirmed = await confirm(
{
- title: 'Confirm Finalize Election',
+ title: 'Confirm Finalize Election',
message: "Are you sure you want to finalize your election? Once finalized you won't be able to edit it."
})
if (!confirmed) return
@@ -389,17 +474,17 @@ const confirmed = await confirm(
console.log("archiving election")
const confirmed = await confirm(
{
- title: 'Confirm Archive Election',
+ title: 'Confirm Archive Election',
message: "Are you sure you wish to archive this election? This action cannot be undone."
})
if (!confirmed) return
- console.log('confirmed')
- try {
- await archive()
- await fetchElection()
- } catch (err) {
- console.log(err)
- }
+ console.log('confirmed')
+ try {
+ await archive()
+ await fetchElection()
+ } catch (err) {
+ console.log(err)
+ }
}
return (
@@ -408,195 +493,48 @@ const confirmed = await confirm(
justifyContent="center"
alignItems="center"
sx={{ width: '100%' }}>
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {(election.settings.voter_access === 'closed' || election.state !== 'draft') && <>
+
+
+ >}
+ {(election.state !== 'draft' && election.state !== 'finalized') && <>
+
+
+
+
+
+
+
+
+ >}
+
+
+
+
+
+
+ {election.state === 'draft' &&
-
+
+
- {election.state === 'draft' &&
- <>
-
-
-
-
-
-
- {/*
- */}
-
-
-
-
-
-
- {/* {`If you're finished setting up your election you can finalize it. This will prevent future edits ${election.settings.invitation ? ', send out invitations, ' : ''} and open the election for voters to submit ballots${election.start_time ? ' after your specified start time' : ''}.`} */}
- {`When finished setting up your election, finalize it. Once final, it can't be edited. Voting begins ${election.start_time ? 'after your specified start time.' : 'immediately.'}`}
-
- {election.settings.invitation &&
-
- Invitations will be sent to your voters
-
- }
- {!hasPermission(permissions, 'canEditElectionState') &&
-
- You do not have the correct permissions for this action
-
- }
-
-
- finalizeElection()}
- >
-
- Finalize Election
-
-
-
-
- >
- }
- {election.state === 'finalized' &&
- <>
-
-
- Your election is finalized
-
-
- {election.settings.invitation &&
-
-
- Invitations have been sent to your voters
-
-
- }
- {election.start_time &&
-
-
- {`Your election will open on ${formatDate(election.start_time, election.settings.time_zone)}`}
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
- >
-
- }
-
- {election.state === 'open' &&
- <>
-
-
- Your election is open
-
-
- {election.settings.invitation &&
-
-
- Invitations have been sent to your voters
-
-
- }
- {election.end_time &&
-
-
- {`Your election will end on ${formatDate(election.end_time, election.settings.time_zone)}`}
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- >
- }
- {election.state === 'closed' &&
- <>
-
-
- Your election is closed
-
-
- {election.end_time &&
-
-
- {`Your election ended on ${formatDate(election.end_time, election.settings.time_zone)}`}
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- >
- }
- {election.state === 'archived' &&
- <>
-
-
- This election has been archived
-
-
- {election.end_time &&
-
-
- {`Your election ended on ${formatDate(election.end_time, election.settings.time_zone)}`}
-
- }
-
-
-
-
-
-
-
-
-
- >
- }
-
-
+ }
+
)
}