Add confirmation for missing vote finalize
This commit is contained in:
@@ -367,14 +367,38 @@ function bindNavButtons() {
|
||||
|
||||
const finalizeBtn = $("finalize-votes");
|
||||
if (finalizeBtn) {
|
||||
const finalizeVotes = async (desired) => {
|
||||
await api.finalizeVotes(desired);
|
||||
state.votesFinal = desired;
|
||||
renderPhasePill();
|
||||
renderVotes();
|
||||
toast(desired ? t("vote.finalize") : t("vote.unfinalize"));
|
||||
};
|
||||
|
||||
const missingVotes = () => {
|
||||
const votedIds = new Set((state.myVotes ?? []).map((v) => v.suggestionId));
|
||||
return (state.allSuggestions ?? []).filter((s) => !votedIds.has(s.id));
|
||||
};
|
||||
|
||||
finalizeBtn.addEventListener("click", async () => {
|
||||
try {
|
||||
const desired = !state.votesFinal;
|
||||
await api.finalizeVotes(desired);
|
||||
state.votesFinal = desired;
|
||||
renderPhasePill();
|
||||
renderVotes();
|
||||
toast(desired ? t("vote.finalize") : t("vote.unfinalize"));
|
||||
if (desired) {
|
||||
const missing = missingVotes();
|
||||
if (missing.length > 0) {
|
||||
openConfirmModal({
|
||||
title: t("vote.finalizeMissingTitle"),
|
||||
body: t("vote.finalizeMissingBody", { count: missing.length }),
|
||||
confirmLabel: t("vote.finalizeMissingConfirm"),
|
||||
onConfirm: async (close) => {
|
||||
await finalizeVotes(desired);
|
||||
close();
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
await finalizeVotes(desired);
|
||||
} catch (err) {
|
||||
toast(err.message, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user