Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DHIS2-15945] translations in enrollment widget #3433

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { dataElementTypes } from '../../../metaData';
type Props = {
date: string,
dateLabel: string,
locale: string,
editEnabled: boolean,
displayAutoGeneratedEventWarning: boolean,
onSave: (string) => void,
Expand Down Expand Up @@ -66,6 +67,7 @@ const styles = {
const DateComponentPlain = ({
date,
dateLabel,
locale,
editEnabled,
displayAutoGeneratedEventWarning,
onSave,
Expand Down Expand Up @@ -103,6 +105,7 @@ const DateComponentPlain = ({
className={classes.calendar}
label={dateLabel}
date={selectedDate}
locale={locale}
onDateSelect={dateChangeHandler}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ const styles = {

const getGeometryType = geometryType =>
(geometryType === 'Point' ? dataElementTypes.COORDINATE : dataElementTypes.POLYGON);
const getEnrollmentDateLabel = program => program.enrollmentDateLabel || i18n.t('Enrollment date');
const getIncidentDateLabel = program => program.incidentDateLabel || i18n.t('Incident date');
const getEnrollmentDateLabel = program => program.displayEnrollmentDateLabel || i18n.t('Enrollment date');
const getIncidentDateLabel = program => program.displayIncidentDateLabel || i18n.t('Incident date');

export const WidgetEnrollmentPlain = ({
classes,
enrollment = {},
program = {},
ownerOrgUnit = {},
locale,
refetchEnrollment,
refetchTEI,
initError,
Expand Down Expand Up @@ -97,6 +98,7 @@ export const WidgetEnrollmentPlain = ({
<Date
date={enrollment.enrolledAt}
dateLabel={getEnrollmentDateLabel(program)}
locale={locale}
editEnabled={editDateEnabled}
displayAutoGeneratedEventWarning={displayAutoGeneratedEventWarning}
onSave={updateEnrollmentDate}
Expand All @@ -109,6 +111,7 @@ export const WidgetEnrollmentPlain = ({
<Date
date={enrollment.occurredAt}
dateLabel={getIncidentDateLabel(program)}
locale={locale}
editEnabled={editDateEnabled}
displayAutoGeneratedEventWarning={displayAutoGeneratedEventWarning}
onSave={updateIncidentDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useOrganizationUnit } from './hooks/useOrganizationUnit';
import { useTrackedEntityInstances } from './hooks/useTrackedEntityInstances';
import { useEnrollment } from './hooks/useEnrollment';
import { useProgram } from './hooks/useProgram';
import { useUserLocale } from '../../utils/localeData/useUserLocale';
import type { Props } from './enrollment.types';
import { plainStatus } from './constants/status.const';

Expand Down Expand Up @@ -42,11 +43,12 @@ export const WidgetEnrollment = ({
refetch: refetchTEI,
} = useTrackedEntityInstances(teiId, programId);
const { error: errorOrgUnit, displayName } = useOrganizationUnit(ownerOrgUnit);
const { error: errorLocale, locale } = useUserLocale();
const canAddNew = enrollments
.filter(item => item.program === programId)
.every(item => item.status !== plainStatus.ACTIVE);
const containsAutoGeneratedEvent = program && program.programStages.some(({ autoGenerateEvent }) => autoGenerateEvent);
const error = errorEnrollment || errorProgram || errorOwnerOrgUnit || errorOrgUnit;
const error = errorEnrollment || errorProgram || errorOwnerOrgUnit || errorOrgUnit || errorLocale;

if (error) {
log.error(errorCreator('Enrollment widget could not be loaded')({ error }));
Expand All @@ -62,7 +64,8 @@ export const WidgetEnrollment = ({
refetchEnrollment={refetchEnrollment}
refetchTEI={refetchTEI}
ownerOrgUnit={{ id: ownerOrgUnit, displayName }}
loading={!(enrollment && program && displayName)}
locale={locale}
loading={!(enrollment && program && displayName && locale)}
onDelete={onDelete}
onAddNew={onAddNew}
updateEnrollmentDate={updateEnrollmentDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type PlainProps = {|
enrollment: Object,
program: Object,
ownerOrgUnit: Object,
locale: string,
refetchEnrollment: QueryRefetchFunction,
refetchTEI: QueryRefetchFunction,
initError?: FetchError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useProgram = (programId: string) => {
resource: `programs/${programId}`,
params: {
fields: [
'displayIncidentDate,incidentDateLabel,enrollmentDateLabel,onlyEnrollOnce,trackedEntityType[displayName],programStages[autoGenerateEvent],access',
'displayIncidentDate,displayIncidentDateLabel,displayEnrollmentDateLabel,onlyEnrollOnce,trackedEntityType[displayName],programStages[autoGenerateEvent],access',
],
},
},
Expand Down
Loading