@@ -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 , notGuest , Task , TaskPriority , TeamPreview } from 'shared' ;
5+ import { countWords , isGuest , isUnderWordCount , notGuest , Task , TaskStatus , TaskPriority , 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,41 @@ 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+ console . log ( 'here' ) ;
38+ schema = yup . object ( ) . shape ( {
39+ notes : yup . string ( ) . optional ( ) ,
40+ startDate : yup . date ( ) . optional ( ) ,
41+ deadline : yup . date ( ) . required ( 'Deadline is required for In Progress tasks' ) ,
42+ priority : yup . mixed < TaskPriority > ( ) . oneOf ( Object . values ( TaskPriority ) ) . required ( ) ,
43+ assignees : yup . array ( ) . required ( ) . min ( 1 , 'At least one assignee is required for In Progress tasks' ) ,
44+ title : yup . string ( ) . required ( ) ,
45+ taskId : yup . string ( ) . required ( )
46+ } ) ;
47+ } else {
48+ console . log ( 'there' ) ;
49+ schema = yup . object ( ) . shape ( {
50+ notes : yup . string ( ) . optional ( ) ,
51+ startDate : yup . date ( ) . optional ( ) ,
52+ deadline : yup . date ( ) . optional ( ) ,
53+ priority : yup . mixed < TaskPriority > ( ) . oneOf ( Object . values ( TaskPriority ) ) . required ( ) ,
54+ assignees : yup . array ( ) . required ( ) ,
55+ title : yup . string ( ) . required ( ) ,
56+ taskId : yup . string ( ) . required ( )
57+ } ) ;
58+ }
59+
4360 const user = useCurrentUser ( ) ;
4461
4562 const { data : users , isLoading, isError, error } = useAllUsers ( ) ;
@@ -161,6 +178,7 @@ const TaskFormModal: React.FC<TaskFormModalProps> = ({ task, onSubmit, modalShow
161178 />
162179 ) }
163180 />
181+ < FormHelperText error = { ! ! errors . assignees } > { errors . assignees ?. message } </ FormHelperText >
164182 </ FormControl >
165183 </ Grid >
166184 < Grid item md = { 6 } >
@@ -199,6 +217,7 @@ const TaskFormModal: React.FC<TaskFormModalProps> = ({ task, onSubmit, modalShow
199217 />
200218 ) }
201219 />
220+ < FormHelperText error = { ! ! errors . deadline } > { errors . deadline ?. message } </ FormHelperText >
202221 </ FormControl >
203222 </ Grid >
204223 < Grid item xs = { 12 } md = { 12 } >
0 commit comments