diff --git a/src/components/Dashboard/ThisWeek/GetThisWeek.graphql b/src/components/Dashboard/ThisWeek/GetThisWeek.graphql index dc5ee0941..4fa81f681 100644 --- a/src/components/Dashboard/ThisWeek/GetThisWeek.graphql +++ b/src/components/Dashboard/ThisWeek/GetThisWeek.graphql @@ -1,7 +1,7 @@ query GetThisWeek( $accountListId: ID! $endOfDay: ISO8601DateTime! - $today: ISO8601Date! + $thirtyDaysAgo: ISO8601Date! $threeWeeksFromNow: ISO8601Date! $twoWeeksAgo: ISO8601Date! ) { @@ -60,7 +60,7 @@ query GetThisWeek( accountListId: $accountListId first: 3 contactsFilter: { - lateAt: { max: $today } + lateAt: { max: $thirtyDaysAgo } status: PARTNER_FINANCIAL pledgeReceived: RECEIVED } diff --git a/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.test.tsx b/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.test.tsx index a533e7dff..980093d89 100644 --- a/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.test.tsx +++ b/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.test.tsx @@ -38,29 +38,6 @@ describe('LateCommitments', () => { nodes: [], totalCount: 0, }; - emptyCheck(latePledgeContacts); - }); - - it('should show empty if all of the late pledges are under 7 days late', () => { - const latePledgeContacts = { - nodes: [ - { - id: 'contact1', - name: 'Smith, Sarah', - lateAt: '2019-12-31', - }, - { - id: 'contact2', - name: 'Smith, John', - lateAt: '2019-12-30', - }, - ], - totalCount: 2, - }; - emptyCheck(latePledgeContacts); - }); - - const emptyCheck = (latePledgeContacts: any) => { const { getByTestId, queryByTestId } = render( , ); @@ -69,7 +46,7 @@ describe('LateCommitments', () => { expect( queryByTestId('LateCommitmentsListContacts'), ).not.toBeInTheDocument(); - }; + }); it('props', () => { const latePledgeContacts = { @@ -112,40 +89,6 @@ describe('LateCommitments', () => { ); }); - it('should not show a late commitment that is less than 7 days late', () => { - const latePledgeContacts = { - nodes: [ - { - id: 'contact1', - name: 'Smith, Sarah', - lateAt: '2019-12-31', - }, - { - id: 'contact2', - name: 'Smith, John', - lateAt: '2015-12-01', - }, - ], - totalCount: 2, - }; - const { getByTestId, queryByTestId } = render( - - - , - ); - const contact1Element = queryByTestId( - 'LateCommitmentsListItemContact-contact1', - ); - expect(contact1Element).not.toBeInTheDocument(); - - const contact2Element = getByTestId( - 'LateCommitmentsListItemContact-contact2', - ); - expect(contact2Element.textContent).toEqual( - 'Smith, JohnTheir gift is 1,492 days late.', - ); - }); - it('should not show a late commitment if it has no lateAt property', () => { const latePledgeContacts = { nodes: [ diff --git a/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx b/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx index 2a51a35d8..caf627730 100644 --- a/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx +++ b/src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx @@ -15,8 +15,6 @@ import { motion } from 'framer-motion'; import { DateTime } from 'luxon'; import { useTranslation } from 'react-i18next'; import { - Contact, - ContactConnection, ContactFilterPledgeReceivedEnum, StatusEnum, } from 'src/graphql/types.generated'; @@ -76,27 +74,6 @@ const LateCommitments = ({ const accountListId = useAccountListId(); const { push } = useRouter(); - const showLateCommitments = (latePledgeContacts?: ContactConnection) => { - if (!latePledgeContacts || latePledgeContacts.nodes.length === 0) { - return false; - } - const filteredLatePledges = latePledgeContacts.nodes.filter( - (contact: Contact) => { - if (contact.lateAt) { - return determineDaysLate(contact.lateAt) >= 7; - } - return false; - }, - ); - return filteredLatePledges.length > 0; - }; - - const determineDaysLate = (lateAt: string) => { - return Math.round( - DateTime.local().diff(DateTime.fromISO(lateAt), 'days').days, - ); - }; - return ( @@ -130,84 +107,82 @@ const LateCommitments = ({ animate={{ opacity: 1 }} exit={{ opacity: 0 }} > - {!showLateCommitments(latePledgeContacts as ContactConnection) && ( + {!latePledgeContacts?.nodes.length && ( empty {t('No late commitments to show.')} )} - {latePledgeContacts && - showLateCommitments(latePledgeContacts as ContactConnection) && ( - <> - - {latePledgeContacts.nodes.map((contact) => { - if (!contact.lateAt) { - return null; - } - const daysLate = Math.round( - DateTime.local().diff( - DateTime.fromISO(contact.lateAt), - 'days', - ).days, - ); + {!!latePledgeContacts?.nodes.length && ( + <> + + {latePledgeContacts.nodes.map((contact) => { + if (!contact.lateAt) { + return null; + } + const daysLate = Math.round( + DateTime.local().diff( + DateTime.fromISO(contact.lateAt), + 'days', + ).days, + ); - return ( - daysLate >= 7 && ( - - push( - `/accountLists/${accountListId}/contacts/list/${contact.id}`, - ) - } - key={contact.id} - > - - - ) - ); + return ( + daysLate && ( + + push( + `/accountLists/${accountListId}/contacts/list/${contact.id}`, + ) + } + key={contact.id} + > + + + ) + ); + })} + + + - - - )} + + + + )} )} diff --git a/src/components/Dashboard/ThisWeek/ThisWeek.mock.ts b/src/components/Dashboard/ThisWeek/ThisWeek.mock.ts index c4bd616a7..d81f724c2 100644 --- a/src/components/Dashboard/ThisWeek/ThisWeek.mock.ts +++ b/src/components/Dashboard/ThisWeek/ThisWeek.mock.ts @@ -146,7 +146,7 @@ export const GetThisWeekDefaultMocks = (): MockedResponse[] => { variables: { accountListId: 'abc', endOfDay: endOfDay.toISO(), - today: endOfDay.toISODate(), + thirtyDaysAgo: endOfDay.minus({ days: 30 }).toISODate(), threeWeeksFromNow: endOfDay.plus({ weeks: 3 }).toISODate(), twoWeeksAgo: endOfDay.minus({ weeks: 2 }).toISODate(), }, @@ -181,7 +181,7 @@ export const GetThisWeekEmptyMocks = (): MockedResponse[] => { variables: { accountListId: 'abc', endOfDay: endOfDay.toISO(), - today: endOfDay.toISODate(), + thirtyDaysAgo: endOfDay.minus({ days: 30 }).toISODate(), threeWeeksFromNow: endOfDay.plus({ weeks: 3 }).toISODate(), twoWeeksAgo: endOfDay.minus({ weeks: 2 }).toISODate(), }, diff --git a/src/components/Dashboard/ThisWeek/ThisWeek.tsx b/src/components/Dashboard/ThisWeek/ThisWeek.tsx index 0b815f4b1..ec84da4b0 100644 --- a/src/components/Dashboard/ThisWeek/ThisWeek.tsx +++ b/src/components/Dashboard/ThisWeek/ThisWeek.tsx @@ -25,7 +25,7 @@ const ThisWeek = ({ accountListId }: Props): ReactElement => { variables: { accountListId, endOfDay: endOfDay.toISO(), - today: endOfDay.toISODate(), + thirtyDaysAgo: endOfDay.minus({ days: 30 }).toISODate(), threeWeeksFromNow: endOfDay.plus({ weeks: 3 }).toISODate(), twoWeeksAgo: endOfDay.minus({ weeks: 2 }).toISODate(), },