@@ -2,6 +2,8 @@ import { type DeepReplace } from '@ifrc-go/ui/utils';
22import {
33 isDefined ,
44 isNotDefined ,
5+ isTruthyString ,
6+ type Maybe ,
57} from '@togglecorp/fujs' ;
68import {
79 addCondition ,
@@ -31,6 +33,12 @@ import {
3133} from '#utils/form' ;
3234import { type GoApiResponse } from '#utils/restRequest' ;
3335
36+ function isTrueValue ( value : Maybe < boolean > ) {
37+ // FIXME: use translations
38+ return ( isNotDefined ( value ) || value === false )
39+ ? 'This field must be consented to if situational overview is filled.'
40+ : undefined ;
41+ }
3442// FORM
3543
3644type FieldReportResponse = GoApiResponse < '/api/v2/field-report/{id}/' > ;
@@ -50,6 +58,8 @@ export type FormValue = Omit<
5058 // FIXME: Why do we need to change countries to country
5159 // Fix this in the server later
5260 country : number ,
61+ // NOTE: This is not sent to server, only used from frontend validation
62+ situationalOverviewConsented : boolean ,
5363} ;
5464
5565export type PartialFormValue = PurgeNull < PartialForm < FormValue , 'uuid' | 'ctype' | 'organization' > > ;
@@ -155,6 +165,7 @@ const fieldsInContext = [
155165] satisfies ( keyof PartialFormValue ) [ ] ;
156166const fieldsInSituation = [
157167 'affected_pop_centres' ,
168+ 'situationalOverviewConsented' ,
158169 'description' ,
159170 'epi_cases' ,
160171 'epi_cases_since_last_fr' ,
@@ -314,6 +325,7 @@ export const reportSchema: FormSchema = {
314325 const situationFields = [
315326 'affected_pop_centres' ,
316327 'description' ,
328+ 'situationalOverviewConsented' ,
317329 'epi_cases' ,
318330 'epi_cases_since_last_fr' ,
319331 'epi_confirmed_cases' ,
@@ -354,13 +366,15 @@ export const reportSchema: FormSchema = {
354366 baseSchema = addCondition (
355367 baseSchema ,
356368 value ,
357- [ 'status' , 'is_covid_report' , 'dtype' ] ,
369+ [ 'status' , 'is_covid_report' , 'dtype' , 'description' ] ,
358370 situationFields ,
359371 ( val ) : SituationSchema => {
360372 const reportType = getReportType ( val ?. status , val ?. is_covid_report , val ?. dtype ) ;
373+ const consentRequired = isTruthyString ( val ?. description ) ;
361374
362375 const baseSchemaTwo : SituationSchema = {
363376 description : { } ,
377+ situationalOverviewConsented : { } ,
364378 other_sources : { } ,
365379
366380 affected_pop_centres : { forceValue : nullValue } ,
@@ -402,6 +416,11 @@ export const reportSchema: FormSchema = {
402416 if ( reportType === 'EW' ) {
403417 return {
404418 ...baseSchemaTwo ,
419+ situationalOverviewConsented : {
420+ validations : [
421+ consentRequired ? isTrueValue : undefined ,
422+ ] . filter ( isDefined ) ,
423+ } ,
405424 num_potentially_affected : { validations : [ positiveIntegerCondition ] } ,
406425 gov_num_potentially_affected : { validations : [ positiveIntegerCondition ] } ,
407426 other_num_potentially_affected : { validations : [ positiveIntegerCondition ] } ,
@@ -443,6 +462,11 @@ export const reportSchema: FormSchema = {
443462 // SITUATION - EVT
444463 return {
445464 ...baseSchemaTwo ,
465+ situationalOverviewConsented : {
466+ validations : [
467+ consentRequired ? isTrueValue : undefined ,
468+ ] . filter ( isDefined ) ,
469+ } ,
446470 num_injured : { validations : [ positiveIntegerCondition ] } ,
447471 gov_num_injured : { validations : [ positiveIntegerCondition ] } ,
448472 other_num_injured : { validations : [ positiveIntegerCondition ] } ,
0 commit comments