@@ -21,7 +21,7 @@ interface IEditTaskMetadataState {
2121}
2222
2323const CourseTaskEditor : FC < {
24- speculativeTask : HomeworkTaskViewModel & { isModified ?: boolean } ,
24+ speculativeTask : HomeworkTaskViewModel & { isModified ?: boolean , hasErrors ?: boolean } ,
2525 speculativeHomework : HomeworkViewModel ,
2626 onUpdate : ( update : { task : HomeworkTaskViewModel , isDeleted ?: boolean , isSaved ?: boolean } ) => void ,
2727 toEditHomework : ( ) => void ,
@@ -78,7 +78,7 @@ const CourseTaskEditor: FC<{
7878 const [ title , setTitle ] = useState < string > ( task . title ! )
7979 const [ maxRating , setMaxRating ] = useState < number > ( task . maxRating ! )
8080 const [ description , setDescription ] = useState < string > ( task . description ! )
81- const [ hasErrors , setHasErrors ] = useState < boolean > ( false )
81+ const [ hasErrors , setHasErrors ] = useState < boolean > ( props . speculativeTask . hasErrors || false )
8282 const [ showDeleteConfirmation , setShowDeleteConfirmation ] = useState < boolean > ( false )
8383
8484 const [ handleSubmitLoading , setHandleSubmitLoading ] = useState ( false ) ;
@@ -87,15 +87,16 @@ const CourseTaskEditor: FC<{
8787 const publicationDate = metadata ?. publicationDate || homework . publicationDate
8888
8989 useEffect ( ( ) => {
90- const update : HomeworkTaskViewModel = {
90+ const update = {
9191 ...props . speculativeTask ,
9292 ...metadata ! ,
9393 title : title ! ,
9494 description : description ,
9595 maxRating : maxRating ,
96+ hasErrors : hasErrors
9697 }
9798 props . onUpdate ( { task : update } )
98- } , [ title , description , maxRating , metadata ] )
99+ } , [ title , description , maxRating , metadata , hasErrors ] )
99100
100101 const handleSubmit = async ( e : any ) => {
101102 e . preventDefault ( )
@@ -126,7 +127,7 @@ const CourseTaskEditor: FC<{
126127 props . onUpdate ( { task, isDeleted : true } )
127128 }
128129
129- const isDisabled = hasErrors || ! isLoaded || ! title || ! maxRating
130+ const isDisabled = hasErrors || ! isLoaded
130131
131132 const homeworkPublicationDateIsSet = ! homework . publicationDateNotSet
132133
@@ -145,6 +146,7 @@ const CourseTaskEditor: FC<{
145146 value = { title }
146147 onChange = { ( e ) => {
147148 e . persist ( )
149+ setHasErrors ( ! e . target . value )
148150 setTitle ( e . target . value )
149151 } }
150152 />
@@ -162,6 +164,7 @@ const CourseTaskEditor: FC<{
162164 value = { maxRating }
163165 onChange = { ( e ) => {
164166 e . persist ( )
167+ setHasErrors ( + e . target . value <= 0 )
165168 setMaxRating ( + e . target . value )
166169 } }
167170 />
0 commit comments