1
1
import React , { useEffect , useState } from "react" ;
2
2
import { Button , Col , Popconfirm , Row , Form } from "antd" ;
3
- import { connect } from "react-redux" ;
3
+ import { connect , useSelector } from "react-redux" ;
4
4
import { bindActionCreators , compose } from "redux" ;
5
5
import {
6
6
EMPTY_FIELD ,
@@ -18,12 +18,13 @@ import {
18
18
updateNoticeOfDeparture ,
19
19
} from "@mds/common/redux/actionCreators/noticeOfDepartureActionCreator" ;
20
20
import { getNoticeOfDeparture } from "@mds/common/redux/selectors/noticeOfDepartureSelectors" ;
21
- import { Field , FieldArray , change } from "@mds/common/components/forms/form" ;
21
+ import { Field , FieldArray , change , getFormValues } from "@mds/common/components/forms/form" ;
22
22
import {
23
23
email ,
24
24
maxLength ,
25
25
phoneNumber ,
26
26
required ,
27
+ requiredList ,
27
28
} from "@mds/common/redux/utils/Validate" ;
28
29
import { getUserAccessData } from "@mds/common/redux/selectors/authenticationSelectors" ;
29
30
import CoreTable from "@mds/common/components/common/CoreTable" ;
@@ -51,7 +52,6 @@ interface RenderContactsProps {
51
52
52
53
export const renderContacts : React . FC < RenderContactsProps > = ( props , disabled = false ) => {
53
54
const { fields } = props ;
54
-
55
55
return (
56
56
< div className = "margin-large--bottom" >
57
57
{ fields . length > 0 && (
@@ -132,6 +132,8 @@ const NoticeOfDepartureModal: React.FC<NoticeOfDepartureModalProps> = (props) =>
132
132
const [ uploadedFiles , setUploadedFiles ] = useState ( [ ] ) ;
133
133
const [ uploading , setUploading ] = useState ( false ) ;
134
134
const formName = FORM . NOTICE_OF_DEPARTURE_FORM ;
135
+ const formValues = useSelector ( getFormValues ( formName ) ) ;
136
+ const currentStatus = formValues ?. nod_status
135
137
136
138
const { noticeOfDeparture, mine, change } = props ;
137
139
const { nod_guid } = noticeOfDeparture ;
@@ -149,6 +151,15 @@ const NoticeOfDepartureModal: React.FC<NoticeOfDepartureModalProps> = (props) =>
149
151
( doc ) => doc . document_type === NOTICE_OF_DEPARTURE_DOCUMENT_TYPE . DECISION
150
152
) ;
151
153
154
+ const isDecisionDocRequired = ( status ) => {
155
+ const requiredDocStatuses = [
156
+ NOTICE_OF_DEPARTURE_STATUS_VALUES . determined_non_substantial ,
157
+ NOTICE_OF_DEPARTURE_STATUS_VALUES . determined_substantial ,
158
+ ] ;
159
+
160
+ return requiredDocStatuses . includes ( status ) && decision . length === 0 && documentArray . length == 0 ;
161
+ }
162
+
152
163
const handleAddDocuments = ( noticeOfDepartureGuid ) => {
153
164
documentArray . forEach ( ( document ) =>
154
165
props . addDocumentToNoticeOfDeparture (
@@ -335,6 +346,8 @@ const NoticeOfDepartureModal: React.FC<NoticeOfDepartureModalProps> = (props) =>
335
346
addFileStart = { ( ) => setUploading ( true ) }
336
347
onAbort = { ( ) => setUploading ( false ) }
337
348
onProcessFiles = { ( ) => setUploading ( false ) }
349
+ validate = { isDecisionDocRequired ( currentStatus ) ? [ requiredList ] : [ ] }
350
+ required = { isDecisionDocRequired ( currentStatus ) }
338
351
uploadUrl = { NOTICE_OF_DEPARTURE_DOCUMENTS ( mine . mine_guid ) }
339
352
acceptedFileTypesMap = { { ...DOCUMENT , ...EXCEL } }
340
353
onFileLoad = { ( documentName , document_manager_guid ) => {
@@ -383,7 +396,7 @@ const NoticeOfDepartureModal: React.FC<NoticeOfDepartureModalProps> = (props) =>
383
396
) : (
384
397
< >
385
398
< RenderCancelButton />
386
- < RenderSubmitButton disabled = { documentArray . length == 0 || uploading } buttonText = "Update" disableOnClean = { false } />
399
+ < RenderSubmitButton disabled = { isDecisionDocRequired ( currentStatus ) || uploading } buttonText = "Update" disableOnClean = { false } />
387
400
</ >
388
401
) }
389
402
</ div >
0 commit comments