Skip to content

Commit

Permalink
Add confirmation dialog before publishing results in Results component
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanGrims committed Dec 9, 2024
1 parent 784f8ed commit 2040e03
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/admin/vote/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { collection, doc, getDoc, getDocs, setDoc } from "firebase/firestore";
import { useLoaderData } from "react-router-dom";
import { auth, db } from "../../firebase";

import { snackbar } from "mdui";
import { confirm, snackbar } from "mdui";
import React from "react";

export default function Results() {
Expand Down Expand Up @@ -52,18 +52,27 @@ export default function Results() {
}

function publishResults() {
setDoc(
doc(db, `votes/${vote.id}`),
{
result: true,
confirm({
headline: "Ergebnisse veröffentlichen",
description:
"Sind Sie sicher, dass Sie die Ergebnisse veröffentlichen möchten? Dies kann nicht rückgängig gemacht werden.",
confirmText: "Ja, veröffentlichen",
cancelText: "Abbrechen",
onConfirm: () => {
setDoc(
doc(db, `votes/${vote.id}`),
{
result: true,
},
{ merge: true }
).then(() => {
snackbar({
message: "Ergebnisse veröffentlicht.",
action: "Seite neuladen",
onActionClick: () => window.location.reload(),
});
});
},
{ merge: true }
).then(() => {
snackbar({
message: "Ergebnisse veröffentlicht.",
action: "Seite neuladen",
onActionClick: () => window.location.reload(),
});
});
}

Expand Down Expand Up @@ -113,7 +122,7 @@ export default function Results() {
variant="outlined"
style={{ width: "100%", padding: "20px" }}
clickable
disabled={vote.result}
disabled={vote.result || !results.length}
onClick={publishResults}
>
<div
Expand Down

0 comments on commit 2040e03

Please sign in to comment.