Skip to content

Commit

Permalink
feat: add to redux
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Nov 25, 2024
1 parent 87782ae commit e7614f1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const buildOrgUnitSettingsFn = () => {
label: i18n.t('Organisation unit'),
required: true,
}),
getPropName: () => 'orgUnit',
getPropName: () => 'orgUnitId',
getValidatorContainers: () => getOrgUnitValidatorContainers(),
getMeta: () => ({
placement: placements.TOP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { convertGeometryOut } from 'capture-core/components/DataEntries/converters';
import { loadNewDataEntry } from '../../../DataEntry/actions/dataEntryLoadNew.actions';
import { getEventDateValidatorContainers } from '../fieldValidators/eventDate.validatorContainersGetter';
import { getEventDateValidatorContainers, getOrgUnitValidatorContainers } from '../fieldValidators';
import { getNoteValidatorContainers } from '../fieldValidators/note.validatorContainersGetter';
import type { ProgramCategory } from '../../../WidgetEventSchedule/CategoryOptions/CategoryOptions.types';
import { getCategoryOptionsValidatorContainers } from '../fieldValidators/categoryOptions.validatorContainersGetter';
Expand All @@ -15,6 +15,11 @@ const dataEntryPropsToInclude: DataEntryPropsToInclude = [
type: 'DATE',
validatorContainers: getEventDateValidatorContainers(),
},
{
id: 'orgUnitId',
type: 'ORGANISATION_UNIT',
validatorContainers: getOrgUnitValidatorContainers(),
},
{
id: 'scheduledAt',
type: 'DATE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const OrgUnitFetcher = ({
return (
<Validated
{...passOnProps}
orgUnitCore={orgUnit}
orgUnit={orgUnit}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Validated = ({
onSaveExternal,
onSaveSuccessActionType,
onSaveErrorActionType,
orgUnitCore,
orgUnit,
teiId,
enrollmentId,
rulesExecutionDependencies,
Expand All @@ -42,23 +42,18 @@ export const Validated = ({
const dataEntryId = 'enrollmentEvent';
const itemId = 'newEvent';
const relatedStageRef = useRef<?RelatedStageRefPayload>(null);
const dataEntryKey = `${dataEntryId}-${itemId}`;
const dataEntryValues = useSelector(({ dataEntriesFieldsValue }) => dataEntriesFieldsValue[dataEntryKey]);
const orgUnitSelected = dataEntryValues?.orgUnit;
const orgUnit = orgUnitSelected || orgUnitCore;
const eventSaveInProgress = useSelector(
({ enrollmentDomain }) => !!enrollmentDomain.eventSaveInProgress?.requestEventId,
);
const { buildNewEventPayload } = useBuildNewEventPayload({
dataEntryId,
itemId,
programId: program.id,
orgUnitId: orgUnit.id,
orgUnitName: orgUnit.name,
teiId,
enrollmentId,
formFoundation,
dataEntryKey,
dataEntryValues,
orgUnit,
});

const rulesExecutionDependenciesClientFormatted =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { getConvertedRelatedStageEvent } from './getConvertedRelatedStageEvent';
import type { LinkedRequestEvent, RelatedStageRefPayload, RequestEvent } from './validated.types';

type Props = {
dataEntryId: string,
itemId: string,
orgUnitId: string,
programId: string,
formFoundation: RenderFoundation,
enrollmentId: string,
orgUnitName: string,
teiId: string,
dataEntryKey: string,
dataEntryValues: Object,
orgUnit: Object,
};

export const createServerData = ({
Expand Down Expand Up @@ -48,16 +49,19 @@ export const createServerData = ({
};

export const useBuildNewEventPayload = ({
dataEntryId,
itemId,
orgUnitId,
programId,
teiId,
enrollmentId,
orgUnitName,
formFoundation,
dataEntryKey,
dataEntryValues,
orgUnit,
}: Props) => {
const { serverVersion: { minor } } = useConfig();
const dataEntryKey = `${dataEntryId}-${itemId}`;
const formValues = useSelector(({ formsValues }) => formsValues[dataEntryKey]);
const dataEntryValues = useSelector(({ dataEntriesFieldsValue }) => dataEntriesFieldsValue[dataEntryKey]);
const dataEntryValuesMeta = useSelector(({ dataEntriesFieldsMeta }) => dataEntriesFieldsMeta[dataEntryKey]);
const notes = useSelector(({ dataEntriesNotes }) => dataEntriesNotes[dataEntryKey]);
const { fromClientDate } = useTimeZoneConversion();
Expand Down Expand Up @@ -135,10 +139,10 @@ export const useBuildNewEventPayload = ({
eventId: requestEventId,
mainDataClientValues: { ...dataEntryClientValues, notes: notesValues },
programId,
orgUnitId: orgUnit.id,
orgUnitId,
enrollmentId,
teiId,
orgUnitName: orgUnit.name,
orgUnitName,
completed: saveType === addEventSaveTypes.COMPLETE,
fromClientDate,
serverMinorVersion: minor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type RelatedStageRefPayload = {|

export type ContainerProps = {|
...CommonValidatedProps,
orgUnitCore: OrgUnit,
orgUnit: OrgUnit,
|};

export type Props = {|
Expand Down

0 comments on commit e7614f1

Please sign in to comment.