From f068b7a9e15885c6c70e87ec96cff4745f3f7c6b Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Sat, 18 Apr 2020 18:13:35 +0000 Subject: [PATCH] [VOTE] fix payload in the absence of a token --- src/components/views/Vote.jsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/views/Vote.jsx b/src/components/views/Vote.jsx index e34814b..8974896 100644 --- a/src/components/views/Vote.jsx +++ b/src/components/views/Vote.jsx @@ -149,14 +149,18 @@ class Vote extends Component { gradesByCandidate.push(gradesById[id]); }); + const payload = { + election: electionSlug, + grades_by_candidate: gradesByCandidate, + } + if (token !== ""){ + payload["token"] = token; + } + fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - election: electionSlug, - grades_by_candidate: gradesByCandidate, - token: token, - }) + body: JSON.stringify(payload) }) .then(this.handleErrors) .then(result =>