Skip to content

Commit d28491f

Browse files
Matin Gohar FarMatin Gohar Far
authored andcommitted
implemented PR suggestions
1 parent 619ec6d commit d28491f

3 files changed

Lines changed: 23 additions & 24 deletions

File tree

src/api/votings.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {CreateVotingRequest} from "store/features/votings/types";
2-
import {SERVER_HTTP_URL} from "../config";
1+
import { CreateVotingRequest, VotingStatus } from "store/features/votings/types";
2+
import { SERVER_HTTP_URL } from "../config";
33

44
export const VotingAPI = {
55
/**
@@ -23,22 +23,21 @@ export const VotingAPI = {
2323

2424
throw new Error(`create voting request resulted in response with status ${response.status}`);
2525
} catch (error) {
26-
throw new Error(`unable to create voting`, {cause: error});
26+
throw new Error(`unable to create voting`, { cause: error });
2727
}
2828
},
2929

30-
changeVotingStatus: async (board: string, voting: string, status?: string) => {
30+
changeVotingStatus: async (board: string, voting: string, status?: VotingStatus) => {
3131
try {
32+
const resolvedStatus: VotingStatus = typeof status === "undefined" || status === null ? "CLOSED" : status;
33+
3234
const options: RequestInit = {
3335
method: "PUT",
3436
credentials: "include",
37+
body: JSON.stringify({ status: resolvedStatus }),
38+
headers: { "Content-Type": "application/json" },
3539
};
3640

37-
if (typeof status !== "undefined") {
38-
options.body = JSON.stringify({status});
39-
options.headers = {"Content-Type": "application/json"};
40-
}
41-
4241
const response = await fetch(`${SERVER_HTTP_URL}/boards/${board}/votings/${voting}`, options);
4342

4443
if (response.status === 200) {
@@ -47,7 +46,7 @@ export const VotingAPI = {
4746

4847
throw new Error(`change voting status request resulted in response with status ${response.status}`);
4948
} catch (error) {
50-
throw new Error(`unable to change voting status`, {cause: error});
49+
throw new Error(`unable to change voting status`, { cause: error });
5150
}
5251
},
5352
};

src/components/VotingDialog/VotingDialog.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getNumberFromStorage, saveToStorage, getFromStorage } from "utils/stora
88
import { CUMULATIVE_VOTING_DEFAULT_STORAGE_KEY, CUSTOM_NUMBER_OF_VOTES_STORAGE_KEY } from "constants/storage";
99
import { PlusIcon, MinusIcon } from "components/Icon";
1010
import "./VotingDialog.scss";
11-
import { closeVoting, createVoting, cancelVoting } from "store/features";
11+
import { closeVoting, createVoting, abortVoting } from "store/features";
1212

1313
export const VotingDialog = () => {
1414
const dispatch = useAppDispatch();
@@ -46,8 +46,8 @@ export const VotingDialog = () => {
4646
navigate("..");
4747
};
4848

49-
const abortVoting = () => {
50-
dispatch(cancelVoting(voting!));
49+
const abort_voting = () => {
50+
dispatch(abortVoting(voting!));
5151
navigate("..");
5252
}
5353

@@ -59,7 +59,7 @@ export const VotingDialog = () => {
5959
<label>{t("VoteConfigurationButton.stopVoting")}</label>
6060
</button>
6161

62-
<button className="voting-dialog__start-button voting-dialog__cancel-button" data-testid="voting-dialog__cancel-button" onClick={() => abortVoting()}>
62+
<button className="voting-dialog__start-button voting-dialog__cancel-button" data-testid="voting-dialog__cancel-button" onClick={() => abort_voting()}>
6363
<label>{t("VoteConfigurationButton.cancelVoting")}</label>
6464
</button>
6565
</>
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import {createAsyncThunk} from "@reduxjs/toolkit";
2-
import {API} from "api";
3-
import {ApplicationState, retryable} from "store";
4-
import {CreateVotingRequest} from "./types";
1+
import { createAsyncThunk } from "@reduxjs/toolkit";
2+
import { API } from "api";
3+
import { ApplicationState, retryable } from "store";
4+
import { CreateVotingRequest } from "./types";
55

6-
export const createVoting = createAsyncThunk<void, CreateVotingRequest, {state: ApplicationState}>("votings/createVoting", async (payload, {dispatch, getState}) => {
6+
export const createVoting = createAsyncThunk<void, CreateVotingRequest, { state: ApplicationState }>("votings/createVoting", async (payload, { dispatch, getState }) => {
77
const boardId = getState().board.data!.id;
88

99
await retryable(
1010
() => API.createVoting(boardId, payload),
1111
dispatch,
12-
() => createVoting({...payload}),
12+
() => createVoting({ ...payload }),
1313
"createVoting"
1414
);
1515
});
1616

17-
export const closeVoting = createAsyncThunk<void, string, {state: ApplicationState}>("votings/closeVoting", async (payload, {dispatch, getState}) => {
17+
export const closeVoting = createAsyncThunk<void, string, { state: ApplicationState }>("votings/closeVoting", async (payload, { dispatch, getState }) => {
1818
const boardId = getState().board.data!.id;
1919

2020
await retryable(
@@ -25,13 +25,13 @@ export const closeVoting = createAsyncThunk<void, string, {state: ApplicationSta
2525
);
2626
});
2727

28-
export const cancelVoting = createAsyncThunk<void, string, {state: ApplicationState}>("votings/cancelVoting", async (payload, {dispatch, getState}) => {
28+
export const abortVoting = createAsyncThunk<void, string, { state: ApplicationState }>("votings/abortVoting", async (payload, { dispatch, getState }) => {
2929
const boardId = getState().board.data!.id;
3030

3131
await retryable(
3232
() => API.changeVotingStatus(boardId, payload, "ABORTED"),
3333
dispatch,
34-
() => cancelVoting(payload),
35-
"cancelVoting"
34+
() => abortVoting(payload),
35+
"abortVoting"
3636
);
3737
});

0 commit comments

Comments
 (0)