@@ -18,6 +18,8 @@ interface IRatingFormProps {
1818 project : ProjectDTO ;
1919}
2020
21+ const NOT_RATED = - 1 ;
22+
2123/**
2224 * Component that allows users to submit and edit ratings for projects.
2325 * Only for one criterion, use multiple of this to cover all of them.
@@ -32,7 +34,9 @@ export const RatingForm = ({
3234
3335 const { showNotification } = useNotificationContext ( ) ;
3436
35- const [ ratingValue , setRatingValue ] = useState < number > ( rating ?. rating || 3 ) ;
37+ const [ ratingValue , setRatingValue ] = useState < number > (
38+ rating ?. rating || NOT_RATED ,
39+ ) ;
3640 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
3741
3842 React . useEffect ( ( ) => {
@@ -42,6 +46,10 @@ export const RatingForm = ({
4246 } , [ rating ] ) ;
4347
4448 const handleSubmit = async ( ) => {
49+ if ( ratingValue === NOT_RATED ) {
50+ return ;
51+ }
52+
4553 setIsSubmitting ( true ) ;
4654
4755 await api . createRating ( {
@@ -64,6 +72,13 @@ export const RatingForm = ({
6472 value = { ratingValue ?. toString ( ) }
6573 onChange = { ( e ) => setRatingValue ( parseInt ( e . target . value , 10 ) ) }
6674 >
75+ < FormControlLabel
76+ key = "hidden"
77+ value = { NOT_RATED . toString ( ) }
78+ control = { < Radio disabled = { isSubmitting } /> }
79+ label = ""
80+ style = { { display : "none" } }
81+ />
6782 { [ 1 , 2 , 3 , 4 , 5 ] . map ( ( value ) => (
6883 < FormControlLabel
6984 key = { value . toString ( ) }
0 commit comments