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-8344 Tools Sources #1118

Merged
merged 15 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion src/components/Tool/FixMailingAddresses/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
LockIcon,
} from 'src/components/Contacts/ContactDetails/ContactDetailsTab/StyledComponents';
import { useContactPartnershipStatuses } from 'src/hooks/useContactPartnershipStatuses';
import useGetAppSettings from 'src/hooks/useGetAppSettings';
import { useLocale } from 'src/hooks/useLocale';
import { useUpdateCache } from 'src/hooks/useUpdateCache';
import { dateFormatShort } from 'src/lib/intlFormat';
Expand Down Expand Up @@ -141,6 +142,7 @@ const Contact: React.FC<Props> = ({
useSetContactPrimaryAddressMutation();
const { update } = useUpdateCache(id);
const { contactStatuses } = useContactPartnershipStatuses();
const { appName } = useGetAppSettings();

const handleSetPrimaryContact = async (address: ContactAddressFragment) => {
await setContactPrimaryAddress({
Expand Down Expand Up @@ -339,7 +341,9 @@ const Contact: React.FC<Props> = ({
onClick={() => openNewAddressModal(newAddress, id)}
>
<AddIcon />
<AddText variant="subtitle1">{t('Add Address')}</AddText>
<AddText variant="subtitle1">
{t('Add Address ({{appName}})', { appName })}
</AddText>
</AddButton>
</Box>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SnackbarProvider } from 'notistack';
import TestRouter from '__tests__/util/TestRouter';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { CreateContactAddressMutation } from 'src/components/Contacts/ContactDetails/ContactDetailsTab/Mailing/AddAddressModal/CreateContactAddress.generated';
import { AppSettingsProvider } from 'src/components/common/AppSettings/AppSettingsProvider';
import theme from 'src/theme';
import FixMailingAddresses from './FixMailingAddresses';
import {
Expand Down Expand Up @@ -44,24 +45,26 @@ const Components = ({
mocks: ApolloErgonoMockMap;
cache?: ApolloCache<object>;
}) => (
<SnackbarProvider>
<TestRouter router={router}>
<ThemeProvider theme={theme}>
<GqlMockedProvider<{
InvalidAddresses: InvalidAddressesQuery;
CreateContactAddress: CreateContactAddressMutation;
}>
mocks={mocks}
cache={cache}
>
<FixMailingAddresses
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</ThemeProvider>
</TestRouter>
</SnackbarProvider>
<AppSettingsProvider>
<SnackbarProvider>
<TestRouter router={router}>
<ThemeProvider theme={theme}>
<GqlMockedProvider<{
InvalidAddresses: InvalidAddressesQuery;
CreateContactAddress: CreateContactAddressMutation;
}>
mocks={mocks}
cache={cache}
>
<FixMailingAddresses
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</ThemeProvider>
</TestRouter>
</SnackbarProvider>
</AppSettingsProvider>
);

describe('FixMailingAddresses', () => {
Expand Down Expand Up @@ -321,7 +324,7 @@ describe('FixMailingAddresses', () => {

await waitFor(() => {
expect(
getByRole('heading', { name: 'Add Address' }),
getByRole('heading', { name: 'Add Address (MPDX)' }),
).toBeInTheDocument();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const useStyles = makeStyles()(() => ({
}));
export const emptyAddress: ContactAddressFragment = {
id: 'new',
source: manualSourceValue,
source: '',
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
street: '',
region: '',
location: '',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tool/FixPhoneNumbers/FixPhoneNumbers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const FixPhoneNumbers: React.FC<Props> = ({
[key: string]: PhoneNumberData;
}>({});

const [defaultSource, setDefaultSource] = useState<string>(manualSourceValue);
const [defaultSource, setDefaultSource] = useState(manualSourceValue);
const [sourceOptions, setSourceOptions] = useState([manualSourceValue]);
const [showBulkConfirmModal, setShowBulkConfirmModal] = useState(false);

Expand Down
8 changes: 2 additions & 6 deletions src/utils/sourceHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ describe('Sources-Helpers', () => {

describe('sourcesMatch()', () => {
it('default', () => {
expect(sourcesMatch('manual', 'manual')).toBe(true);
expect(sourcesMatch('Siebel', 'Siebel')).toBe(true);
expect(sourcesMatch('MPDX', 'MPDX')).toBe(true);
expect(sourcesMatch('Siebel', undefined)).toBe(false);
expect(sourcesMatch('manual', 'random custom')).toBe(false);
});
it('matches sources with the old MPDX database value', () => {
expect(sourcesMatch('manual', 'MPDX')).toBe(true);
expect(sourcesMatch('MDPX', 'random custom')).toBe(false);
});
});

Expand Down
14 changes: 4 additions & 10 deletions src/utils/sourceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { TFunction } from 'react-i18next';

const appName = process.env.APP_NAME ?? 'MPDX';

// This value should be used in the database for a custom/manual source. Like when the user creates a new email, phone number, address, etc.
export const manualSourceValue = 'manual';
// In the past, 'MPDX' was saved to the database as the source for manual entries.
export const oldManualSourceValue = 'MPDX';
// This value is what the API sets as the source for new data created from MPDX. For example when the user creates a new email, phone number, address, etc.
export const manualSourceValue = 'MPDX';

export const sourceToStr = (
t: TFunction,
Expand All @@ -16,7 +14,6 @@ export const sourceToStr = (
return t('US Donation Services');
case 'DataServer':
return t('DonorHub');
case 'manual':
case 'MPDX':
return appName;
case 'TntImport':
Expand All @@ -28,7 +25,7 @@ export const sourceToStr = (
}
};

export const editableSources = ['MPDX', 'manual', 'TntImport'];
export const editableSources = ['MPDX', 'TntImport'];

export const isEditableSource = (source: string | undefined): boolean => {
// A source is editable if it is undefined or if it is in the list of editable sources.
Expand All @@ -43,8 +40,5 @@ export const sourcesMatch = (
defaultSource: string | undefined,
itemSource: string | undefined,
): boolean => {
return (
itemSource === defaultSource ||
(defaultSource === manualSourceValue && itemSource === oldManualSourceValue)
);
return itemSource === defaultSource;
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
};
Loading