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-8349] Add monthly commitment average and goal #1125

Merged
merged 6 commits into from
Oct 11, 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
2 changes: 1 addition & 1 deletion pages/api/Schema/reports/pledgeHistories/dataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getReportsPledgeHistories = (
id: id,
endDate: end_date,
pledged: pledged,
recieved: received,
received: received,
startDate: start_date,
updatedAt: updated_at,
updatedInDbAt: updated_in_db_at,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
extend type Query {
reportPledgeHistories(accountListId: ID!): [ReportsPledgeHistories]
reportPledgeHistories(
accountListId: ID!
range: String
endDate: String
): [ReportsPledgeHistories]
}

type ReportsPledgeHistories {
id: ID!
pledged: Float
recieved: Float
received: Float
endDate: ISO8601DateTime
startDate: ISO8601DateTime
createdAt: ISO8601DateTime
Expand Down
8 changes: 6 additions & 2 deletions pages/api/Schema/reports/pledgeHistories/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const ReportsPledgeHistoriesResolvers: Resolvers = {
Query: {
reportPledgeHistories: async (
_source,
{ accountListId },
{ accountListId, range, endDate },
{ dataSources },
) => {
return dataSources.mpdxRestApi.getReportPldegeHistories(accountListId);
return dataSources.mpdxRestApi.getReportPledgeHistories(
accountListId,
range,
endDate,
);
},
},
};
Expand Down
14 changes: 10 additions & 4 deletions pages/api/graphql-rest.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,15 @@ class MpdxRestApi extends RESTDataSource {
return getAppointmentResults(data);
}

async getReportPldegeHistories(accountListId: string) {
async getReportPledgeHistories(
accountListId: string,
range: string | null | undefined,
endDate: string | null | undefined,
) {
const rangeFilter = range ? `&filter[range]=${range}` : '';
const endDateFilter = endDate ? `&filter[end_date]=${endDate}` : '';
const { data } = await this.get(
`reports/pledge_histories?filter%5Baccount_list_id%5D=${accountListId}`,
`reports/pledge_histories?filter[account_list_id]=${accountListId}${rangeFilter}${endDateFilter}`,
);
return getReportsPledgeHistories(data);
}
Expand Down Expand Up @@ -447,7 +453,7 @@ class MpdxRestApi extends RESTDataSource {
) {
const designationAccountFilter =
designationAccountId && designationAccountId.length > 0
? `&filter[designation_account_id=${designationAccountId.join(',')}`
? `&filter[designation_account_id]=${designationAccountId.join(',')}`
canac marked this conversation as resolved.
Show resolved Hide resolved
: '';
const { data }: { data: FourteenMonthReportResponse } = await this.get(
`reports/${
Expand All @@ -467,7 +473,7 @@ class MpdxRestApi extends RESTDataSource {
) {
const designationAccountFilter =
designationAccountId && designationAccountId.length > 0
? `&filter[designation_account_id=${designationAccountId.join(',')}`
? `&filter[designation_account_id]=${designationAccountId.join(',')}`
: '';
const { data }: { data: ExpectedMonthlyTotalResponse } = await this.get(
`reports/expected_monthly_totals?filter[account_list_id]=${accountListId}${designationAccountFilter}`,
Expand Down
25 changes: 0 additions & 25 deletions src/components/Coaching/CoachingDetail/Activity/Activity.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,4 @@ describe('Activity', () => {
);
});
});

describe('links', () => {
const connectionsRemainingLinkText =
mocks.CoachingDetailActivity.accountListAnalytics.contactsByStatus.connectionsRemaining.toString();

it('are hidden when viewing coaching account list', async () => {
const { findByTestId, queryByRole } = render(<TestComponent />);

expect(
await findByTestId('CurrentRealityConnections'),
).toBeInTheDocument();
expect(
queryByRole('link', { name: connectionsRemainingLinkText }),
).not.toBeInTheDocument();
});

it('are shown when viewing own account list', async () => {
const { findByRole } = render(
<TestComponent accountListType={AccountListTypeEnum.Own} />,
);
expect(
await findByRole('link', { name: connectionsRemainingLinkText }),
).toBeInTheDocument();
});
});
});
61 changes: 23 additions & 38 deletions src/components/Coaching/CoachingDetail/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { getLocalizedContactStatus } from 'src/utils/functions/getLocalizedContactStatus';
import { MultilineSkeleton } from '../../../Shared/MultilineSkeleton';
import { AccountListTypeEnum, CoachingPeriodEnum } from '../CoachingDetail';
import { CoachingLink } from '../CoachingLink';
import { HelpButton } from '../HelpButton';
import { useCoachingDetailActivityQuery } from './Activity.generated';
import { AppealProgress } from './AppealProgress';
Expand Down Expand Up @@ -152,22 +153,6 @@ const StatsText = styled(Typography)({
fontSize: '0.9em',
});

interface LinkProps {
accountListType: AccountListTypeEnum;
children: React.ReactNode;
href: string;
}

const Link: React.FC<LinkProps> = ({ accountListType, children, href }) =>
// Only show links when the account list belongs to the user
accountListType === AccountListTypeEnum.Own ? (
<NextLink href={href} passHref>
<MuiLink underline="none">{children}</MuiLink>
</NextLink>
) : (
<span>{children}</span>
);

interface ActivityProps {
accountListId: string;
accountListType: AccountListTypeEnum;
Expand Down Expand Up @@ -256,7 +241,7 @@ export const Activity: React.FC<ActivityProps> = ({
<PeopleOutline sx={{ fontSize: '6rem' }} />
<SectionTitle>{t('Connections Remaining')}</SectionTitle>
<SectionTitleNumber>
<Link
<CoachingLink
href={contactsLink({
status: [
ContactFilterStatusEnum.NeverContacted,
Expand All @@ -272,14 +257,14 @@ export const Activity: React.FC<ActivityProps> = ({
.connectionsRemaining
}
</StatsText>
</Link>
</CoachingLink>
</SectionTitleNumber>
{loading ? (
<MultilineSkeleton lines={2} width="90%" />
) : (
<StatsRow>
<StatsColumn>
<Link
<CoachingLink
href={contactsLink({
status: [
ContactFilterStatusEnum.Null,
Expand All @@ -294,10 +279,10 @@ export const Activity: React.FC<ActivityProps> = ({
<StatsColumnTitle>
{getLocalizedContactStatus(t, StatusEnum.NeverContacted)}
</StatsColumnTitle>
</Link>
</CoachingLink>
</StatsColumn>
<StatsColumn>
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.AskInFuture],
})}
Expand All @@ -309,10 +294,10 @@ export const Activity: React.FC<ActivityProps> = ({
<StatsColumnTitle>
{getLocalizedContactStatus(t, StatusEnum.AskInFuture)}
</StatsColumnTitle>
</Link>
</CoachingLink>
</StatsColumn>
<StatsColumn>
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.CultivateRelationship],
})}
Expand All @@ -327,7 +312,7 @@ export const Activity: React.FC<ActivityProps> = ({
StatusEnum.CultivateRelationship,
)}
</StatsColumnTitle>
</Link>
</CoachingLink>
</StatsColumn>
</StatsRow>
)}
Expand All @@ -336,7 +321,7 @@ export const Activity: React.FC<ActivityProps> = ({
<CalendarMonthOutlined sx={{ fontSize: '6rem' }} />
<SectionTitle>{t('Partners Currently Initiating With')}</SectionTitle>
<SectionTitleNumber>
<Link
<CoachingLink
href={contactsLink({
status: [
ContactFilterStatusEnum.ContactForAppointment,
Expand All @@ -349,14 +334,14 @@ export const Activity: React.FC<ActivityProps> = ({
<StatsText sx={{ fontWeight: 'bold' }}>
{data?.accountListAnalytics.contactsByStatus.initiations}
</StatsText>
</Link>
</CoachingLink>
</SectionTitleNumber>
{loading ? (
<MultilineSkeleton lines={2} width="90%" />
) : (
<StatsRow>
<StatsColumn>
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.ContactForAppointment],
})}
Expand All @@ -374,10 +359,10 @@ export const Activity: React.FC<ActivityProps> = ({
StatusEnum.ContactForAppointment,
)}
</StatsColumnTitle>
</Link>
</CoachingLink>
</StatsColumn>
<StatsColumn>
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.AppointmentScheduled],
})}
Expand All @@ -395,10 +380,10 @@ export const Activity: React.FC<ActivityProps> = ({
StatusEnum.AppointmentScheduled,
)}
</StatsColumnTitle>
</Link>
</CoachingLink>
</StatsColumn>
<StatsColumn>
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.CallForDecision],
})}
Expand All @@ -413,7 +398,7 @@ export const Activity: React.FC<ActivityProps> = ({
<StatsColumnTitle>
{getLocalizedContactStatus(t, StatusEnum.CallForDecision)}
</StatsColumnTitle>
</Link>
</CoachingLink>
</StatsColumn>
</StatsRow>
)}
Expand Down Expand Up @@ -489,14 +474,14 @@ export const Activity: React.FC<ActivityProps> = ({
{data?.accountListAnalytics.contactsByStatus.financial}
</StatsLargeNumber>
)}
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.PartnerFinancial],
})}
accountListType={accountListType}
>
<SectionTitle>{t('Financial Partners')}</SectionTitle>
</Link>
</CoachingLink>
</ActivitySection>
<ActivitySection data-testid="CurrentRealityPartnerSpecial">
{loading ? (
Expand All @@ -506,14 +491,14 @@ export const Activity: React.FC<ActivityProps> = ({
{data?.accountListAnalytics.contactsByStatus.special}
</StatsLargeNumber>
)}
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.PartnerSpecial],
})}
accountListType={accountListType}
>
<SectionTitle>{t('Special Gift Partners')}</SectionTitle>
</Link>
</CoachingLink>
</ActivitySection>
<ActivitySection data-testid="CurrentRealityPartnerPrayer">
{loading ? (
Expand All @@ -523,14 +508,14 @@ export const Activity: React.FC<ActivityProps> = ({
{data?.accountListAnalytics.contactsByStatus.prayer}
</StatsLargeNumber>
)}
<Link
<CoachingLink
href={contactsLink({
status: [ContactFilterStatusEnum.PartnerPray],
})}
accountListType={accountListType}
>
<SectionTitle>{t('Prayer Partners')}</SectionTitle>
</Link>
</CoachingLink>
</ActivitySection>
</SectionsContainer>
</AnimatedCard>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Coaching/CoachingDetail/CoachingDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ export const CoachingDetail: React.FC<CoachingDetailProps> = ({
/>
<MonthlyCommitment
coachingId={accountListId}
accountListType={accountListType}
currencyCode={accountListData?.currency}
goal={accountListData?.monthlyGoal ?? 0}
mpdInfo={accountListData ?? null}
/>
<PartnersProgress
accountListId={accountListId}
Expand Down
25 changes: 25 additions & 0 deletions src/components/Coaching/CoachingDetail/CoachingLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render } from '@testing-library/react';
import { AccountListTypeEnum } from './CoachingDetail';
import { CoachingLink } from './CoachingLink';

describe('CoachingLink', () => {
it('are hidden when viewing coaching account list', () => {
const { queryByRole } = render(
<CoachingLink accountListType={AccountListTypeEnum.Coaching} href="/page">
Page
</CoachingLink>,
);

expect(queryByRole('link', { name: 'Page' })).not.toBeInTheDocument();
});

it('are shown when viewing own account list', async () => {
const { getByRole } = render(
<CoachingLink accountListType={AccountListTypeEnum.Own} href="/page">
Page
</CoachingLink>,
);

expect(getByRole('link', { name: 'Page' })).toBeInTheDocument();
});
});
26 changes: 26 additions & 0 deletions src/components/Coaching/CoachingDetail/CoachingLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import NextLink from 'next/link';
import { Link, LinkProps as MuiLinkProps } from '@mui/material';
import { AccountListTypeEnum } from './CoachingDetail';

interface LinkProps extends MuiLinkProps {
accountListType: AccountListTypeEnum;
href: string;
}

/*
* Component to show links when the account list belongs to the user and hide links when viewing a
* coached account list.
*/
export const CoachingLink: React.FC<LinkProps> = ({
accountListType,
href,
children,
...props
}) =>
accountListType === AccountListTypeEnum.Own ? (
<NextLink href={href} passHref>
<Link {...props}>{children}</Link>
</NextLink>
) : (
<span>{children}</span>
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ query GetReportsPledgeHistories($coachingId: ID!) {
startDate
endDate
pledged
recieved
received
}
}

query MonthlyCommitmentSingleMonth($accountListId: ID!, $month: String!) {
reportPledgeHistories(
accountListId: $accountListId
range: "1m"
endDate: $month
) {
id
pledged
received
}
}
Loading
Loading