Skip to content

Commit 39a2c16

Browse files
authored
Merge pull request #1078 from IFRCGo/feature/per-content-translation
Feature/per content translation
2 parents dc00339 + 2d7a6a5 commit 39a2c16

File tree

9 files changed

+71
-37
lines changed

9 files changed

+71
-37
lines changed

.changeset/soft-dragons-change.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
- Enable ability to start PER in IFRC supported lanugages
6+
- Make PER forms readOnly in case of language mismatch

app/src/components/domain/LanguageMismatchMessage/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ interface Props {
1313

1414
// FIXME: typings should be fixed in the server
1515
// this should be of type Language
16-
originalLanguage: string;
16+
originalLanguage: string | undefined;
1717
}
1818

1919
function LanguageMismatchMessage(props: Props) {
2020
const strings = useTranslation(i18n);
2121

2222
const {
2323
title = strings.languageMismatchErrorTitle,
24-
originalLanguage,
24+
originalLanguage = 'en',
2525
} = props;
2626

2727
return (

app/src/utils/outletContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ export interface PerProcessOutletContext {
4141
statusResponse: PerProcessStatusResponse | undefined,
4242
refetchStatusResponse: () => void,
4343
actionDivRef: React.RefObject<HTMLDivElement>,
44+
readOnly?: boolean;
4445
}

app/src/views/PerAssessmentForm/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function Component() {
8888
statusResponse,
8989
refetchStatusResponse,
9090
actionDivRef,
91+
readOnly: readOnlyFromContext,
9192
} = useOutletContext<PerProcessOutletContext>();
9293

9394
const {
@@ -361,7 +362,8 @@ export function Component() {
361362
|| fetchingPerAssessment
362363
|| fetchingStatus;
363364

364-
const readOnlyMode = isNotDefined(currentPerStep)
365+
const readOnlyMode = readOnlyFromContext
366+
|| isNotDefined(currentPerStep)
365367
|| currentPerStep !== PER_PHASE_ASSESSMENT;
366368

367369
const error = useMemo(

app/src/views/PerOverviewForm/index.tsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export function Component() {
8585
statusResponse,
8686
actionDivRef,
8787
refetchStatusResponse,
88+
readOnly,
8889
} = useOutletContext<PerProcessOutletContext>();
90+
8991
const { per_overviewassessmentmethods } = useGlobalEnums();
9092
const userMe = useUserMe();
9193

@@ -101,6 +103,7 @@ export function Component() {
101103
validate,
102104
} = useForm(
103105
overviewSchema,
106+
// FIXME: use value from enum
104107
{ value: { assessment_method: 'per' } },
105108
isSettingUpProcess,
106109
);
@@ -273,6 +276,7 @@ export function Component() {
273276
},
274277
);
275278
},
279+
useCurrentLanguageForMutation: true,
276280
});
277281

278282
const handleSubmit = useCallback(
@@ -337,10 +341,10 @@ export function Component() {
337341
const error = getErrorObject(formError);
338342

339343
const currentPerStep = statusResponse?.phase;
340-
const submissionDisabled = isDefined(currentPerStep)
341-
&& currentPerStep !== PER_PHASE_OVERVIEW;
344+
const submissionDisabled = readOnly
345+
|| (isDefined(currentPerStep) && currentPerStep !== PER_PHASE_OVERVIEW);
342346

343-
const partialReadonlyMode = value?.is_draft === false;
347+
const partialReadOnly = value?.is_draft === false;
344348

345349
const dataPending = fetchingPerOverview;
346350
const savePerPending = createPerPending || updatePerPending;
@@ -366,7 +370,7 @@ export function Component() {
366370
<Container
367371
headerElementRef={formContentRef}
368372
className={styles.overviewForm}
369-
heading={partialReadonlyMode
373+
heading={partialReadOnly
370374
? strings.overviewEditHeading
371375
: strings.overviewSetupHeading}
372376
headingLevel={2}
@@ -393,7 +397,7 @@ export function Component() {
393397
name={undefined}
394398
variant="secondary"
395399
onClick={handleSave}
396-
disabled={savePerPending}
400+
disabled={savePerPending || readOnly}
397401
>
398402
{strings.saveButtonLabel}
399403
</Button>
@@ -419,7 +423,7 @@ export function Component() {
419423
onChange={setFieldValue}
420424
value={value?.country}
421425
error={getErrorString(error?.country)}
422-
readOnly={partialReadonlyMode}
426+
readOnly={partialReadOnly || readOnly}
423427
disabled={disabled}
424428
regions={!userMe?.is_superuser
425429
? userMe?.is_per_admin_for_regions : undefined}
@@ -448,7 +452,7 @@ export function Component() {
448452
onChange={setFieldValue}
449453
value={value?.date_of_orientation}
450454
error={error?.date_of_orientation}
451-
readOnly={partialReadonlyMode}
455+
readOnly={partialReadOnly || readOnly}
452456
disabled={disabled}
453457
/>
454458
</InputSection>
@@ -466,6 +470,7 @@ export function Component() {
466470
setFileIdToUrlMap={setFileIdToUrlMap}
467471
error={getErrorString(error?.orientation_documents)}
468472
disabled={disabled}
473+
readOnly={readOnly}
469474
>
470475
{strings.uploadButtonLabel}
471476
</GoMultiFileInput>
@@ -490,7 +495,7 @@ export function Component() {
490495
onChange={setFieldValue}
491496
value={value?.date_of_assessment}
492497
error={error?.date_of_assessment}
493-
readOnly={partialReadonlyMode}
498+
readOnly={partialReadOnly || readOnly}
494499
disabled={disabled}
495500
/>
496501
</InputSection>
@@ -508,7 +513,7 @@ export function Component() {
508513
onChange={setFieldValue}
509514
value={value?.type_of_assessment}
510515
error={error?.type_of_assessment}
511-
readOnly={partialReadonlyMode}
516+
readOnly={partialReadOnly || readOnly}
512517
disabled={disabled || perOptionsPending}
513518
/>
514519
</InputSection>
@@ -553,7 +558,7 @@ export function Component() {
553558
value={value?.branches_involved}
554559
onChange={setFieldValue}
555560
error={error?.branches_involved}
556-
readOnly={partialReadonlyMode}
561+
readOnly={partialReadOnly || readOnly}
557562
disabled={disabled}
558563
/>
559564
</InputSection>
@@ -570,7 +575,7 @@ export function Component() {
570575
labelSelector={stringValueSelector}
571576
onChange={setFieldValue}
572577
error={error?.assessment_method}
573-
readOnly={partialReadonlyMode}
578+
readOnly={partialReadOnly || readOnly}
574579
disabled={disabled}
575580
/>
576581
</InputSection>
@@ -584,7 +589,7 @@ export function Component() {
584589
value={value?.assess_preparedness_of_country}
585590
onChange={setFieldValue}
586591
error={error?.assess_preparedness_of_country}
587-
readOnly={partialReadonlyMode}
592+
readOnly={partialReadOnly || readOnly}
588593
disabled={disabled}
589594
/>
590595
</InputSection>
@@ -598,7 +603,7 @@ export function Component() {
598603
value={value.assess_urban_aspect_of_country}
599604
onChange={setFieldValue}
600605
error={error?.assess_urban_aspect_of_country}
601-
readOnly={partialReadonlyMode}
606+
readOnly={partialReadOnly || readOnly}
602607
disabled={disabled}
603608
/>
604609
</InputSection>
@@ -613,7 +618,7 @@ export function Component() {
613618
value={value?.assess_climate_environment_of_country}
614619
onChange={setFieldValue}
615620
error={error?.assess_climate_environment_of_country}
616-
readOnly={partialReadonlyMode}
621+
readOnly={partialReadOnly || readOnly}
617622
disabled={disabled}
618623
/>
619624
</InputSection>
@@ -659,6 +664,7 @@ export function Component() {
659664
error={error?.workplan_development_date}
660665
onChange={setFieldValue}
661666
disabled={disabled}
667+
readOnly={readOnly}
662668
/>
663669
</InputSection>
664670
<InputSection
@@ -672,6 +678,7 @@ export function Component() {
672678
value={value?.workplan_revision_date}
673679
error={error?.workplan_revision_date}
674680
disabled={disabled}
681+
readOnly={readOnly}
675682
/>
676683
</InputSection>
677684
</Container>
@@ -695,6 +702,7 @@ export function Component() {
695702
onChange={setFieldValue}
696703
error={error?.ns_focal_point_name}
697704
disabled={disabled}
705+
readOnly={readOnly}
698706
/>
699707
<TextInput
700708
label={strings.focalPointEmailInputLabel}
@@ -703,6 +711,7 @@ export function Component() {
703711
onChange={setFieldValue}
704712
error={error?.ns_focal_point_email}
705713
disabled={disabled}
714+
readOnly={readOnly}
706715
/>
707716
<TextInput
708717
label={strings.focalPointPhoneNumberInputLabel}
@@ -711,6 +720,7 @@ export function Component() {
711720
onChange={setFieldValue}
712721
error={error?.ns_focal_point_phone}
713722
disabled={disabled}
723+
readOnly={readOnly}
714724
/>
715725
</InputSection>
716726
<InputSection
@@ -726,6 +736,7 @@ export function Component() {
726736
onChange={setFieldValue}
727737
error={error?.ns_second_focal_point_name}
728738
disabled={disabled}
739+
readOnly={readOnly}
729740
/>
730741
<TextInput
731742
label={strings.focalPointEmailInputLabel}
@@ -734,6 +745,7 @@ export function Component() {
734745
onChange={setFieldValue}
735746
error={error?.ns_second_focal_point_email}
736747
disabled={disabled}
748+
readOnly={readOnly}
737749
/>
738750
<TextInput
739751
label={strings.focalPointPhoneNumberInputLabel}
@@ -742,6 +754,7 @@ export function Component() {
742754
onChange={setFieldValue}
743755
error={error?.ns_second_focal_point_phone}
744756
disabled={disabled}
757+
readOnly={readOnly}
745758
/>
746759
</InputSection>
747760
<InputSection
@@ -756,6 +769,7 @@ export function Component() {
756769
onChange={setFieldValue}
757770
error={error?.partner_focal_point_name}
758771
disabled={disabled}
772+
readOnly={readOnly}
759773
/>
760774
<TextInput
761775
label={strings.focalPointEmailInputLabel}
@@ -764,6 +778,7 @@ export function Component() {
764778
onChange={setFieldValue}
765779
error={error?.partner_focal_point_email}
766780
disabled={disabled}
781+
readOnly={readOnly}
767782
/>
768783
<TextInput
769784
label={strings.focalPointPhoneNumberInputLabel}
@@ -772,6 +787,7 @@ export function Component() {
772787
onChange={setFieldValue}
773788
error={error?.partner_focal_point_phone}
774789
disabled={disabled}
790+
readOnly={readOnly}
775791
/>
776792
<TextInput
777793
label={strings.focalPointOrganizationInputLabel}
@@ -780,6 +796,7 @@ export function Component() {
780796
onChange={setFieldValue}
781797
error={error?.partner_focal_point_organization}
782798
disabled={disabled}
799+
readOnly={readOnly}
783800
/>
784801
</InputSection>
785802
<InputSection
@@ -794,6 +811,7 @@ export function Component() {
794811
onChange={setFieldValue}
795812
error={error?.facilitator_name}
796813
disabled={disabled}
814+
readOnly={readOnly}
797815
/>
798816
<TextInput
799817
label={strings.focalPointEmailInputLabel}
@@ -802,6 +820,7 @@ export function Component() {
802820
onChange={setFieldValue}
803821
error={error?.facilitator_email}
804822
disabled={disabled}
823+
readOnly={readOnly}
805824
/>
806825
<TextInput
807826
label={strings.focalPointPhoneNumberInputLabel}
@@ -810,6 +829,7 @@ export function Component() {
810829
onChange={setFieldValue}
811830
error={error?.facilitator_phone}
812831
disabled={disabled}
832+
readOnly={readOnly}
813833
/>
814834
<TextInput
815835
label={strings.otherContactMethodInputLabel}
@@ -818,6 +838,7 @@ export function Component() {
818838
onChange={setFieldValue}
819839
error={error?.facilitator_contact}
820840
disabled={disabled}
841+
readOnly={readOnly}
821842
/>
822843
</InputSection>
823844
</Container>

app/src/views/PerPrioritizationForm/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function Component() {
7979
statusResponse,
8080
refetchStatusResponse,
8181
actionDivRef,
82+
readOnly: readOnlyFromContext,
8283
} = useOutletContext<PerProcessOutletContext>();
8384

8485
const {
@@ -335,7 +336,8 @@ export function Component() {
335336
);
336337

337338
const currentPerStep = statusResponse?.phase;
338-
const readOnlyMode = isNotDefined(currentPerStep)
339+
const readOnlyMode = readOnlyFromContext
340+
|| isNotDefined(currentPerStep)
339341
|| currentPerStep < PER_PHASE_PRIORITIZATION;
340342

341343
const sortedFormComponents = useMemo(

0 commit comments

Comments
 (0)