-
Notifications
You must be signed in to change notification settings - Fork 2
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
Created a "You need to save!" Modal on the Candidate Decider #799
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
732d47b
Created a "You need to save!" reminder on the Candidate Decider
jujulcrane 8ff28ff
updated format and lint
jujulcrane 09278ea
Added navigation for the search bar and id dropdown and removed isSav…
jujulcrane 3d4f847
fixed format and lint
jujulcrane 1129501
Update CandidateDecider.tsx
jujulcrane d4c18e7
Update CandidateDecider.tsx
jujulcrane ee07bdd
reducing code duplication
jujulcrane 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
There are no files selected for viewing
This file contains 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,5 +1,5 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Button, Dropdown, Checkbox } from 'semantic-ui-react'; | ||
import { Button, Dropdown, Checkbox, Modal } from 'semantic-ui-react'; | ||
import CandidateDeciderAPI from '../../API/CandidateDeciderAPI'; | ||
import ResponsesPanel from './ResponsesPanel'; | ||
import LocalProgressPanel from './LocalProgressPanel'; | ||
|
@@ -17,6 +17,8 @@ type CandidateDeciderProps = { | |
}; | ||
|
||
const CandidateDecider: React.FC<CandidateDeciderProps> = ({ uuid }) => { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const [nextCandidate, setNextCandidate] = useState<number | null>(null); | ||
const [currentCandidate, setCurrentCandidate] = useState<number>(0); | ||
const [showOtherVotes, setShowOtherVotes] = useState<boolean>(false); | ||
|
||
|
@@ -46,6 +48,9 @@ const CandidateDecider: React.FC<CandidateDeciderProps> = ({ uuid }) => { | |
const [defaultCurrentRating, setDefaultCurrentRating] = useState<Rating>(); | ||
const [defaultCurrentComment, setDefaultCurrentComment] = useState<string>(); | ||
|
||
const isSaved = | ||
currentComment === defaultCurrentComment && currentRating === defaultCurrentRating; | ||
|
||
const populateReviewForCandidate = (candidate: number) => { | ||
const rating = getRating(candidate); | ||
const comment = getComment(candidate); | ||
|
@@ -68,24 +73,6 @@ const CandidateDecider: React.FC<CandidateDeciderProps> = ({ uuid }) => { | |
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [currentCandidate, instance.candidates, reviews]); | ||
|
||
const next = () => { | ||
if (currentCandidate === instance.candidates.length - 1) return; | ||
setCurrentCandidate((prev) => { | ||
const nextCandidate = prev + 1; | ||
populateReviewForCandidate(nextCandidate); | ||
return nextCandidate; | ||
}); | ||
}; | ||
|
||
const previous = () => { | ||
if (currentCandidate === 0) return; | ||
setCurrentCandidate((prev) => { | ||
const prevCandidate = prev - 1; | ||
populateReviewForCandidate(prevCandidate); | ||
return prevCandidate; | ||
}); | ||
}; | ||
|
||
const handleRatingAndCommentChange = (id: number, rating: Rating, comment: string) => { | ||
CandidateDeciderAPI.updateRatingAndComment(instance.uuid, id, rating, comment); | ||
if (userInfo) { | ||
|
@@ -109,17 +96,69 @@ const CandidateDecider: React.FC<CandidateDeciderProps> = ({ uuid }) => { | |
} | ||
}; | ||
|
||
const handleCandidateChange = (candidate: number) => { | ||
if (candidate < 0 || candidate >= instance.candidates.length) { | ||
return; | ||
} | ||
if (!isSaved) { | ||
setNextCandidate(candidate); | ||
setIsModalOpen(true); | ||
} else { | ||
setCurrentCandidate(candidate); | ||
populateReviewForCandidate(candidate); | ||
} | ||
}; | ||
|
||
const navigateToNextCandidate = (candidate: number) => { | ||
setCurrentCandidate(candidate); | ||
populateReviewForCandidate(candidate); | ||
setNextCandidate(null); | ||
setIsModalOpen(false); | ||
}; | ||
|
||
return instance.candidates.length === 0 ? ( | ||
<div></div> | ||
) : ( | ||
<div className={styles.candidateDeciderContainer}> | ||
<Modal open={isModalOpen} onClose={() => setIsModalOpen(false)} size="small"> | ||
<Modal.Header>Don't Forget To Save!</Modal.Header> | ||
<Modal.Content> | ||
<p>You have unsaved changes. Do you want to save them before navigating?</p> | ||
</Modal.Content> | ||
<Modal.Actions> | ||
<Button onClick={() => setIsModalOpen(false)}>Cancel</Button> | ||
<Button | ||
onClick={() => { | ||
handleRatingAndCommentChange( | ||
currentCandidate, | ||
currentRating ?? 0, | ||
currentComment ?? '' | ||
); | ||
if (nextCandidate !== null) { | ||
navigateToNextCandidate(nextCandidate); | ||
} | ||
}} | ||
> | ||
Save | ||
</Button> | ||
<Button | ||
primary | ||
onClick={() => { | ||
if (nextCandidate !== null) { | ||
navigateToNextCandidate(nextCandidate); | ||
} | ||
}} | ||
> | ||
Discard | ||
</Button> | ||
</Modal.Actions> | ||
</Modal> | ||
<div className={styles.applicationContainer}> | ||
<div className={styles.searchBar}> | ||
<SearchBar | ||
instance={instance} | ||
setCurrentCandidate={(candidate) => { | ||
setCurrentCandidate(candidate); | ||
populateReviewForCandidate(candidate); | ||
handleCandidateChange(candidate); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually you can just pass in
is the same as
|
||
}} | ||
currentCandidate={currentCandidate} | ||
/> | ||
|
@@ -136,29 +175,35 @@ const CandidateDecider: React.FC<CandidateDeciderProps> = ({ uuid }) => { | |
text: candidate.id | ||
}))} | ||
onChange={(_, data) => { | ||
setCurrentCandidate(data.value as number); | ||
populateReviewForCandidate(data.value as number); | ||
handleCandidateChange(data.value as number); | ||
}} | ||
/> | ||
<span className={styles.ofNum}>of {instance.candidates.length}</span> | ||
<Button.Group className={styles.previousNextButtonContainer}> | ||
<Button basic color="blue" disabled={currentCandidate === 0} onClick={previous}> | ||
<Button | ||
basic | ||
color="blue" | ||
disabled={currentCandidate === 0} | ||
onClick={() => { | ||
handleCandidateChange(currentCandidate - 1); | ||
}} | ||
> | ||
PREVIOUS | ||
</Button> | ||
<Button | ||
basic | ||
color="blue" | ||
disabled={currentCandidate === instance.candidates.length - 1} | ||
onClick={next} | ||
onClick={() => { | ||
handleCandidateChange(currentCandidate + 1); | ||
}} | ||
> | ||
NEXT | ||
</Button> | ||
</Button.Group> | ||
<Button | ||
className="ui blue button" | ||
disabled={ | ||
currentComment === defaultCurrentComment && currentRating === defaultCurrentRating | ||
} | ||
disabled={isSaved} | ||
onClick={() => { | ||
handleRatingAndCommentChange( | ||
currentCandidate, | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a function
navigateToNextCandidate
for this and the code that's being duplicated below?