Skip to content

Commit 57af5e8

Browse files
committed
feat(field-report): add consent checkbox above situational overview
1 parent 767e4ef commit 57af5e8

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

app/src/views/FieldReportForm/SituationFields/i18n.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"fieldsStep2SituationFieldsEVTMissingDescription": "Number of people missing.",
4848
"fieldsStep2SituationFieldsEVTMissingLabel": "Missing",
4949
"fieldsStep2SourceOfFiguresLabel": "Source (of figures)",
50-
"fieldReportFormNumericDetails": "Numeric Details (People)"
50+
"fieldReportFormNumericDetails": "Numeric Details (People)",
51+
"fieldReportOverviewConsentLabel": "All content published on IFRC platforms must adhere to the {fundamentalPrinciples} and align with the relevant Movement language and communications guidelines. Where content does not meet these standards, the IFRC will collaborate with the respective National Society to revise it accordingly.",
52+
"fieldReportFundamentalPrinciplesLabel": "Fundamental Principles"
5153
}
5254
}
5355

app/src/views/FieldReportForm/SituationFields/index.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMemo } from 'react';
22
import {
3+
Checkbox,
34
Container,
45
DateInput,
56
InputSection,
@@ -8,12 +9,14 @@ import {
89
TextArea,
910
} from '@ifrc-go/ui';
1011
import { useTranslation } from '@ifrc-go/ui/hooks';
12+
import { resolveToComponent } from '@ifrc-go/ui/utils';
1113
import {
1214
type EntriesAsList,
1315
type Error,
1416
getErrorObject,
1517
} from '@togglecorp/toggle-form';
1618

19+
import Link from '#components/Link';
1720
import RichTextArea from '#components/RichTextArea';
1821
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
1922
import { type ReportType } from '#utils/constants';
@@ -53,6 +56,20 @@ function SituationFields(props: Props) {
5356

5457
const sectionHeading = strings.fieldReportFormNumericDetails;
5558

59+
const overviewConsentLabel = resolveToComponent(
60+
strings.fieldReportOverviewConsentLabel,
61+
{
62+
fundamentalPrinciples: (
63+
<Link
64+
href="https://www.ifrc.org/who-we-are/international-red-cross-and-red-crescent-movement/fundamental-principles"
65+
external
66+
>
67+
{strings.fieldReportFundamentalPrinciplesLabel}
68+
</Link>
69+
),
70+
},
71+
);
72+
5673
if (reportType === 'COVID') {
5774
return (
5875
<Container
@@ -500,12 +517,20 @@ function SituationFields(props: Props) {
500517
title={strings.fieldsStep2DescriptionEVTLabel}
501518
description={strings.fieldsStep2DescriptionEVTDescription}
502519
>
520+
<Checkbox
521+
label={overviewConsentLabel}
522+
name="situationalOverviewConsented"
523+
value={value.situationalOverviewConsented}
524+
onChange={onValueChange}
525+
disabled={disabled}
526+
error={error?.situationalOverviewConsented}
527+
/>
503528
<RichTextArea
504529
name="description"
505530
value={value.description}
506531
onChange={onValueChange}
507532
error={error?.description}
508-
disabled={disabled}
533+
disabled={disabled || !value.situationalOverviewConsented}
509534
placeholder={strings.fieldsStep2DescriptionEVTPlaceholder}
510535
/>
511536
</InputSection>

app/src/views/FieldReportForm/common.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { type DeepReplace } from '@ifrc-go/ui/utils';
22
import {
33
isDefined,
44
isNotDefined,
5+
isTruthyString,
6+
type Maybe,
57
} from '@togglecorp/fujs';
68
import {
79
addCondition,
@@ -31,6 +33,12 @@ import {
3133
} from '#utils/form';
3234
import { 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

3644
type 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

5565
export type PartialFormValue = PurgeNull<PartialForm<FormValue, 'uuid' | 'ctype' | 'organization'>>;
@@ -155,6 +165,7 @@ const fieldsInContext = [
155165
] satisfies (keyof PartialFormValue)[];
156166
const 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] },

app/src/views/FieldReportForm/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useTranslation } from '@ifrc-go/ui/hooks';
2121
import {
2222
isDefined,
2323
isNotDefined,
24+
isTruthyString,
2425
listToGroupList,
2526
} from '@togglecorp/fujs';
2627
import {
@@ -210,7 +211,12 @@ export function Component() {
210211
: [],
211212
);
212213
setDistrictOptions(response?.districts_details);
213-
onValueSet(formValue);
214+
// NOTE: We are setting situationalOverviewConsented here because its only-client
215+
// value and if the field it filled it means that user consented to it
216+
onValueSet({
217+
...formValue,
218+
situationalOverviewConsented: isTruthyString(formValue.description),
219+
});
214220
},
215221
});
216222

0 commit comments

Comments
 (0)