-
Notifications
You must be signed in to change notification settings - Fork 17
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
Senghoung/edit review feature #426
Changes from all commits
c812f80
73522af
68bf590
6fabcb3
00d2e05
6b485c9
04bf079
0081f8c
026ed8b
7b8c4fc
ff0aed5
810001c
e23a9bc
e1fb4cb
7b5ad98
a007eb8
41af00c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,6 @@ | |||||
import RangeSlider from 'react-bootstrap-range-slider'; | ||||||
import Modal from 'react-bootstrap/Modal'; | ||||||
import ReCAPTCHA from 'react-google-recaptcha'; | ||||||
|
||||||
import { addReview } from '../../store/slices/reviewSlice'; | ||||||
import { useAppDispatch, useAppSelector } from '../../store/hooks'; | ||||||
import { ReviewProps } from '../Review/Review'; | ||||||
|
@@ -21,6 +20,8 @@ | |||||
|
||||||
interface ReviewFormProps extends ReviewProps { | ||||||
closeForm: () => void; | ||||||
editable?: boolean; | ||||||
review?: ReviewData; | ||||||
} | ||||||
|
||||||
const ReviewForm: FC<ReviewFormProps> = (props) => { | ||||||
|
@@ -44,7 +45,7 @@ | |||||
'Group projects', | ||||||
'Gives good feedback', | ||||||
]; | ||||||
|
||||||
const [reviewId, setReviewId] = useState<string | undefined>(props.review?._id); //edit review | ||||||
const [professor, setProfessor] = useState(props.professor?.ucinetid || ''); | ||||||
const [course, setCourse] = useState(props.course?.id || ''); | ||||||
const [yearTaken, setYearTaken] = useState(''); | ||||||
|
@@ -82,19 +83,48 @@ | |||||
if (cookies.user === undefined) { | ||||||
alert('You must be logged in to add a review!'); | ||||||
props.closeForm(); | ||||||
} else { | ||||||
setSubmitted(false); | ||||||
} | ||||||
} | ||||||
}, [showForm, props, cookies]); | ||||||
//If editable is true | ||||||
if (props.review) { | ||||||
const [year, quarter] = props.review.quarter.split(' '); | ||||||
setReviewId(props.review?._id); | ||||||
setQuarterTaken(quarter); | ||||||
setYearTaken(year); | ||||||
setGradeReceived(props.review.gradeReceived); | ||||||
setDifficulty(props.review.difficulty); | ||||||
setQuality(props.review.rating); | ||||||
setContent(props.review?.reviewContent); | ||||||
setSelectedTags(props.review?.tags); | ||||||
setAttendance(props.review?.attendance); | ||||||
setTakeAgain(props.review?.takeAgain); | ||||||
setTextbook(props.review?.textbook); | ||||||
setUserName(props.review?.userDisplay); | ||||||
setProfessor(props.review?.professorID); | ||||||
setCourse(props.review?.courseID); | ||||||
} | ||||||
}, [showForm]); | ||||||
Check warning on line 108 in site/src/component/ReviewForm/ReviewForm.tsx
|
||||||
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. Add the dependencies to clear the warning. The lint check will allow warnings but our goal should be to have none so let's make sure not to add anymore.
Suggested change
|
||||||
|
||||||
const postReview = async (review: ReviewData) => { | ||||||
const res = await axios.post<ReviewData>('/api/reviews', review).catch((err) => err.response); | ||||||
if (res.status === 400) { | ||||||
alert(res.data.error ?? 'You have already submitted a review for this course/professor'); | ||||||
} else if (res.data.error !== undefined) { | ||||||
alert('You must be logged in to add a review!'); | ||||||
if (props.editable) { | ||||||
const res = await axios.patch('/api/reviews/updateReview', review); | ||||||
if (res.data.hasOwnProperty.call(res.data, 'error')) { | ||||||
alert('You must be logged in to edit the review!'); | ||||||
} else { | ||||||
setSubmitted(true); | ||||||
} | ||||||
} else { | ||||||
setSubmitted(true); | ||||||
dispatch(addReview(res.data)); | ||||||
const res = await axios.post<ReviewData>('/api/reviews', review).catch((err) => err.response); | ||||||
if (res.status === 400) { | ||||||
alert(res.data.error ?? 'You have already submitted a review for this course/professor'); | ||||||
} else if (res.data.error !== undefined) { | ||||||
alert('You must be logged in to add a review!'); | ||||||
} else { | ||||||
setSubmitted(true); | ||||||
dispatch(addReview(res.data)); | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
|
@@ -116,35 +146,69 @@ | |||||
alert('Please complete the CAPTCHA'); | ||||||
return; | ||||||
} | ||||||
|
||||||
const date = new Date(); | ||||||
const year = date.getFullYear(); | ||||||
const month = (1 + date.getMonth()).toString(); | ||||||
const day = date.getDate().toString(); | ||||||
const review = { | ||||||
professorID: professor, | ||||||
courseID: course, | ||||||
userID: userID, | ||||||
userDisplay: userName, | ||||||
reviewContent: content, | ||||||
rating: quality, | ||||||
difficulty: difficulty, | ||||||
timestamp: month + '/' + day + '/' + year, | ||||||
gradeReceived: gradeReceived, | ||||||
forCredit: true, | ||||||
quarter: yearTaken + ' ' + quarterTaken, | ||||||
score: 0, | ||||||
takeAgain: takeAgain, | ||||||
textbook: textbook, | ||||||
attendance: attendance, | ||||||
tags: selectedTags, | ||||||
captchaToken: captchaToken, | ||||||
}; | ||||||
if (content.length > 500) { | ||||||
setOverCharLimit(true); | ||||||
if (props.editable === false) { | ||||||
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. Does this need to specifically === false, or can we just:
Suggested change
|
||||||
const date = new Date(); | ||||||
const year = date.getFullYear(); | ||||||
const month = (1 + date.getMonth()).toString(); | ||||||
const day = date.getDate().toString(); | ||||||
const review = { | ||||||
professorID: professor, | ||||||
courseID: course, | ||||||
userID: userID, | ||||||
userDisplay: userName, | ||||||
reviewContent: content, | ||||||
rating: quality, | ||||||
difficulty: difficulty, | ||||||
timestamp: month + '/' + day + '/' + year, | ||||||
gradeReceived: gradeReceived, | ||||||
forCredit: true, | ||||||
quarter: yearTaken + ' ' + quarterTaken, | ||||||
score: 0, | ||||||
takeAgain: takeAgain, | ||||||
textbook: textbook, | ||||||
attendance: attendance, | ||||||
tags: selectedTags, | ||||||
captchaToken: captchaToken, | ||||||
}; | ||||||
if (content.length > 500) { | ||||||
setOverCharLimit(true); | ||||||
} else { | ||||||
setOverCharLimit(false); | ||||||
postReview(review); | ||||||
} | ||||||
} else { | ||||||
setOverCharLimit(false); | ||||||
postReview(review); | ||||||
const date = new Date(); | ||||||
const year = date.getFullYear(); | ||||||
const month = (1 + date.getMonth()).toString(); | ||||||
const day = date.getDate().toString(); | ||||||
const review = { | ||||||
_id: reviewId, | ||||||
professorID: professor, | ||||||
courseID: course, | ||||||
userID: userID, | ||||||
userDisplay: userName, | ||||||
reviewContent: content, | ||||||
rating: quality, | ||||||
difficulty: difficulty, | ||||||
timestamp: month + '/' + day + '/' + year, | ||||||
gradeReceived: gradeReceived, | ||||||
forCredit: true, | ||||||
quarter: yearTaken + ' ' + quarterTaken, | ||||||
score: 0, | ||||||
takeAgain: takeAgain, | ||||||
textbook: textbook, | ||||||
attendance: attendance, | ||||||
tags: selectedTags, | ||||||
verified: false, | ||||||
captchaToken: captchaToken, | ||||||
}; | ||||||
if (content.length > 500) { | ||||||
setOverCharLimit(true); | ||||||
} else { | ||||||
setOverCharLimit(false); | ||||||
postReview(review); | ||||||
setSubmitted(true); | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
|
@@ -234,10 +298,14 @@ | |||||
<Col> | ||||||
<Row> | ||||||
<Col> | ||||||
<h1> | ||||||
It's your turn to review{' '} | ||||||
{props.course ? props.course?.department + ' ' + props.course?.courseNumber : props.professor?.name} | ||||||
</h1> | ||||||
{props.editable ? ( | ||||||
<h1>Edit your review for {props.review?.courseID + ' ' + props.review?.professorID}</h1> | ||||||
) : ( | ||||||
<h1> | ||||||
It's your turn to review{' '} | ||||||
{props.course ? props.course?.department + ' ' + props.course?.courseNumber : props.professor?.name} | ||||||
</h1> | ||||||
)} | ||||||
</Col> | ||||||
</Row> | ||||||
<Row className="mt-4" lg={2} md={1}> | ||||||
|
@@ -254,6 +322,7 @@ | |||||
defaultValue="" | ||||||
required | ||||||
onChange={(e) => setGradeReceived(e.target.value)} | ||||||
value={gradeReceived} | ||||||
> | ||||||
<option disabled={true} value=""> | ||||||
Grade | ||||||
|
@@ -278,6 +347,7 @@ | |||||
defaultValue="" | ||||||
required | ||||||
onChange={(e) => setQuarterTaken(e.target.value)} | ||||||
value={quarterTaken} | ||||||
> | ||||||
<option disabled={true} value=""> | ||||||
Quarter | ||||||
|
@@ -296,6 +366,7 @@ | |||||
defaultValue="" | ||||||
required | ||||||
onChange={(e) => setYearTaken(e.target.value)} | ||||||
value={yearTaken} | ||||||
> | ||||||
<option disabled={true} value=""> | ||||||
Year | ||||||
|
@@ -349,20 +420,23 @@ | |||||
id="takeAgain" | ||||||
label="Would Take Again" | ||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTakeAgain(e.target.checked)} | ||||||
checked={takeAgain} | ||||||
/> | ||||||
<Form.Check | ||||||
inline | ||||||
type="switch" | ||||||
id="textbook" | ||||||
label="Use Textbook" | ||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTextbook(e.target.checked)} | ||||||
checked={textbook} | ||||||
/> | ||||||
<Form.Check | ||||||
inline | ||||||
type="switch" | ||||||
id="attendance" | ||||||
label="Mandatory Attendance" | ||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setAttendance(e.target.checked)} | ||||||
checked={attendance} | ||||||
/> | ||||||
</Col> | ||||||
</Row> | ||||||
|
@@ -407,6 +481,7 @@ | |||||
setOverCharLimit(false); | ||||||
} | ||||||
}} | ||||||
value={props.editable ? content : props.review?.reviewContent} | ||||||
/> | ||||||
{/* <textarea rows={5} /> */} | ||||||
<div className="char-limit"> | ||||||
|
@@ -444,6 +519,7 @@ | |||||
setUserName(cookies.user.name); | ||||||
} | ||||||
}} | ||||||
checked={userName === 'Anonymous Peter'} | ||||||
/> | ||||||
</Col> | ||||||
</Row> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,8 @@ | |
align-items: flex-end; | ||
} | ||
} | ||
|
||
//Delete modal | ||
.delete-review-modal { | ||
text-align: center !important; | ||
} |
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.
Should make this a button not a div for accessibility purposes and then style it appropriately. I agree with Ethan's comments on the button styling.