@@ -2,24 +2,14 @@ import { yupResolver } from '@hookform/resolvers/yup';
22import { Autocomplete , FormControl , FormHelperText , FormLabel , Grid , MenuItem , TextField } from '@mui/material' ;
33import { DatePicker } from '@mui/x-date-pickers' ;
44import { Controller , useForm } from 'react-hook-form' ;
5- import { countWords , isGuest , isUnderWordCount , Task , TaskPriority , TeamPreview } from 'shared' ;
5+ import { countWords , isGuest , isUnderWordCount , Task , TaskPriority , TaskStatus , TeamPreview } from 'shared' ;
66import { useAllUsers , useCurrentUser } from '../../../../hooks/users.hooks' ;
77import * as yup from 'yup' ;
88import { taskUserToAutocompleteOption } from '../../../../utils/task.utils' ;
99import NERFormModal from '../../../../components/NERFormModal' ;
1010import LoadingIndicator from '../../../../components/LoadingIndicator' ;
1111import ErrorPage from '../../../ErrorPage' ;
1212
13- const schema = yup . object ( ) . shape ( {
14- notes : yup . string ( ) . optional ( ) ,
15- startDate : yup . date ( ) . optional ( ) ,
16- deadline : yup . date ( ) . optional ( ) ,
17- priority : yup . mixed < TaskPriority > ( ) . oneOf ( Object . values ( TaskPriority ) ) . required ( ) ,
18- assignees : yup . array ( ) . required ( ) ,
19- title : yup . string ( ) . required ( ) ,
20- taskId : yup . string ( ) . required ( )
21- } ) ;
22-
2313export interface EditTaskFormInput {
2414 taskId : string ;
2515 title : string ;
@@ -32,14 +22,53 @@ export interface EditTaskFormInput {
3222
3323interface TaskFormModalProps {
3424 task ?: Task ;
25+ status ?: Task [ 'status' ] ;
3526 teams : TeamPreview [ ] ;
3627 modalShow : boolean ;
3728 onHide : ( ) => void ;
3829 onSubmit : ( data : EditTaskFormInput ) => Promise < void > ;
3930 onReset ?: ( ) => void ;
4031}
4132
42- const TaskFormModal : React . FC < TaskFormModalProps > = ( { task, onSubmit, modalShow, onHide, onReset } ) => {
33+ const TaskFormModal : React . FC < TaskFormModalProps > = ( { task, status, onSubmit, modalShow, onHide, onReset } ) => {
34+ let schema ;
35+
36+ if ( status === TaskStatus . IN_PROGRESS ) {
37+ schema = yup . object ( ) . shape ( {
38+ notes : yup
39+ . string ( )
40+ . optional ( )
41+ . test ( ( value ) => {
42+ if ( ! value ) return true ;
43+ const wordCount = countWords ( value ) ;
44+ return wordCount < 250 ;
45+ } ) ,
46+ startDate : yup . date ( ) . optional ( ) ,
47+ deadline : yup . date ( ) . required ( 'Deadline is required for In Progress tasks' ) ,
48+ priority : yup . mixed < TaskPriority > ( ) . oneOf ( Object . values ( TaskPriority ) ) . required ( ) ,
49+ assignees : yup . array ( ) . required ( ) . min ( 1 , 'At least one assignee is required for In Progress tasks' ) ,
50+ title : yup . string ( ) . required ( ) ,
51+ taskId : yup . string ( ) . required ( )
52+ } ) ;
53+ } else {
54+ schema = yup . object ( ) . shape ( {
55+ notes : yup
56+ . string ( )
57+ . optional ( )
58+ . test ( ( value ) => {
59+ if ( ! value ) return true ;
60+ const wordCount = countWords ( value ) ;
61+ return wordCount < 250 ;
62+ } ) ,
63+ startDate : yup . date ( ) . optional ( ) ,
64+ deadline : yup . date ( ) . optional ( ) ,
65+ priority : yup . mixed < TaskPriority > ( ) . oneOf ( Object . values ( TaskPriority ) ) . required ( ) ,
66+ assignees : yup . array ( ) . required ( ) ,
67+ title : yup . string ( ) . required ( ) ,
68+ taskId : yup . string ( ) . required ( )
69+ } ) ;
70+ }
71+
4372 const user = useCurrentUser ( ) ;
4473
4574 const { data : users , isLoading, isError, error } = useAllUsers ( ) ;
@@ -162,6 +191,7 @@ const TaskFormModal: React.FC<TaskFormModalProps> = ({ task, onSubmit, modalShow
162191 />
163192 ) }
164193 />
194+ < FormHelperText error = { ! ! errors . assignees } > { errors . assignees ?. message } </ FormHelperText >
165195 </ FormControl >
166196 </ Grid >
167197 < Grid item md = { 6 } >
@@ -200,6 +230,7 @@ const TaskFormModal: React.FC<TaskFormModalProps> = ({ task, onSubmit, modalShow
200230 />
201231 ) }
202232 />
233+ < FormHelperText error = { ! ! errors . deadline } > { errors . deadline ?. message } </ FormHelperText >
203234 </ FormControl >
204235 </ Grid >
205236 < Grid item xs = { 12 } md = { 12 } >
0 commit comments