Skip to content

Commit

Permalink
OM-345: removee redundant state
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Oct 23, 2024
1 parent af083c8 commit 50e915f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/components/WorkerImportDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ function WorkerImportDialog({
onChange={(event) => setImportPlan(event.target.value)}
>
{WORKER_IMPORT_PLANS.map(({ value, labelKey }) => (
<>
<FormControlLabel
key={value}
value={value}
control={<Radio color="primary" />}
label={formatMessage(labelKey)}
/>
{importPlan === WORKER_IMPORT_GROUP_OF_WORKERS && <GroupPicker onChange={handleGroupChange} />}
</>
<FormControlLabel
key={value}
value={value}
control={<Radio color="primary" />}
label={formatMessage(labelKey)}
/>
))}
{importPlan === WORKER_IMPORT_GROUP_OF_WORKERS && (
<GroupPicker onChange={handleGroupChange} currentGroup={currentGroup} />
)}
</RadioGroup>
</DialogContent>
<Divider />
Expand Down
9 changes: 3 additions & 6 deletions src/pickers/GroupPicker.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useState, useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';
import { useSelector, useDispatch } from 'react-redux';

import { useModulesManager, useTranslations, Autocomplete } from '@openimis/fe-core';
import { fetchGroupsAction } from '../actions';
import { ADMIN_RIGHT, MODULE_NAME } from '../constants';

function GroupPicker({
withLabel = true, withPlaceholder = true, label, onChange,
withLabel = true, withPlaceholder = true, label, onChange, currentGroup,
}) {
const modulesManager = useModulesManager();
const dispatch = useDispatch();
Expand All @@ -18,8 +18,6 @@ function GroupPicker({
const { economicUnit } = useSelector((state) => state.policyHolder);
const rights = useSelector((state) => state.core?.user?.i_user?.rights ?? []);

const [group, setGroup] = useState(null);

const isAdmin = useMemo(() => rights.includes(ADMIN_RIGHT), [rights]);

useEffect(() => {
Expand All @@ -36,7 +34,6 @@ function GroupPicker({

const handleChange = (selectedGroup) => {
onChange(selectedGroup);
setGroup(selectedGroup);
};

return (
Expand All @@ -48,7 +45,7 @@ function GroupPicker({
options={groups}
isLoading={fetchingGroups}
isFetched={fetchedGroups}
value={group}
value={currentGroup}
getOptionLabel={groupLabel}
onChange={handleChange}
onInputChange={() => {}}
Expand Down
4 changes: 2 additions & 2 deletions src/pickers/WorkerMultiplePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ function WorkerMultiplePicker({
const handleImport = () => {
setConfigurationDialogOpen(false);

const currentWorkersSet = new Set(value.map((worker) => worker.id));
const currentWorkersSet = new Set(value.map((worker) => worker.uuid));
const importedWorkers = importPlanWorkers(importPlan);
const uniqueImportedWorkers = importedWorkers.filter((worker) => !currentWorkersSet.has(worker.id));
const uniqueImportedWorkers = importedWorkers.filter((worker) => !currentWorkersSet.has(worker.uuid));
const updatedWorkers = [...value, ...uniqueImportedWorkers];

onChange(null, updatedWorkers);
Expand Down

0 comments on commit 50e915f

Please sign in to comment.