Skip to content

Commit

Permalink
update callback names for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 3, 2023
1 parent b946cca commit 1b6cb98
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/DonorsList/AddDonorButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
visibleFilters,
} from './constants';

const AddDonorButton = ({ fetchDonors, fields, stripes, name }) => {
const AddDonorButton = ({ onAddDonors, fields, stripes, name }) => {
const addDonors = (donors = []) => {
const addedDonorIds = new Set(fields.value);
const newDonorsIds = map(donors.filter(({ id }) => !addedDonorIds.has(id)), 'id');

if (newDonorsIds.length) {
fetchDonors([...addedDonorIds, ...newDonorsIds]);
onAddDonors([...addedDonorIds, ...newDonorsIds]);
newDonorsIds.forEach(contactId => fields.push(contactId));
}
};
Expand Down Expand Up @@ -51,7 +51,7 @@ const AddDonorButton = ({ fetchDonors, fields, stripes, name }) => {
};

AddDonorButton.propTypes = {
fetchDonors: PropTypes.func.isRequired,
onAddDonors: PropTypes.func.isRequired,
fields: PropTypes.object,
stripes: PropTypes.object,
name: PropTypes.string.isRequired,
Expand Down
8 changes: 2 additions & 6 deletions lib/DonorsList/DonorsContainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { FieldArray } from 'react-final-form-arrays';

Expand All @@ -15,10 +15,6 @@ function DonorsContainer({ name, donorOrganizationIds }) {
const [donorIds, setDonorIds] = useState(() => donorOrganizationIds);
const { donors, isLoading } = useFetchDonors(donorIds);

const handleFetchDonors = useCallback(ids => {
setDonorIds(ids);
}, []);

const donorsMap = donors.reduce((acc, contact) => {
acc[contact.id] = contact;

Expand All @@ -36,7 +32,7 @@ function DonorsContainer({ name, donorOrganizationIds }) {
name={name}
id={name}
component={DonorsList}
fetchDonors={handleFetchDonors}
setDonorIds={setDonorIds}
donorsMap={donorsMap}
/>
</Col>
Expand Down
6 changes: 3 additions & 3 deletions lib/DonorsList/DonorsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const getResultsFormatter = ({
),
});

const DonorsList = ({ fetchDonors, fields, donorsMap, id }) => {
const DonorsList = ({ setDonorIds, fields, donorsMap, id }) => {
const intl = useIntl();
const stripes = useStripes();
const canViewOrganizations = stripes.hasPerm('ui-organizations.view');
Expand Down Expand Up @@ -82,7 +82,7 @@ const DonorsList = ({ fetchDonors, fields, donorsMap, id }) => {
/>
<br />
<AddDonorButton
fetchDonors={fetchDonors}
onAddDonors={setDonorIds}
fields={fields}
stripes={stripes}
name={id}
Expand All @@ -92,7 +92,7 @@ const DonorsList = ({ fetchDonors, fields, donorsMap, id }) => {
};

DonorsList.propTypes = {
fetchDonors: PropTypes.func.isRequired,
setDonorIds: PropTypes.func.isRequired,
fields: PropTypes.object,
donorsMap: PropTypes.object,
id: PropTypes.string.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions lib/DonorsList/DonorsList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { render, screen } from '@testing-library/react';

import DonorsList from './DonorsList';

const mockFetchDonors = jest.fn();
const mockSetDonorIds = jest.fn();

const defaultProps = {
fetchDonors: mockFetchDonors,
setDonorIds: mockSetDonorIds,
fields: {},
donorsMap: {},
id: 'donors',
Expand Down

0 comments on commit 1b6cb98

Please sign in to comment.