diff --git a/anonymousVoting/clientAnonymousVoting/src/components/ConnectWallet.js b/anonymousVoting/clientAnonymousVoting/src/components/ConnectWallet.js
index 0cbecd89..8a6d5065 100644
--- a/anonymousVoting/clientAnonymousVoting/src/components/ConnectWallet.js
+++ b/anonymousVoting/clientAnonymousVoting/src/components/ConnectWallet.js
@@ -124,4 +124,4 @@ const ConnectWallet = () => {
);
}
-export default ConnectWallet;
\ No newline at end of file
+export default ConnectWallet;
diff --git a/anonymousVoting/clientAnonymousVoting/src/components/CreateProcessPage.js b/anonymousVoting/clientAnonymousVoting/src/components/CreateProcessPage.js
index f5e4ed38..64218f8a 100644
--- a/anonymousVoting/clientAnonymousVoting/src/components/CreateProcessPage.js
+++ b/anonymousVoting/clientAnonymousVoting/src/components/CreateProcessPage.js
@@ -5,8 +5,8 @@ import styles from './CreateProcessPage.module.css';
import {ethers} from 'ethers';
//web3 imports
-import { deployVotingProcess, deployTestContract, getTestContract } from '../web3/contracts'
-import { useState, useEffect, useRef } from 'react';
+import { deployVotingProcess} from '../web3/contracts'
+import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
@@ -27,35 +27,44 @@ const CreateProcess = () => {
const [open, setOpen] = useState(false);
const [transactionResult, setTransactionResult] = useState(null);
- const refValue = useRef(false);
+ // const refValue = useRef(false);
- const createProcess = async (e) => {
- e.preventDefault();
- console.log("name: ", name);
- //format proposals
- let proposalArray = formatProposals(proposals);
- //check form inputs
- if(!isFormValid()){
- window.alert("Form is not valid");
- return;
- }
+ const createProcess = async (e) => {
+ e.preventDefault();
+
+ if (!isFormValid()) {
+ window.alert("Form is not valid");
+ return;
+ }
+
+ try {
setPending(true);
- refValue.current = true;
- //deploy new process contract
- const result = await deployVotingProcess(name, description, proposalArray,1000000,1000000);
+
+ const proposalArray = formatProposals(proposals);
+ const result = await deployVotingProcess(
+ name,
+ description,
+ proposalArray,
+ 1000000,
+ 1000000
+ );
+
setTransactionResult(result);
+ setShow(true);
- refValue.current = false;
+ } catch (err) {
+ console.error(err);
+ window.alert("Transaction failed");
+ } finally {
setPending(false);
-
- setShow(true);
}
+};
+
const isFormValid = () => {
- if(proposals < 2)
- return false;
- return true;
- }
+ return proposals.split(',').length >= 2;
+};
+
const formatProposals = (input) => {
let proposals = input.split(',');
@@ -67,9 +76,6 @@ const CreateProcess = () => {
}
- useEffect(() => {
- // setPending(!pending);
- }, [pending])
return (
@@ -105,11 +111,27 @@ const CreateProcess = () => {
/>
-
+
+
- {refValue.current == true &&
-
-
}
+
diff --git a/anonymousVoting/clientAnonymousVoting/src/components/modals/AddCandidateModal.js b/anonymousVoting/clientAnonymousVoting/src/components/modals/AddCandidateModal.js
index bd2f8af4..33eedc20 100644
--- a/anonymousVoting/clientAnonymousVoting/src/components/modals/AddCandidateModal.js
+++ b/anonymousVoting/clientAnonymousVoting/src/components/modals/AddCandidateModal.js
@@ -1,18 +1,20 @@
import { useState } from 'react';
import { Flex, Modal, Button, Card } from "rimble-ui";
import { ethers } from "ethers";
-import ElectionOrganiser from "../../build/ElectionOrganizer.json";
-import {successtoast, dangertoast } from '../utilities/Toasts';
+import { successtoast, dangertoast } from '../utilities/Toasts';
import { toast } from "react-toastify";
-import {addProposal} from '../../web3/contracts';
+import { addProposal } from '../../web3/contracts';
export function AddCandidateModal({ electionId }) {
const [isOpen, setIsOpen] = useState(false);
+
+ // ✅ ONLY name is kept (description removed)
const [candidateDetail, setCandidateDetail] = useState({
- name: '',
- description: ''
+ name: ''
});
+ // ✅ Terms acceptance state
+ const [acceptedTerms, setAcceptedTerms] = useState(false);
const handleCandidateDetailChange = (e) => {
const { name, value } = e.target;
@@ -20,55 +22,60 @@ export function AddCandidateModal({ electionId }) {
...candidateDetail,
[name]: value
});
- }
-
+ };
const handleSubmitCandidate = async (e) => {
- let id ;
- e.preventDefault();
- try {
-
-
- let tx = await addProposal(electionId,ethers.utils.toUtf8Bytes(candidateDetail.name.trim()));
-
- await tx.wait();
- console.log(tx);
-
- // successtoast(id, "Candidate Added Successfully")
-
-
-
- } catch(err) {
- dangertoast(id ,"Candidate Addition Failed")
- console.log(err);
- }
-
+ e.preventDefault();
+
+ if (!acceptedTerms) {
+ toast.error("You must accept the Terms & Conditions");
+ return;
+ }
+
+ try {
+ let tx = await addProposal(
+ electionId,
+ ethers.utils.toUtf8Bytes(candidateDetail.name.trim())
+ );
+
+ await tx.wait();
+
+ setIsOpen(false);
+ setAcceptedTerms(false);
+
+ successtoast("Candidate Added Successfully"); // optional success toast
+ } catch (err) {
+ dangertoast("Candidate Addition Failed"); // removed 'id'
+ console.log(err);
}
+};
+
- const closeModal = e => {
+ const closeModal = (e) => {
e.preventDefault();
setIsOpen(false);
+ setAcceptedTerms(false);
};
- const openModal = e => {
+ const openModal = (e) => {
e.preventDefault();
setIsOpen(true);
};
return (
-
-
Add Candidate
+
+ Add Candidate
-
+
-
+
-
+
Add candidates
-
-
+
-
Canidate Name
-
-
-
Candidate Name
+
+
+
-
-
Canidate Description
-
-
-
-
+
+ {/* ✅ Terms & Conditions checkbox */}
+
+
+
-
-
+
+
Cancel
-
+
);
-}
\ No newline at end of file
+}