From 0159c59538ac98628c4d480b58f52726372f39c8 Mon Sep 17 00:00:00 2001 From: Shreeyash Shrestha Date: Thu, 25 Sep 2025 12:36:54 +0545 Subject: [PATCH] feat(dref-translation): use finalize api in dref table and add view mode in all dref forms --- .../domain/ImageWithCaptionInput/index.tsx | 4 + .../domain/LanguageMismatchMessage/i18n.json | 6 +- .../domain/LanguageMismatchMessage/index.tsx | 17 +-- .../MultiImageWithCaptionInput/index.tsx | 6 +- .../domain/SourceInformationInput/index.tsx | 6 +- app/src/utils/constants.ts | 2 +- .../DrefTableActions/i18n.json | 4 + .../DrefTableActions/index.tsx | 137 +++++++++++++++++- .../DrefApplicationForm/Actions/index.tsx | 24 ++- .../DrefApplicationForm/EventDetail/index.tsx | 35 ++++- .../IndicatorInput/index.tsx | 6 +- .../Operation/InterventionInput/index.tsx | 10 +- .../ActivitiesInput/index.tsx | 5 +- .../Operation/ProposedActionsInput/index.tsx | 6 + .../Operation/RiskSecurityInput/index.tsx | 6 +- .../DrefApplicationForm/Operation/index.tsx | 45 +++++- .../Overview/CopyFieldReportSection/index.tsx | 4 + .../DrefApplicationForm/Overview/index.tsx | 18 +++ .../DrefApplicationForm/Submission/index.tsx | 38 +++++ app/src/views/DrefApplicationForm/i18n.json | 2 +- app/src/views/DrefApplicationForm/index.tsx | 25 ++-- .../Actions/NeedInput/index.tsx | 5 +- .../DrefFinalReportForm/Actions/index.tsx | 16 +- .../DrefFinalReportForm/EventDetail/index.tsx | 15 +- .../IndicatorInput/index.tsx | 4 + .../Operation/InterventionInput/index.tsx | 16 +- .../ActivitiesInput/index.tsx | 5 +- .../Operation/ProposedActionsInput/index.tsx | 7 + .../Operation/RiskSecurityInput/index.tsx | 6 +- .../DrefFinalReportForm/Operation/index.tsx | 41 +++++- .../DrefFinalReportForm/Overview/index.tsx | 16 +- .../DrefFinalReportForm/Submission/index.tsx | 36 +++++ app/src/views/DrefFinalReportForm/i18n.json | 2 +- app/src/views/DrefFinalReportForm/index.tsx | 16 +- .../Actions/NeedInput/index.tsx | 5 +- .../Actions/index.tsx | 16 +- .../EventDetail/index.tsx | 26 +++- .../IndicatorInput/index.tsx | 7 +- .../Operation/InterventionInput/index.tsx | 13 +- .../Operation/RiskSecurityInput/index.tsx | 6 +- .../Operation/index.tsx | 40 ++++- .../Overview/index.tsx | 16 +- .../Submission/index.tsx | 38 +++++ .../views/DrefOperationalUpdateForm/i18n.json | 2 +- .../views/DrefOperationalUpdateForm/index.tsx | 24 ++- app/src/views/FieldReportForm/index.tsx | 1 + app/src/views/FlashUpdateForm/index.tsx | 1 + .../Actions/NeedInput/index.tsx | 5 +- .../OldDrefFinalReportForm/Actions/index.tsx | 16 +- .../EventDetail/index.tsx | 16 +- .../IndicatorInput/index.tsx | 5 +- .../Operation/InterventionInput/index.tsx | 16 +- .../Operation/RiskSecurityInput/index.tsx | 6 +- .../Operation/index.tsx | 36 ++++- .../OldDrefFinalReportForm/Overview/index.tsx | 16 +- .../Submission/index.tsx | 36 +++++ .../views/OldDrefFinalReportForm/index.tsx | 18 ++- app/src/views/PerProcessForm/index.tsx | 1 + app/src/views/ThreeWActivityForm/index.tsx | 1 + .../000051-1758782876113.json | 65 +++++++++ 60 files changed, 936 insertions(+), 87 deletions(-) create mode 100644 translationMigrations/000051-1758782876113.json diff --git a/app/src/components/domain/ImageWithCaptionInput/index.tsx b/app/src/components/domain/ImageWithCaptionInput/index.tsx index 406a54690a..ec7c546902 100644 --- a/app/src/components/domain/ImageWithCaptionInput/index.tsx +++ b/app/src/components/domain/ImageWithCaptionInput/index.tsx @@ -30,6 +30,7 @@ interface Props { name: N; url: SupportedPaths; value: Value | null | undefined; + readOnly: boolean; onChange: (value: SetValueArg | undefined, name: N) => void; error: ObjectError | undefined; fileIdToUrlMap: Record; @@ -44,6 +45,7 @@ interface Props { function ImageWithCaptionInput(props: Props) { const { className, + readOnly, name, value, url, @@ -92,6 +94,7 @@ function ImageWithCaptionInput(props: Props) name="id" accept="image/*" value={value?.id} + readOnly={readOnly} onChange={handleFileInputChange} url={url} fileIdToUrlMap={fileIdToUrlMap} @@ -116,6 +119,7 @@ function ImageWithCaptionInput(props: Props) className={styles.captionInput} name="caption" value={value?.caption} + readOnly={readOnly} onChange={setFieldValue} error={error?.caption} placeholder={strings.imageWithCaptionEnterCaption} diff --git a/app/src/components/domain/LanguageMismatchMessage/i18n.json b/app/src/components/domain/LanguageMismatchMessage/i18n.json index cbf3857ced..fd8ba0f291 100644 --- a/app/src/components/domain/LanguageMismatchMessage/i18n.json +++ b/app/src/components/domain/LanguageMismatchMessage/i18n.json @@ -1,8 +1,8 @@ { "namespace": "languageMismatchMessage", "strings": { - "languageMismatchErrorTitle": "Edit not available in selected language!", - "languageMismatchErrorMessage": "This form was originally created in {originalLanguage} and cannot be edited in a different language!", - "languageMismatchHelpMessage": "Please change the language to {originalLanguage} to edit it!" + "languageMismatchErrorTitle": "Edit not available in {selectedLanguage} language!", + "languageMismatchErrorMessage": "This is because form was originally created in {originalLanguage} language and edits cannot be edited in the {selectedLanguage} language.", + "languageMismatchHelpMessage": "To make changes, please switch to the original language of the form." } } diff --git a/app/src/components/domain/LanguageMismatchMessage/index.tsx b/app/src/components/domain/LanguageMismatchMessage/index.tsx index 104a6a567b..6e37324f62 100644 --- a/app/src/components/domain/LanguageMismatchMessage/index.tsx +++ b/app/src/components/domain/LanguageMismatchMessage/index.tsx @@ -14,6 +14,7 @@ interface Props { // FIXME: typings should be fixed in the server // this should be of type Language originalLanguage: string | undefined; + selectedLanguage: Language; } function LanguageMismatchMessage(props: Props) { @@ -21,7 +22,8 @@ function LanguageMismatchMessage(props: Props) { const { title = strings.languageMismatchErrorTitle, - originalLanguage = 'en', + originalLanguage, + selectedLanguage, } = props; return ( @@ -32,16 +34,13 @@ function LanguageMismatchMessage(props: Props) { resolveToString( strings.languageMismatchErrorMessage, // FIXME: this should not require cast - { originalLanguage: languageNameMapEn[originalLanguage as Language] ?? '--' }, - ) - } - actions={ - resolveToString( - strings.languageMismatchHelpMessage, - // FIXME: this should not require cast - { originalLanguage: languageNameMapEn[originalLanguage as Language] ?? '--' }, + { + originalLanguage: languageNameMapEn[originalLanguage as Language] ?? '--', + selectedLanguage: languageNameMapEn[selectedLanguage] ?? '--', + }, ) } + actions={strings.languageMismatchHelpMessage} /> ); } diff --git a/app/src/components/domain/MultiImageWithCaptionInput/index.tsx b/app/src/components/domain/MultiImageWithCaptionInput/index.tsx index 9e7ba273a1..2f56e65e02 100644 --- a/app/src/components/domain/MultiImageWithCaptionInput/index.tsx +++ b/app/src/components/domain/MultiImageWithCaptionInput/index.tsx @@ -45,6 +45,7 @@ interface Props { label: React.ReactNode; icons?: React.ReactNode; actions?: React.ReactNode; + readOnly?: boolean; disabled?: boolean; } @@ -62,6 +63,7 @@ function MultiImageWithCaptionInput(props: Prop label, icons, actions, + readOnly, disabled, } = props; @@ -139,6 +141,7 @@ function MultiImageWithCaptionInput(props: Prop icons={icons} actions={actions} withoutPreview + readOnly={readOnly} disabled={disabled} > {label} @@ -168,7 +171,7 @@ function MultiImageWithCaptionInput(props: Prop ariaLabel={strings.removeImagesButtonTitle} variant="secondary" spacing="none" - disabled={disabled} + disabled={disabled || readOnly} > @@ -187,6 +190,7 @@ function MultiImageWithCaptionInput(props: Prop onChange={handleCaptionChange} error={imageError?.caption} placeholder={strings.enterCaptionPlaceholder} + readOnly={readOnly} disabled={disabled} /> diff --git a/app/src/components/domain/SourceInformationInput/index.tsx b/app/src/components/domain/SourceInformationInput/index.tsx index 8ee3a02713..33dc8dc73c 100644 --- a/app/src/components/domain/SourceInformationInput/index.tsx +++ b/app/src/components/domain/SourceInformationInput/index.tsx @@ -31,6 +31,7 @@ interface Props { onRemove: (index: number) => void; index: number; disabled?: boolean; + readOnly: boolean; } function SourceInformationInput(props: Props) { @@ -41,6 +42,7 @@ function SourceInformationInput(props: Props) { index, onRemove, disabled, + readOnly, } = props; const strings = useTranslation(i18n); @@ -92,6 +94,7 @@ function SourceInformationInput(props: Props) { value={value.source_name} error={error?.source_name} onChange={onFieldChange} + readOnly={readOnly} disabled={disabled} /> @@ -258,7 +263,7 @@ function Actions(props: Props) { onRemove={onNsActionRemove} error={getErrorObject(error?.national_society_actions)} titleDisplayMap={nsActionTitleDisplayMap} - disabled={disabled} + disabled={readOnly || disabled} /> ))} @@ -272,6 +277,7 @@ function Actions(props: Props) {