-
Notifications
You must be signed in to change notification settings - Fork 178
Feature/candidate onboarding terms #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
charuljain02
wants to merge
5
commits into
AOSSIE-Org:main
Choose a base branch
from
charuljain02:feature/candidate-onboarding-terms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4da995e
fix: add loading spinner and disable create process button during tra…
charuljain02 619f550
feat: require candidate to accept terms before onboarding
charuljain02 2a2ff08
Update ConnectWallet.js
charuljain02 bd64812
Update AddCandidateModal.js
charuljain02 17ab194
Update AddCandidateModal.js
charuljain02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,4 +124,4 @@ const ConnectWallet = () => { | |
| ); | ||
| } | ||
|
|
||
| export default ConnectWallet; | ||
| export default ConnectWallet; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 72 additions & 65 deletions
137
anonymousVoting/clientAnonymousVoting/src/components/modals/AddCandidateModal.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,127 +1,134 @@ | ||
| 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; | ||
| setCandidateDetail({ | ||
| ...candidateDetail, | ||
| [name]: value | ||
| }); | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| const handleSubmitCandidate = async (e) => { | ||
| let id ; | ||
| let id; | ||
| e.preventDefault(); | ||
|
|
||
| // ✅ Enforce terms acceptance | ||
| 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(); | ||
| console.log(tx); | ||
|
|
||
| // successtoast(id, "Candidate Added Successfully") | ||
|
|
||
|
|
||
|
|
||
| } catch(err) { | ||
| dangertoast(id ,"Candidate Addition Failed") | ||
| let tx = await addProposal( | ||
| electionId, | ||
| ethers.utils.toUtf8Bytes(candidateDetail.name.trim()) | ||
| ); | ||
charuljain02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| await tx.wait(); | ||
|
|
||
| setIsOpen(false); | ||
| setAcceptedTerms(false); | ||
| } catch (err) { | ||
| dangertoast(id, "Candidate Addition Failed"); | ||
| 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 ( | ||
| <div> | ||
| <div onClick={openModal} style={{cursor: "pointer"}}> | ||
| <font size = '2'>Add Candidate</font> | ||
| <div onClick={openModal} style={{ cursor: "pointer" }}> | ||
| <font size="2">Add Candidate</font> | ||
| </div> | ||
|
|
||
| <Modal isOpen={isOpen}> | ||
| <Card width={"90%"} height={"max-content"} p={0} style={{maxWidth: "500px"}}> | ||
| <Card width="90%" height="max-content" p={0} style={{ maxWidth: "500px" }}> | ||
| <Button.Text | ||
| style={{margin: "0px"}} | ||
| style={{ margin: "0px" }} | ||
| icononly | ||
| icon={"Close"} | ||
| color={"moon-gray"} | ||
| position={"absolute"} | ||
| icon="Close" | ||
| color="moon-gray" | ||
| position="absolute" | ||
| top={0} | ||
| right={0} | ||
| mt={3} | ||
| mr={3} | ||
| onClick={closeModal} | ||
| /> | ||
|
|
||
| <div style={{margin: "10px", maxWidth: "700px", width: "90%"}}> | ||
| <div style={{ margin: "10px", maxWidth: "700px", width: "90%" }}> | ||
| <h5>Add candidates</h5> | ||
|
|
||
| <br/> | ||
| <br /> | ||
|
|
||
| <div> | ||
| <b>Canidate Name</b> | ||
| <br/> | ||
| <input | ||
| className="form-control" | ||
| <b>Candidate Name</b> | ||
| <br /> | ||
|
|
||
| <input | ||
| className="form-control" | ||
| placeholder="Name of the candidate" | ||
| name="name" | ||
| value={candidateDetail.name} | ||
| onChange={handleCandidateDetailChange} | ||
| style={{marginTop: "15px"}} | ||
| style={{ marginTop: "15px" }} | ||
| /> | ||
| <br /><br /> | ||
|
|
||
| <b>Canidate Description</b> | ||
| <br/> | ||
|
|
||
| <textarea | ||
| className="form-control" | ||
| placeholder="Name of the candidate" | ||
| name="description" | ||
| rows={6} | ||
| value={candidateDetail.description} | ||
| onChange={handleCandidateDetailChange} | ||
| style={{marginTop: "15px"}} | ||
| /> | ||
|
|
||
| <br /><br /> | ||
|
|
||
| {/* ✅ Terms & Conditions checkbox */} | ||
| <div> | ||
| <label style={{ cursor: "pointer" }}> | ||
| <input | ||
| type="checkbox" | ||
| checked={acceptedTerms} | ||
| onChange={(e) => setAcceptedTerms(e.target.checked)} | ||
| style={{ marginRight: "8px" }} | ||
| /> | ||
| I accept the Terms & Conditions | ||
| </label> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <Flex | ||
| px={4} | ||
| py={3} | ||
| justifyContent={"flex-end"} | ||
| > | ||
|
|
||
| <Flex px={4} py={3} justifyContent="flex-end"> | ||
| <Button.Outline onClick={closeModal}>Cancel</Button.Outline> | ||
| <Button ml={3} type="submit" onClick={handleSubmitCandidate}>Confirm</Button> | ||
| <Button | ||
| ml={3} | ||
| type="submit" | ||
| onClick={handleSubmitCandidate} | ||
| disabled={!acceptedTerms} | ||
| > | ||
| Confirm | ||
| </Button> | ||
| </Flex> | ||
| </Card> | ||
| </Modal> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.