Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161,482 changes: 0 additions & 161,482 deletions packages/admin-portal/graphql.schema.json

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions packages/voting-portal/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
selectBallotStyleElectionIds,
selectFirstBallotStyle,
} from "./store/ballotStyles/ballotStylesSlice"
import {selectElectionEventById} from "./store/electionEvents/electionEventsSlice"
import WatermarkBackground from "./components/WaterMark/Watermark"
import SequentLogo from "@sequentech/ui-essentials/public/Sequent_logo.svg"
import BlankLogoImg from "@sequentech/ui-essentials/public/blank_logo.svg"
Expand Down Expand Up @@ -72,15 +71,11 @@ const StyledMain = styled(`main`)`
const HeaderWithContext: React.FC = () => {
const authContext = useContext(AuthContext)
const {globalSettings} = useContext(SettingsContext)
const {eventId} = useParams<TenantEventType>()

const ballotStyle = useAppSelector(selectFirstBallotStyle)
const electionEvent = useAppSelector(selectElectionEventById(eventId))

let presentation: IElectionEventPresentation | undefined =
ballotStyle?.ballot_eml.election_event_presentation ??
electionEvent?.presentation ??
undefined
ballotStyle?.ballot_eml.election_event_presentation ?? undefined

let languagesList = presentation?.language_conf?.enabled_language_codes ?? ["en"]
let showUserProfile = presentation?.show_user_profile ?? true
Expand Down
16 changes: 6 additions & 10 deletions packages/voting-portal/src/hooks/useUpdateTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// SPDX-License-Identifier: AGPL-3.0-only

import React, {useContext, useEffect} from "react"
import {IElectionEvent} from "../store/electionEvents/electionEventsSlice"
import {overwriteTranslations} from "@sequentech/ui-core"
import {IElectionEventPresentation, overwriteTranslations} from "@sequentech/ui-core"

type props = {
electionEvent: IElectionEvent | undefined
presentation: IElectionEventPresentation | undefined
}
const useUpdateTranslation = (
{electionEvent}: props,
{presentation}: props,
defaultLanguageTouched: boolean,
setDefaultLanguageTouched: (value: boolean) => void
) => {
Expand All @@ -19,17 +18,14 @@ const useUpdateTranslation = (
// So search param "lang" > user selected locale (saved in cookie) >
// language detection policy (force default) > browser settings
useEffect(() => {
if (!electionEvent?.presentation) {
if (!presentation) {
return
}
let hasSetDefaultLanguage = overwriteTranslations(
electionEvent?.presentation,
!defaultLanguageTouched
)
let hasSetDefaultLanguage = overwriteTranslations(presentation, !defaultLanguageTouched)
if (hasSetDefaultLanguage) {
setDefaultLanguageTouched(true)
}
}, [electionEvent?.presentation])
}, [presentation])

return {}
}
Expand Down
1 change: 0 additions & 1 deletion packages/voting-portal/src/queries/GetElectionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const GET_ELECTION_EVENT = gql`
where: {_and: {id: {_eq: $electionEventId}, tenant_id: {_eq: $tenantId}}}
) {
id
presentation
status
description
}
Expand Down
27 changes: 6 additions & 21 deletions packages/voting-portal/src/routes/BallotLocator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ import Tab from "@mui/material/Tab"
import {Link, useLocation, useNavigate, useParams} from "react-router-dom"
import {GET_CAST_VOTE} from "../queries/GetCastVote"
import {useQuery} from "@apollo/client/react"
import {
GetBallotStylesQuery,
GetCastVoteQuery,
GetElectionEventQuery,
ListCastVoteMessagesQuery,
} from "../gql/graphql"
import {GetBallotStylesQuery, GetCastVoteQuery, ListCastVoteMessagesQuery} from "../gql/graphql"
import {faAngleLeft, faCircleQuestion, faCopy} from "@fortawesome/free-solid-svg-icons"
import {GET_BALLOT_STYLES} from "../queries/GetBallotStyles"
import {LIST_CAST_VOTE_MESSAGES} from "../queries/listCastVoteMessages"
Expand All @@ -36,8 +31,6 @@ import {useAppDispatch, useAppSelector} from "../store/hooks"
import {selectFirstBallotStyle} from "../store/ballotStyles/ballotStylesSlice"
import {SettingsContext} from "../providers/SettingsContextProvider"
import useUpdateTranslation from "../hooks/useUpdateTranslation"
import {GET_ELECTION_EVENT} from "../queries/GetElectionEvent"
import {IElectionEvent} from "../store/electionEvents/electionEventsSlice"
import Table from "@mui/material/Table"
import TableSortLabel from "@mui/material/TableSortLabel"
import TableBody from "@mui/material/TableBody"
Expand Down Expand Up @@ -147,13 +140,8 @@ const BallotLocator: React.FC = () => {
const [page, setPage] = React.useState(0)
const [rowsPerPage, setRowsPerPage] = React.useState(5)
const lastCVRequestTimestamp = useRef<number | undefined>(undefined) // Timestamp of last LIST_CAST_VOTE_MESSAGES request
const {data: dataElectionEvent} = useQuery<GetElectionEventQuery>(GET_ELECTION_EVENT, {
variables: {
electionEventId: eventId,
tenantId,
},
skip: globalSettings.DISABLE_AUTH, // Skip query if in demo mode
})
const ballotStyle = useAppSelector(selectFirstBallotStyle)
const electionEventPresentation = ballotStyle?.ballot_eml.election_event_presentation

const {refetch} = useQuery<ListCastVoteMessagesQuery>(LIST_CAST_VOTE_MESSAGES, {
variables: {
Expand All @@ -166,9 +154,7 @@ const BallotLocator: React.FC = () => {
})

useUpdateTranslation(
{
electionEvent: dataElectionEvent?.sequent_backend_election_event[0] as IElectionEvent,
},
{presentation: electionEventPresentation},
defaultLanguageTouched,
setDefaultLanguageTouched
) // Overwrite translations
Expand Down Expand Up @@ -226,15 +212,14 @@ const BallotLocator: React.FC = () => {
if (validatedBallotId) {
setBallotIdNotFoundErr(false)
}
const showLogs = dataElectionEvent?.sequent_backend_election_event[0]?.presentation
?.show_cast_vote_logs as EShowCastVoteLogsPolicy
const showLogs = electionEventPresentation?.show_cast_vote_logs as EShowCastVoteLogsPolicy
setShowCVLogsPolicy(showLogs === EShowCastVoteLogsPolicy.SHOW_LOGS_TAB)
// the length must be an even number of characters
if (showLogs && allowSendRequest.current) {
allowSendRequest.current = false
requestCVMsgs()
}
}, [inputBallotId, dataElectionEvent, page, rowsPerPage])
}, [inputBallotId, electionEventPresentation, page, rowsPerPage])

const handleChangePage = (event: unknown, newPage: number) => {
allowSendRequest.current = true
Expand Down
5 changes: 1 addition & 4 deletions packages/voting-portal/src/routes/ConfirmationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from "@sequentech/ui-essentials"
import {
stringToHtml,
IElectionEventPresentation,
EVotingStatus,
IAuditableMultiBallot,
IAuditableSingleBallot,
Expand All @@ -30,7 +29,6 @@ import Link from "@mui/material/Link"
import {useAppDispatch, useAppSelector} from "../store/hooks"
import {selectAuditableBallot} from "../store/auditableBallots/auditableBallotsSlice"
import {canVoteSomeElection} from "../store/castVotes/castVotesSlice"
import {selectElectionEventById} from "../store/electionEvents/electionEventsSlice"
import {IElectionExtended} from "../store/elections/electionsSlice"
import {TenantEventType} from ".."
import {clearBallot} from "../store/ballotSelections/ballotSelectionsSlice"
Expand Down Expand Up @@ -134,7 +132,6 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
const location = useLocation()
const ballotStyle = useAppSelector(selectBallotStyleByElectionId(String(electionId)))
const dispatch = useAppDispatch()
const electionEvent = useAppSelector(selectElectionEventById(eventId))
const [createBallotReceipt] = useMutation(CREATE_BALLOT_RECEIPT)
const [documentId, setDocumentId] = useState<string | null>(null)
const {getDocumentUrl} = useGetPublicDocumentUrl()
Expand All @@ -145,7 +142,7 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
const isDemo = oneBallotStyle?.ballot_eml.public_key?.is_demo
const [isPolling, setIsPolling] = useState<boolean>(false)

let presentation = electionEvent?.presentation as IElectionEventPresentation | undefined
let presentation = ballotStyle?.ballot_eml.election_event_presentation
const ballotStyleElectionIds = useAppSelector(selectBallotStyleElectionIds)
const {data: dataElections} = useQuery<GetElectionsQuery>(GET_ELECTIONS, {
variables: {
Expand Down
11 changes: 8 additions & 3 deletions packages/voting-portal/src/routes/ElectionSelectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,13 @@ const ElectionSelectionScreen: React.FC = () => {
const {eventId, tenantId} = useParams<{eventId?: string; tenantId?: string}>()
const electionEvent = useAppSelector(selectElectionEventById(eventId))
const oneBallotStyle = useAppSelector(selectFirstBallotStyle)
const electionEventPresentation = oneBallotStyle?.ballot_eml.election_event_presentation
//Handle both transalations from presentation and i18n language change.
useUpdateTranslation({electionEvent}, defaultLanguageTouched, setDefaultLanguageTouched) // Overwrite translations
useUpdateTranslation(
{presentation: electionEventPresentation},
defaultLanguageTouched,
setDefaultLanguageTouched
) // Overwrite translations
const ballotStyleElectionIds = useAppSelector(selectBallotStyleElectionIds)
const electionIds = useAppSelector(selectElectionIds)
const dispatch = useAppDispatch()
Expand Down Expand Up @@ -468,8 +473,8 @@ const ElectionSelectionScreen: React.FC = () => {
}, [dataElectionEvent, dispatch])

useEffect(() => {
setIsMaterialsActivated(electionEvent?.presentation?.materials?.activated || false)
}, [electionEvent?.presentation?.materials?.activated])
setIsMaterialsActivated(electionEventPresentation?.materials?.activated || false)
}, [electionEventPresentation?.materials?.activated])

useEffect(() => {
if (castVotes?.sequent_backend_cast_vote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
import {createSlice, PayloadAction} from "@reduxjs/toolkit"
import {RootState} from "../store"
import {IElectionEventPresentation} from "@sequentech/ui-core"

export interface IElectionEvent {
alias?: string | null
Expand All @@ -21,7 +20,6 @@ export interface IElectionEvent {
is_audit?: boolean | null
labels?: string | null
name?: string | null
presentation?: IElectionEventPresentation | null
public_key?: string | null
statistics?: string | null
status?: string | null
Expand Down
3 changes: 2 additions & 1 deletion packages/voting-portal/src/store/elections/electionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const {setElection} = electionsSlice.actions
export const selectElectionIds = (state: RootState) => {
return sortElectionList(
Object.values(state.elections) as unknown as IElection[],
Object.values(state.electionEvent)[0]?.presentation?.elections_order
Object.values(state.ballotStyles)[0]?.ballot_eml.election_event_presentation
?.elections_order
).map((election) => election.id)
}

Expand Down
Loading