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

MPDX-7933 Tools Fix Mailing Address - Primary Contact Star #957

Merged
merged 21 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5b2d349
Adding the ability to allow custom cache updates after mutation.
dr-bizz Jun 12, 2024
3e30b78
Refactor state props and how we handle Modal open and close
dr-bizz Jun 12, 2024
fd46a83
Adding custom cache updates to modals
dr-bizz Jun 12, 2024
9343e8d
No longer need to return a boolean for handleClose as custom cache fu…
dr-bizz Jun 12, 2024
1fab9fe
Replacing add button with new add button.
dr-bizz Jun 12, 2024
32956f7
Fix key error causing console errors
dr-bizz Jun 12, 2024
1a08da9
Fixing error with updating cache
dr-bizz Jun 13, 2024
b9bcd54
Adding tests for Edi and add mailing address modals and functionality.
dr-bizz Jun 13, 2024
69c2386
Adding Dynamic components
dr-bizz Jun 13, 2024
402f45a
improving tests
dr-bizz Jun 13, 2024
8b41fb0
fixup! improving tests
dr-bizz Jun 13, 2024
b50045a
Merge branch 'main' into MPDX-7935-add-mailing-address
dr-bizz Jun 13, 2024
1adcbf6
REmoving MPDX name and padding/margin
dr-bizz Jun 14, 2024
68f4d9c
Adding set Primary Contact functionality
dr-bizz Jun 14, 2024
03ddd90
Adding tests
dr-bizz Jun 14, 2024
f303fb3
Allow for TNT (DataServer) data to be edited in MPDX as it's imported…
dr-bizz Jun 14, 2024
98084ae
Moving useUpdateCache to hooks folder as more components are using it.
dr-bizz Jun 14, 2024
8480284
Only MPDX, TNT and manually address are now editable
dr-bizz Jun 14, 2024
6343904
Fixing failing test due to new changes with what source can be edited
dr-bizz Jun 14, 2024
7575b9d
Merge branch 'MPDX-7935-add-mailing-address' into MPDX-7933-primary-c…
dr-bizz Jun 14, 2024
0b4cb7f
Merge branch 'MPDX-7935-add-mailing-address' into MPDX-7933-primary-c…
dr-bizz Jun 17, 2024
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 @@ -23,6 +23,7 @@ import {
SubmitButton,
} from 'src/components/common/Modal/ActionButtons/ActionButtons';
import { AddressCreateInput } from 'src/graphql/types.generated';
import { useUpdateCache } from 'src/hooks/useUpdateCache';
import Modal from '../../../../../common/Modal/Modal';
import {
ContactDetailsTabDocument,
Expand All @@ -34,7 +35,6 @@ import {
} from '../AddressLocation';
import { useSetContactPrimaryAddressMutation } from '../SetPrimaryAddress.generated';
import { StreetAutocomplete } from '../StreetAutocomplete/StreetAutocomplete';
import { useUpdateCache } from '../useUpdateCache';
import { useCreateContactAddressMutation } from './CreateContactAddress.generated';
import { createAddressSchema } from './createAddressSchema';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SubmitButton,
} from 'src/components/common/Modal/ActionButtons/ActionButtons';
import { AddressUpdateInput } from 'src/graphql/types.generated';
import { useUpdateCache } from 'src/hooks/useUpdateCache';
import Modal from '../../../../../common/Modal/Modal';
import {
ContactDetailsTabDocument,
Expand All @@ -39,7 +40,6 @@ import {
import { ContactMailingFragment } from '../ContactMailing.generated';
import { useSetContactPrimaryAddressMutation } from '../SetPrimaryAddress.generated';
import { StreetAutocomplete } from '../StreetAutocomplete/StreetAutocomplete';
import { useUpdateCache } from '../useUpdateCache';
import {
useDeleteContactAddressMutation,
useDonationServicesEmailQuery,
Expand Down
64 changes: 55 additions & 9 deletions src/components/Tool/FixMailingAddresses/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
Card,
CardContent,
CardHeader,
CircularProgress,
Grid,
Hidden,
IconButton,
Typography,
} from '@mui/material';
import clsx from 'clsx';
import { DateTime } from 'luxon';
import { useSnackbar } from 'notistack';
import { useTranslation } from 'react-i18next';
import { makeStyles } from 'tss-react/mui';
import { editableSources } from 'src/components/Contacts/ContactDetails/ContactDetailsTab/Mailing/EditContactAddressModal/EditContactAddressModal';
import { useSetContactPrimaryAddressMutation } from 'src/components/Contacts/ContactDetails/ContactDetailsTab/Mailing/SetPrimaryAddress.generated';
import {
AddButton,
AddIcon,
Expand All @@ -29,6 +32,7 @@
LockIcon,
} from 'src/components/Contacts/ContactDetails/ContactDetailsTab/StyledComponents';
import { useLocale } from 'src/hooks/useLocale';
import { useUpdateCache } from 'src/hooks/useUpdateCache';
import { dateFormatShort } from 'src/lib/intlFormat';
import { contactPartnershipStatus } from 'src/utils/contacts/contactPartnershipStatus';
import theme from '../../../theme';
Expand Down Expand Up @@ -122,10 +126,35 @@
}) => {
const { t } = useTranslation();
const locale = useLocale();
const { enqueueSnackbar } = useSnackbar();
const { classes } = useStyles();
const newAddress = { ...emptyAddress, newAddress: true };
//TODO: Add button functionality
//TODO: Make contact name a link to contact page
const [setContactPrimaryAddress, { loading: settingPrimaryAddress }] =
useSetContactPrimaryAddressMutation();
const { update } = useUpdateCache(id);

const handleSetPrimaryContact = async (address: ContactAddressFragment) => {
await setContactPrimaryAddress({
variables: {
contactId: id,
primaryAddressId: address.primaryMailingAddress ? null : address.id,
},
update,
onCompleted: () => {
enqueueSnackbar(t('Mailing information edited successfully'), {
variant: 'success',
});
},
onError: () => {
enqueueSnackbar(

Check warning on line 149 in src/components/Tool/FixMailingAddresses/Contact.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Tool/FixMailingAddresses/Contact.tsx#L148-L149

Added lines #L148 - L149 were not covered by tests
t('Error occurred while updating mailing information'),
{
variant: 'error',
},
);
},
});
};

return (
<Card className={classes.contactCard}>
Expand Down Expand Up @@ -191,13 +220,30 @@
</Typography>
</Grid>
<Grid item md={4} className={classes.alignCenter}>
<ContactIconContainer aria-label={t('Edit Icon')}>
{address.primaryMailingAddress ? (
<StarIcon className={classes.hoverHighlight} />
) : (
<StarOutlineIcon className={classes.hoverHighlight} />
)}
</ContactIconContainer>
{!settingPrimaryAddress && (
<ContactIconContainer
aria-label={t('Edit Icon')}
onClick={() => handleSetPrimaryContact(address)}
>
{address.primaryMailingAddress ? (
<StarIcon
className={classes.hoverHighlight}
data-testid="primaryContactStarIcon"
/>
) : (
<StarOutlineIcon
className={classes.hoverHighlight}
data-testid="contactStarIcon"
/>
)}
</ContactIconContainer>
)}
{settingPrimaryAddress && (
<CircularProgress
size={'20px'}
data-testid="settingPrimaryAddress"
/>
)}
</Grid>
</Box>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,42 @@ describe('FixSendNewsletter', () => {
);
}, 10000);
});
describe('Set primary mailing address', () => {
it('should set the address as primary', async () => {
const { getByTestId, getAllByTestId, queryByTestId, queryAllByTestId } =
render(
<Components
mocks={{
InvalidAddresses: {
...mockInvalidAddressesResponse.InvalidAddresses,
},
}}
/>,
);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);

const primaryAddress = getByTestId('primaryContactStarIcon');
const secondaryAddresses = getAllByTestId('contactStarIcon');

expect(primaryAddress).toBeInTheDocument();
expect(secondaryAddresses.length).toBe(2);

expect(queryAllByTestId('settingPrimaryAddress').length).toBe(0);

userEvent.click(secondaryAddresses[0]);

expect(getAllByTestId('settingPrimaryAddress').length).toBe(3);

await waitFor(() =>
expect(mockEnqueue).toHaveBeenCalledWith(
'Mailing information edited successfully',
{
variant: 'success',
},
),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ContactPrimaryAddressRelationFragmentDoc,
PrimaryMailingAddressFragmentDoc,
SetContactPrimaryAddressMutation,
} from './SetPrimaryAddress.generated';
} from 'src/components/Contacts/ContactDetails/ContactDetailsTab/Mailing/SetPrimaryAddress.generated';

// This hook provides an Apollo cache update function for the setContactPrimaryAddress mutation
// used by the add address and edit address modals
Expand Down
Loading