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

Fix Late Commitments #1121

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/components/Dashboard/ThisWeek/GetThisWeek.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
query GetThisWeek(
$accountListId: ID!
$endOfDay: ISO8601DateTime!
$today: ISO8601Date!
$thirtyDaysAgo: ISO8601Date!
$threeWeeksFromNow: ISO8601Date!
$twoWeeksAgo: ISO8601Date!
) {
Expand Down Expand Up @@ -60,7 +60,7 @@ query GetThisWeek(
accountListId: $accountListId
first: 3
contactsFilter: {
lateAt: { max: $today }
lateAt: { max: $thirtyDaysAgo }
status: PARTNER_FINANCIAL
pledgeReceived: RECEIVED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<LateCommitments latePledgeContacts={latePledgeContacts} />,
);
Expand All @@ -69,7 +46,7 @@ describe('LateCommitments', () => {
expect(
queryByTestId('LateCommitmentsListContacts'),
).not.toBeInTheDocument();
};
});

it('props', () => {
const latePledgeContacts = {
Expand Down Expand Up @@ -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(
<GqlMockedProvider>
<LateCommitments latePledgeContacts={latePledgeContacts} />
</GqlMockedProvider>,
);
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: [
Expand Down
163 changes: 69 additions & 94 deletions src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import { DateTime } from 'luxon';
import { useTranslation } from 'react-i18next';
import {
Contact,
ContactConnection,
ContactFilterPledgeReceivedEnum,
StatusEnum,
} from 'src/graphql/types.generated';
Expand Down Expand Up @@ -76,27 +74,6 @@
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 (
<LateCommitmentsContainer>
<CardHeader title={t('Late Commitments')} />
Expand Down Expand Up @@ -130,84 +107,82 @@
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
{!showLateCommitments(latePledgeContacts as ContactConnection) && (
{!latePledgeContacts?.nodes.length && (
<LateCommitmentsCardContent data-testid="LateCommitmentsCardContentEmpty">
<img src={illustration14} alt="empty" />
{t('No late commitments to show.')}
</LateCommitmentsCardContent>
)}
{latePledgeContacts &&
showLateCommitments(latePledgeContacts as ContactConnection) && (
<>
<CardList data-testid="LateCommitmentsListContacts">
{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 && (
<>
<CardList data-testid="LateCommitmentsListContacts">
{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 && (
<ListItem
component="a"
button
data-testid={`LateCommitmentsListItemContact-${contact.id}`}
onClick={() =>
push(
`/accountLists/${accountListId}/contacts/list/${contact.id}`,
)
}
key={contact.id}
>
<ListItemText
primary={contact.name}
secondary={t(
'Their gift is {{daysLate}} day late._plural',
{
daysLate: numberFormat(daysLate, locale),
},
)}
/>
</ListItem>
)
);
return (
daysLate && (
<ListItem
component="a"
button
data-testid={`LateCommitmentsListItemContact-${contact.id}`}
onClick={() =>
push(

Check warning on line 137 in src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Dashboard/ThisWeek/LateCommitments/LateCommitments.tsx#L137

Added line #L137 was not covered by tests
`/accountLists/${accountListId}/contacts/list/${contact.id}`,
)
}
key={contact.id}
>
<ListItemText
primary={contact.name}
secondary={t(
'Their gift is {{daysLate}} day late._plural',
{
daysLate: numberFormat(daysLate, locale),
},
)}
/>
</ListItem>
)
);
})}
</CardList>
<CardActions>
<Button
size="small"
color="primary"
data-testid="LateCommitmentsButtonViewAll"
href={`/accountLists/${accountListId}/contacts/list?filters=${encodeURIComponent(
JSON.stringify({
lateAt: {
min: DateTime.fromISO('1970-01-01'),
max: DateTime.local()
.endOf('day')
.minus({ days: 30 })
.toISODate(),
},
pledgeReceived: ContactFilterPledgeReceivedEnum.Received,
status: [StatusEnum.PartnerFinancial],
}),
)}`}
>
{t('View All ({{totalCount}})', {
totalCount: numberFormat(
latePledgeContacts?.totalCount ?? 0,
locale,
),
})}
</CardList>
<CardActions>
<Button
size="small"
color="primary"
data-testid="LateCommitmentsButtonViewAll"
href={`/accountLists/${accountListId}/contacts/list?filters=${encodeURIComponent(
JSON.stringify({
lateAt: {
min: DateTime.fromISO('1970-01-01'),
max: DateTime.local()
.endOf('day')
.minus({ days: 30 })
.toISODate(),
},
pledgeReceived:
ContactFilterPledgeReceivedEnum.Received,
status: [StatusEnum.PartnerFinancial],
}),
)}`}
>
{t('View All ({{totalCount}})', {
totalCount: numberFormat(
latePledgeContacts?.totalCount ?? 0,
locale,
),
})}
</Button>
</CardActions>
</>
)}
</Button>
</CardActions>
</>
)}
</MotionDiv>
)}
</LateCommitmentsContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dashboard/ThisWeek/ThisWeek.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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(),
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/ThisWeek/ThisWeek.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down
Loading