Skip to content

Commit

Permalink
feat(anonymous-voting): add anonymous option to voting dialog (#4172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaazizi committed Dec 4, 2024
1 parent adc6e24 commit 19bd966
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/VotingDialog/VotingDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ export const VotingDialog = () => {
const [allowCumulativeVoting, setAllowCumulativeVoting] = useState(cumulativeVotingDefault);
const [numberOfVotes, setNumberOfVotes] = useState(getNumberFromStorage(CUSTOM_NUMBER_OF_VOTES_STORAGE_KEY, 5));

const IS_ANONYMOUS_STORAGE_KEY = "IS_ANONYMOUS_DEFAULT";
const [isAnonymous, setIsAnonymous] = useState(true);

if (!isAdmin) {
navigate("..");
}

const startVoting = () => {
dispatch(
createVoting({
voteLimit: numberOfVotes,
showVotesOfOthers: false,
showVotesOfOthers: !isAnonymous, // Nur anzeigen, wenn nicht anonym
allowMultipleVotes: allowCumulativeVoting,
isAnonymous, // Neue Eigenschaft, die den Modus an das Backend sendet
})
);
saveToStorage(CUSTOM_NUMBER_OF_VOTES_STORAGE_KEY, String(numberOfVotes));
saveToStorage(CUMULATIVE_VOTING_DEFAULT_STORAGE_KEY, String(allowCumulativeVoting));
saveToStorage(IS_ANONYMOUS_STORAGE_KEY, String(isAnonymous));
navigate("..");
};

Expand All @@ -56,6 +60,12 @@ export const VotingDialog = () => {
<label>{t("VoteConfigurationButton.allowMultipleVotesPerNote")}</label>
<Toggle active={allowCumulativeVoting} className="voting-dialog__toggle" />
</button>

{/* Neuer Toggle für anonymen Modus */}
<button className="dialog__button" data-testid="voting-dialog__anonymous-button" onClick={() => setIsAnonymous((prev) => !prev)}>
<label>{isAnonymous ? t("VoteConfigurationButton.anonymousMode") : t("VoteConfigurationButton.nonAnonymousMode")}</label>
<Toggle active={isAnonymous} className="voting-dialog__toggle" />
</button>
<div className="dialog__button">
<label>{t("VoteConfigurationButton.numberOfVotes")}</label>
<div className="voting-dialog__votes-controls">
Expand Down

0 comments on commit 19bd966

Please sign in to comment.