@@ -25,6 +25,7 @@ import {
2525} from '@togglecorp/fujs' ;
2626
2727import DropdownMenuItem from '#components/DropdownMenuItem' ;
28+ import Link from '#components/Link' ;
2829import { type components } from '#generated/types' ;
2930import useGlobalEnums from '#hooks/domain/useGlobalEnums' ;
3031import useAlert from '#hooks/useAlert' ;
@@ -36,11 +37,16 @@ import {
3637 EAP_STATUS_TECHNICALLY_VALIDATED ,
3738 EAP_STATUS_UNDER_DEVELOPMENT ,
3839 EAP_STATUS_UNDER_REVIEW ,
40+ EAP_TYPE_FULL ,
41+ EAP_TYPE_SIMPLIFIED ,
3942} from '#utils/constants' ;
4043import {
4144 type GoApiBody ,
4245 useLazyRequest ,
4346} from '#utils/restRequest' ;
47+ import { type ResponseObjectError } from '#utils/restRequest/error' ;
48+
49+ import { type EapListItem } from '../utils' ;
4450
4551import i18n from './i18n.json' ;
4652
@@ -70,6 +76,7 @@ export interface Props {
7076 status : EapStatus ;
7177 onStatusUpdate ?: ( ) => void ;
7278 hasValidatedBudgetFile ?: boolean ;
79+ details : EapListItem ;
7380}
7481
7582function EapStatus ( props : Props ) {
@@ -78,13 +85,18 @@ function EapStatus(props: Props) {
7885 status,
7986 onStatusUpdate,
8087 hasValidatedBudgetFile,
88+ details,
8189 } = props ;
8290
91+ const simplifiedEapDetails = details . simplified_eap_details ;
92+ const fullEapDetails = details . full_eap_details ;
93+
8394 const alert = useAlert ( ) ;
8495
8596 const { eap_eap_status : eapStatusOptions } = useGlobalEnums ( ) ;
8697 const [ newStatus , setNewStatus ] = useState < EapStatus | undefined > ( ) ;
8798 const [ checklistFile , setChecklistFile ] = useState < File | undefined > ( ) ;
99+ const [ hasFormErrors , setHasFormErrors ] = useState < ResponseObjectError > ( ) ;
88100
89101 const strings = useTranslation ( i18n ) ;
90102
@@ -114,11 +126,19 @@ function EapStatus(props: Props) {
114126 } ,
115127 formData : true ,
116128 onFailure : ( error ) => {
129+ const {
130+ value : { formErrors, messageForNotification } ,
131+ } = error ;
132+
133+ if ( isDefined ( formErrors ) ) {
134+ setHasFormErrors ( formErrors ) ;
135+ }
136+
117137 alert . show (
118138 strings . statusUpdateFailedAlert ,
119139 {
120140 variant : 'danger' ,
121- description : error . value . messageForNotification ,
141+ description : messageForNotification ,
122142 } ,
123143 ) ;
124144 } ,
@@ -140,6 +160,7 @@ function EapStatus(props: Props) {
140160 const confirmDisabled = (
141161 ( newStatus === EAP_STATUS_NS_ADDRESSING_COMMENTS && isNotDefined ( checklistFile ) )
142162 || ( newStatus === EAP_STATUS_PENDING_PFA && ! hasValidatedBudgetFile )
163+ || isDefined ( hasFormErrors )
143164 ) ;
144165
145166 return (
@@ -166,13 +187,45 @@ function EapStatus(props: Props) {
166187 heading = { strings . updateStatusHeading }
167188 onClose = { handleStatusUpdateCancel }
168189 footerActions = { (
169- < Button
170- name = { requestBody }
171- onClick = { triggerStatusUpdate }
172- disabled = { confirmDisabled }
173- >
174- { strings . confirmStatusButtonLabel }
175- </ Button >
190+ < ListView >
191+ { details . eap_type === EAP_TYPE_SIMPLIFIED && hasFormErrors && (
192+ < Link
193+ to = "simplifiedEapForm"
194+ urlParams = { { eapId } }
195+ urlSearch = { isDefined ( simplifiedEapDetails [ 0 ] ?. version )
196+ ? `version=${ simplifiedEapDetails [ 0 ] . version } `
197+ : undefined }
198+ title = { strings . editSimplifiedEapFormLinkLabel }
199+ state = { { error : hasFormErrors } }
200+ styleVariant = "outline"
201+ colorVariant = "primary"
202+ >
203+ { strings . editSimplifiedEapFormLinkLabel }
204+ </ Link >
205+ ) }
206+ { details . eap_type === EAP_TYPE_FULL && hasFormErrors && (
207+ < Link
208+ to = "eapFullExport"
209+ urlParams = { { eapId } }
210+ urlSearch = { isDefined ( fullEapDetails [ 0 ] ?. version )
211+ ? `version=${ fullEapDetails [ 0 ] . version } `
212+ : undefined }
213+ title = { strings . editFullEapFormLinkLabel }
214+ state = { { error : hasFormErrors } }
215+ styleVariant = "outline"
216+ colorVariant = "primary"
217+ >
218+ { strings . editFullEapFormLinkLabel }
219+ </ Link >
220+ ) }
221+ < Button
222+ name = { requestBody }
223+ onClick = { triggerStatusUpdate }
224+ disabled = { confirmDisabled }
225+ >
226+ { strings . confirmStatusButtonLabel }
227+ </ Button >
228+ </ ListView >
176229 ) }
177230 >
178231 < ListView
@@ -211,6 +264,15 @@ function EapStatus(props: Props) {
211264 </ Label >
212265 </ ListView >
213266 ) }
267+ { isDefined ( hasFormErrors ) && (
268+ < Alert
269+ name = "form-error-warning"
270+ type = "warning"
271+ title = { strings . submitFormErrorMessage }
272+ withLightBackground
273+ withoutShadow
274+ />
275+ ) }
214276 { newStatus === EAP_STATUS_PENDING_PFA && ! hasValidatedBudgetFile && (
215277 < Alert
216278 name = "no-budget-file-warning"
0 commit comments