@@ -26,9 +26,9 @@ import {
2626 DisasterCategory ,
2727} from '#utils/constants' ;
2828import {
29- identifiedNeedsAndGapsSortedList ,
30- nsActionsSortedList ,
31- plannedInterventionSortedList ,
29+ identifiedNeedsAndGapsOrder ,
30+ nsActionsOrder ,
31+ plannedInterventionOrder ,
3232} from '#utils/domain/dref' ;
3333import ifrcLogo from '#assets/icons/ifrc-square.png' ;
3434
@@ -101,58 +101,72 @@ export function Component() {
101101 } ,
102102 } ) ;
103103
104- const filteredPlannedIntervention = useMemo (
105- ( ) => drefResponse ?. planned_interventions ?. map ( ( intervention ) => {
106- if ( isNotDefined ( intervention . title ) ) {
104+ const plannedInterventions = useMemo (
105+ ( ) => {
106+ if ( isNotDefined ( drefResponse ) || isNotDefined ( drefResponse . planned_interventions ) ) {
107107 return undefined ;
108108 }
109- return { ...intervention , title : intervention . title } ;
110- } ) . filter ( isDefined ) ,
111- [ drefResponse ?. planned_interventions ] ,
109+
110+ const { planned_interventions } = drefResponse ;
111+
112+ return planned_interventions . map (
113+ ( intervention ) => {
114+ if ( isNotDefined ( intervention . title ) ) {
115+ return undefined ;
116+ }
117+ return { ...intervention , title : intervention . title } ;
118+ } ,
119+ ) . filter ( isDefined ) . sort (
120+ ( a , b ) => plannedInterventionOrder [ a . title ] - plannedInterventionOrder [ b . title ] ,
121+ ) ;
122+ } ,
123+ [ drefResponse ] ,
112124 ) ;
113125
114- const filteredIdentifiedNeedsAndGaps = useMemo (
115- ( ) => drefResponse ?. needs_identified ?. map ( ( need ) => {
116- if ( isNotDefined ( need . title ) ) {
126+ const needsIdentified = useMemo (
127+ ( ) => {
128+ if ( isNotDefined ( drefResponse ) || isNotDefined ( drefResponse . needs_identified ) ) {
117129 return undefined ;
118130 }
119- return { ...need , title : need . title } ;
120- } ) . filter ( isDefined ) ,
121- [ drefResponse ?. needs_identified ] ,
131+
132+ const { needs_identified } = drefResponse ;
133+
134+ return needs_identified . map (
135+ ( need ) => {
136+ if ( isNotDefined ( need . title ) ) {
137+ return undefined ;
138+ }
139+
140+ return {
141+ ...need ,
142+ title : need . title ,
143+ } ;
144+ } ,
145+ ) . filter ( isDefined ) . sort ( ( a , b ) => (
146+ identifiedNeedsAndGapsOrder [ a . title ] - identifiedNeedsAndGapsOrder [ b . title ]
147+ ) ) ;
148+ } ,
149+ [ drefResponse ] ,
122150 ) ;
123151
124- const filteredNsActions = useMemo (
125- ( ) => drefResponse ?. national_society_actions ?. map ( ( nsAction ) => {
126- if ( isNotDefined ( nsAction . title ) ) {
152+ const nsActions = useMemo (
153+ ( ) => {
154+ if ( isNotDefined ( drefResponse ) || isNotDefined ( drefResponse . needs_identified ) ) {
127155 return undefined ;
128156 }
129- return { ...nsAction , title : nsAction . title } ;
130- } ) . filter ( isDefined ) ,
131- [ drefResponse ?. national_society_actions ] ,
132- ) ;
133-
134- const sortedPlannedInterventions = useMemo (
135- ( ) => filteredPlannedIntervention ?. sort (
136- // eslint-disable-next-line max-len
137- ( a , b ) => plannedInterventionSortedList [ a . title ] - plannedInterventionSortedList [ b . title ] ,
138- ) ,
139- [ filteredPlannedIntervention ] ,
140- ) ;
141157
142- const sortedIdentifiedNeedsAndGaps = useMemo (
143- ( ) => filteredIdentifiedNeedsAndGaps ?. sort (
144- // eslint-disable-next-line max-len
145- ( a , b ) => identifiedNeedsAndGapsSortedList [ a . title ] - identifiedNeedsAndGapsSortedList [ b . title ] ,
146- ) ,
147- [ filteredIdentifiedNeedsAndGaps ] ,
148- ) ;
158+ const { national_society_actions } = drefResponse ;
149159
150- const sortedNsActions = useMemo (
151- ( ) => filteredNsActions ?. sort ( ( a , b ) => (
152- // eslint-disable-next-line max-len
153- nsActionsSortedList [ a . title ] - nsActionsSortedList [ b . title ]
154- ) ) ,
155- [ filteredNsActions ] ,
160+ return national_society_actions ?. map ( ( nsAction ) => {
161+ if ( isNotDefined ( nsAction . title ) ) {
162+ return undefined ;
163+ }
164+ return { ...nsAction , title : nsAction . title } ;
165+ } ) . filter ( isDefined ) . sort ( ( a , b ) => (
166+ nsActionsOrder [ a . title ] - nsActionsOrder [ b . title ]
167+ ) ) ;
168+ } ,
169+ [ drefResponse ] ,
156170 ) ;
157171
158172 const eventDescriptionDefined = isTruthyString ( drefResponse ?. event_description ?. trim ( ) ) ;
@@ -187,7 +201,7 @@ export function Component() {
187201 const showNsAction = isDefined ( drefResponse )
188202 && isDefined ( drefResponse . national_society_actions )
189203 && drefResponse . national_society_actions . length > 0
190- && isDefined ( sortedNsActions ) ;
204+ && isDefined ( nsActions ) ;
191205
192206 const icrcActionsDefined = isTruthyString ( drefResponse ?. icrc ?. trim ( ) ) ;
193207
@@ -209,11 +223,15 @@ export function Component() {
209223 const needsIdentifiedDefined = isDefined ( drefResponse )
210224 && isDefined ( drefResponse . needs_identified )
211225 && drefResponse . needs_identified . length > 0
212- && isDefined ( sortedIdentifiedNeedsAndGaps ) ;
226+ && isDefined ( needsIdentified ) ;
227+
228+ const assessmentReportDefined = isDefined ( drefResponse )
229+ && isDefined ( drefResponse . assessment_report_details )
230+ && isDefined ( drefResponse . assessment_report_details . file ) ;
213231
214232 const showNeedsIdentifiedSection = isDefined ( drefResponse )
215233 && drefResponse . type_of_dref !== DREF_TYPE_ASSESSMENT
216- && ( identifiedGapsDefined || needsIdentifiedDefined ) ;
234+ && ( identifiedGapsDefined || needsIdentifiedDefined || assessmentReportDefined ) ;
217235
218236 const operationObjectiveDefined = isTruthyString ( drefResponse ?. operation_objective ?. trim ( ) ) ;
219237 const responseStrategyDefined = isTruthyString ( drefResponse ?. response_strategy ?. trim ( ) ) ;
@@ -242,7 +260,7 @@ export function Component() {
242260 const plannedInterventionDefined = isDefined ( drefResponse )
243261 && isDefined ( drefResponse . planned_interventions )
244262 && drefResponse . planned_interventions . length > 0
245- && isDefined ( sortedPlannedInterventions ) ;
263+ && isDefined ( plannedInterventions ) ;
246264
247265 const humanResourceDefined = isTruthyString ( drefResponse ?. human_resource ?. trim ( ) ) ;
248266 const surgePersonnelDeployedDefined = isTruthyString (
@@ -409,8 +427,6 @@ export function Component() {
409427 className = { styles . metaItem }
410428 label = { strings . operationStartDateLabel }
411429 value = { drefResponse ?. date_of_approval }
412- valueType = "date"
413- format = "dd-MM-yyyy"
414430 strongValue
415431 />
416432 < TextOutput
@@ -426,14 +442,12 @@ export function Component() {
426442 label = { strings . operationEndDateLabel }
427443 value = { drefResponse ?. end_date }
428444 valueType = "date"
429- format = "dd-MM-yyyy"
430445 strongValue
431446 />
432447 < TextOutput
433448 className = { styles . metaItem }
434449 label = { strings . drefPublishedLabel }
435450 value = { drefResponse ?. publishing_date }
436- format = "dd-MM-yyyy"
437451 valueType = "date"
438452 strongValue
439453 />
@@ -490,7 +504,6 @@ export function Component() {
490504 >
491505 < DateOutput
492506 value = { drefResponse ?. event_date }
493- format = "dd-MM-yyyy"
494507 />
495508 </ Container >
496509 ) }
@@ -537,13 +550,15 @@ export function Component() {
537550 </ Container >
538551 ) }
539552 { drefResponse ?. supporting_document_details ?. file && (
540- < Link
541- href = { drefResponse ?. supporting_document_details ?. file }
542- external
543- withUnderline
544- >
545- { strings . drefApplicationSupportingDocumentation }
546- </ Link >
553+ < Container >
554+ < Link
555+ href = { drefResponse ?. supporting_document_details ?. file }
556+ external
557+ withUnderline
558+ >
559+ { strings . drefApplicationSupportingDocumentation }
560+ </ Link >
561+ </ Container >
547562 ) }
548563 { sourceInformationDefined && (
549564 < Container
@@ -650,14 +665,13 @@ export function Component() {
650665 >
651666 < DateOutput
652667 value = { drefResponse ?. ns_respond_date }
653- format = "dd-MM-yyyy"
654668 />
655669 </ Container >
656670 ) }
657671 < Container
658672 childrenContainerClassName = { styles . nsActionsContent }
659673 >
660- { sortedNsActions ?. map (
674+ { nsActions ?. map (
661675 ( nsAction ) => (
662676 < BlockTextOutput
663677 key = { nsAction . id }
@@ -753,7 +767,7 @@ export function Component() {
753767 < Heading level = { 2 } >
754768 { strings . needsIdentifiedSectionHeading }
755769 </ Heading >
756- { needsIdentifiedDefined && sortedIdentifiedNeedsAndGaps ?. map (
770+ { needsIdentifiedDefined && needsIdentified ?. map (
757771 ( identifiedNeed ) => (
758772 < Fragment key = { identifiedNeed . id } >
759773 < Heading className = { styles . needsIdentifiedHeading } >
@@ -777,13 +791,17 @@ export function Component() {
777791 </ DescriptionText >
778792 </ Container >
779793 ) }
780- < Link
781- href = { drefResponse ?. assessment_report_details ?. file }
782- external
783- withUnderline
784- >
785- { strings . drefAssessmentReportLink }
786- </ Link >
794+ { assessmentReportDefined && (
795+ < Container >
796+ < Link
797+ href = { drefResponse ?. assessment_report_details ?. file }
798+ external
799+ withUnderline
800+ >
801+ { strings . drefAssessmentReportLink }
802+ </ Link >
803+ </ Container >
804+ ) }
787805 </ >
788806 ) }
789807 { showOperationStrategySection && (
@@ -976,7 +994,7 @@ export function Component() {
976994 < Heading level = { 2 } >
977995 { strings . plannedInterventionSectionHeading }
978996 </ Heading >
979- { sortedPlannedInterventions ?. map ( ( plannedIntervention ) => (
997+ { plannedInterventions ?. map ( ( plannedIntervention ) => (
980998 < Fragment key = { plannedIntervention . id } >
981999 < Heading className = { styles . plannedInterventionHeading } >
9821000 < img
0 commit comments