From 2040e031aa3bd6fe48d4da0d527266486ec3d1f8 Mon Sep 17 00:00:00 2001 From: JohanGrims Date: Mon, 9 Dec 2024 23:54:06 +0100 Subject: [PATCH] Add confirmation dialog before publishing results in Results component --- src/admin/vote/Results.jsx | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/admin/vote/Results.jsx b/src/admin/vote/Results.jsx index 177d357..829be28 100644 --- a/src/admin/vote/Results.jsx +++ b/src/admin/vote/Results.jsx @@ -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() { @@ -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(), - }); }); } @@ -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} >