From cdd1a11c7535ab2cd415f5d8b9a9945d789c4671 Mon Sep 17 00:00:00 2001 From: Damian Date: Sun, 7 Nov 2021 10:39:32 -0300 Subject: [PATCH] Disable Submit Election button is the election do not have any candidate --- packages/react-app/src/views/Create.jsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/react-app/src/views/Create.jsx b/packages/react-app/src/views/Create.jsx index 637e4460..c4ad0842 100644 --- a/packages/react-app/src/views/Create.jsx +++ b/packages/react-app/src/views/Create.jsx @@ -242,9 +242,15 @@ const Create = ({ const updateCandidates = (checked, addr) => { if (checked) { - newElection.candidates.push(addr); + setNewElection(prevState => ({ + ...prevState, + candidates: [...prevState.candidates, addr], + })); } else { - newElection.candidates = newElection.candidates.filter(d => d !== addr); + setNewElection(prevState => ({ + ...prevState, + candidates: newElection.candidates.filter(d => d !== addr), + })); } console.log(newElection); }; @@ -570,6 +576,7 @@ const Create = ({ isLoading={isSubmitting || isConfirmingElection} loadingText="Submitting" type="submit" + disabled={newElection.candidates.length === 0} leftIcon={} > Submit Election