Skip to content

Commit

Permalink
Merge pull request #1037 from CruGlobal/MPDX-8154
Browse files Browse the repository at this point in the history
MPDX-8154 Add Contact Button and fix Star filtering
  • Loading branch information
dr-bizz committed Sep 9, 2024
2 parents 3d9d163 + 44b0b48 commit 4ef692e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ const router = {
isReady: true,
};

const Components = () => (
interface ComponentsProps {
appealStatus?: AppealStatusEnum;
}

const Components = ({
appealStatus = AppealStatusEnum.Processed,
}: ComponentsProps) => (
<SnackbarProvider>
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={theme}>
Expand All @@ -59,7 +65,7 @@ const Components = () => (
title={title}
onContactSelected={onContactSelected}
changeContactStatus={changeContactStatus}
appealStatus={AppealStatusEnum.Processed}
appealStatus={appealStatus}
/>
</VirtuosoMockContext.Provider>
</AppealsWrapper>
Expand Down Expand Up @@ -95,4 +101,24 @@ describe('ContactFlowColumn', () => {
getByRole('menuitem', { name: 'Select 1 contact' });
});
});

it('"asked" column should has the "Add Contact to Appeal" button', async () => {
const { findByText } = render(
<Components appealStatus={AppealStatusEnum.Asked} />,
);

expect(await findByText('Add Contact to Appeal')).toBeInTheDocument();

userEvent.click(await findByText('Add Contact to Appeal'));

expect(await findByText('Add Contact(s) to Appeal')).toBeInTheDocument();
});

it('other columns should not have the "Add Contact to Appeal" button', async () => {
const { findByText, queryByText } = render(<Components />);

expect(await findByText(title)).toBeInTheDocument();

expect(queryByText('Add Contact to Appeal')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React, { useRef, useState } from 'react';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import {
Box,
Button,
Card,
CircularProgress,
IconButton,
Menu,
MenuItem,
Typography,
} from '@mui/material';
import { styled } from '@mui/material/styles';
import { useDrop } from 'react-dnd';
import { useTranslation } from 'react-i18next';
import {
Expand All @@ -28,13 +30,23 @@ import {
} from 'src/components/Tool/Appeal/AppealsContext/AppealsContext';
import { appealHeaderInfoHeight } from '../../AppealDetails/AppealHeaderInfo/AppealHeaderInfo';
import { useContactsQuery } from '../../AppealsContext/contacts.generated';
import {
DynamicAddContactToAppealModal,
preloadAddContactToAppealModal,
} from '../../Modals/AddContactToAppealModal/DynamicAddContactToAppealModal';
import { useExcludedAppealContactsQuery } from '../../Shared/AppealExcludedContacts.generated';
import { ContactFlowDropZone } from '../ContactFlowDropZone/ContactFlowDropZone';
import {
ContactFlowRow,
DraggedContact,
} from '../ContactFlowRow/ContactFlowRow';

const AddContactToAppealBox = styled(Box)(({ theme }) => ({
padding: theme.spacing(1),
height: '52px',
background: '#fff',
}));

interface Props
extends Omit<
ContactFlowColumnProps,
Expand All @@ -56,19 +68,21 @@ export const ContactFlowColumn: React.FC<Props> = ({
onContactSelected,
changeContactStatus,
}) => {
const { appealId, sanitizedFilters } = React.useContext(
const { appealId, sanitizedFilters, starredFilter } = React.useContext(
AppealsContext,
) as AppealsType;
const { t } = useTranslation();

const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [addContactsModalOpen, setAddContactsModalOpen] = useState(false);
const open = Boolean(anchorEl);

const { data, loading, fetchMore } = useContactsQuery({
variables: {
accountListId: accountListId ?? '',
contactsFilters: {
...sanitizedFilters,
...starredFilter,
appeal: [appealId ?? ''],
appealStatus,
wildcardSearch: searchTerm as string,
Expand Down Expand Up @@ -111,6 +125,10 @@ export const ContactFlowColumn: React.FC<Props> = ({
// TODO implement deselect all
};

const handleAddContactToAppeal = () => {
setAddContactsModalOpen(true);
};

const totalContacts = data?.contacts.totalCount || 0;

return loading && !data ? (
Expand Down Expand Up @@ -162,6 +180,7 @@ export const ContactFlowColumn: React.FC<Props> = ({
<StyledCardContent
style={{
height: `calc(100vh - ${navBarHeight} - ${headerHeight} - ${appealHeaderInfoHeight} - 87px)`,
padding: 0,
}}
>
<CardContentInner
Expand All @@ -174,7 +193,15 @@ export const ContactFlowColumn: React.FC<Props> = ({
changeContactStatus={changeContactStatus}
/>
</CardContentInner>
<Box ref={cardContentRef} width="100%" height="100%">
<Box
ref={cardContentRef}
width="100%"
height={
appealStatus === AppealStatusEnum.Asked
? 'calc(100% - 52px)'
: '100%'
}
>
<InfiniteList
loading={loading}
data={data?.contacts.nodes}
Expand All @@ -199,7 +226,25 @@ export const ContactFlowColumn: React.FC<Props> = ({
EmptyPlaceholder={undefined}
/>
</Box>
{appealStatus === AppealStatusEnum.Asked && (
<AddContactToAppealBox>
<Button
fullWidth
variant="outlined"
onClick={handleAddContactToAppeal}
onMouseEnter={preloadAddContactToAppealModal}
>
{t('Add Contact to Appeal')}
</Button>
</AddContactToAppealBox>
)}
</StyledCardContent>

{addContactsModalOpen && (
<DynamicAddContactToAppealModal
handleClose={() => setAddContactsModalOpen(false)}
/>
)}
</Card>
);
};

0 comments on commit 4ef692e

Please sign in to comment.