diff --git a/src/api/votings.ts b/src/api/votings.ts index 09e84c02f4..bfcf882573 100644 --- a/src/api/votings.ts +++ b/src/api/votings.ts @@ -1,5 +1,5 @@ -import {CreateVotingRequest} from "store/features/votings/types"; -import {SERVER_HTTP_URL} from "../config"; +import { CreateVotingRequest, VotingStatus } from "store/features/votings/types"; +import { SERVER_HTTP_URL } from "../config"; export const VotingAPI = { /** @@ -23,16 +23,20 @@ export const VotingAPI = { throw new Error(`create voting request resulted in response with status ${response.status}`); } catch (error) { - throw new Error(`unable to create voting`, {cause: error}); + throw new Error(`unable to create voting`, { cause: error }); } }, - changeVotingStatus: async (board: string, voting: string) => { + changeVotingStatus: async (board: string, voting: string, status?: VotingStatus) => { try { - const response = await fetch(`${SERVER_HTTP_URL}/boards/${board}/votings/${voting}`, { + const options: RequestInit = { method: "PUT", credentials: "include", - }); + body: JSON.stringify({ status: status }), + headers: { "Content-Type": "application/json" }, + }; + + const response = await fetch(`${SERVER_HTTP_URL}/boards/${board}/votings/${voting}`, options); if (response.status === 200) { return await response.json(); @@ -40,7 +44,7 @@ export const VotingAPI = { throw new Error(`change voting status request resulted in response with status ${response.status}`); } catch (error) { - throw new Error(`unable to change voting status`, {cause: error}); + throw new Error(`unable to change voting status`, { cause: error }); } }, }; diff --git a/src/components/VotingDialog/VotingDialog.tsx b/src/components/VotingDialog/VotingDialog.tsx index 6d0bf41260..f88341c17a 100644 --- a/src/components/VotingDialog/VotingDialog.tsx +++ b/src/components/VotingDialog/VotingDialog.tsx @@ -1,18 +1,18 @@ -import {useState} from "react"; -import {useTranslation} from "react-i18next"; -import {Dialog} from "components/Dialog"; -import {useNavigate} from "react-router"; -import {useAppDispatch, useAppSelector} from "store"; -import {Toggle} from "components/Toggle"; -import {getNumberFromStorage, saveToStorage, getFromStorage} from "utils/storage"; -import {CUMULATIVE_VOTING_DEFAULT_STORAGE_KEY, CUSTOM_NUMBER_OF_VOTES_STORAGE_KEY} from "constants/storage"; -import {PlusIcon, MinusIcon} from "components/Icon"; +import { useState } from "react"; +import { useTranslation } from "react-i18next"; +import { Dialog } from "components/Dialog"; +import { useNavigate } from "react-router"; +import { useAppDispatch, useAppSelector } from "store"; +import { Toggle } from "components/Toggle"; +import { getNumberFromStorage, saveToStorage, getFromStorage } from "utils/storage"; +import { CUMULATIVE_VOTING_DEFAULT_STORAGE_KEY, CUSTOM_NUMBER_OF_VOTES_STORAGE_KEY } from "constants/storage"; +import { PlusIcon, MinusIcon } from "components/Icon"; import "./VotingDialog.scss"; -import {closeVoting, createVoting} from "store/features"; +import { closeVoting, createVoting, abortVoting } from "store/features"; export const VotingDialog = () => { const dispatch = useAppDispatch(); - const {t} = useTranslation(); + const { t } = useTranslation(); const navigate = useNavigate(); const isAdmin = useAppSelector((state) => state.participants?.self?.role === "OWNER" || state.participants?.self?.role === "MODERATOR"); const voting = useAppSelector((state) => state.votings.open?.id); @@ -46,12 +46,23 @@ export const VotingDialog = () => { navigate(".."); }; + const abort_voting = () => { + dispatch(abortVoting(voting!)); + navigate(".."); + } + return ( navigate("..")}> {voting ? ( - + <> + + + + ) : ( <>