Skip to content

Commit

Permalink
Website: small cleanups (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkue authored Feb 13, 2025
1 parent c70ce9a commit 23ef67c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 28 deletions.
2 changes: 0 additions & 2 deletions shared/src/types/recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export type Recipient = {
successor?: string;
};

export const recipientNGOs = ['aurora', 'jamil', 'reachout', 'equal-rights', 'united-polio', 'slaes'];

export const toPaymentDate = (dateTime: DateTime) => {
return dateTime.set({
day: 15,
Expand Down
20 changes: 11 additions & 9 deletions shared/src/utils/stats/RecipientStatsCalculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,25 @@ test('Calculate recipient statistics', async () => {
expect(stats.recipientsCountByStatus[RecipientProgramStatus.Former]).toEqual(undefined);

// Verify total number of recipients for organization 1
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]['total']).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]!['total']).toEqual(1);

// Verify number of active recipients for organization 1
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id][RecipientProgramStatus.Active]).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]![RecipientProgramStatus.Active]).toEqual(1);

// Verify suspended recipients status:
// - Organization 1 should have no suspended recipients (undefined) and 1 active recipient
// - Organization 2 should have 1 suspended recipient
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id][RecipientProgramStatus.Suspended]).toEqual(undefined);
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id][RecipientProgramStatus.Active]).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id][RecipientProgramStatus.Suspended]).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id][RecipientProgramStatus.Active]).toEqual(undefined);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id][RecipientProgramStatus.Waitlisted]).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]![RecipientProgramStatus.Suspended]).toEqual(
undefined,
);
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]![RecipientProgramStatus.Active]).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id]![RecipientProgramStatus.Suspended]).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id]![RecipientProgramStatus.Active]).toEqual(undefined);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id]![RecipientProgramStatus.Waitlisted]).toEqual(1);

// Verify total recipients count for each organization:
// - Organization 1 should have 1 recipient
// - Organization 2 should have 2 recipients
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id].total).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id].total).toEqual(2);
expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]!['total']).toEqual(1);
expect(stats.recipientsCountByOrganisationAndStatus[org2Ref.id]!['total']).toEqual(2);
});
4 changes: 1 addition & 3 deletions shared/src/utils/stats/RecipientStatsCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export type TotalRecipientsByStatus = {
[status in RecipientProgramStatus]?: number;
} & { total: number };

export type OrganisationRecipientsByStatus = {
[orgId: string]: TotalRecipientsByStatus;
};
export type OrganisationRecipientsByStatus = Partial<Record<string, TotalRecipientsByStatus>> & { total: number };

export class RecipientStatsCalculator {
constructor(readonly recipients: _.Collection<Pick<Recipient, 'progr_status' | 'organisation'>>) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
NgoHoverCardType,
} from '@/app/[lang]/[region]/(website)/partners/(types)/PartnerCards';
import { firestoreAdmin } from '@/firebase-admin';
import { recipientNGOs, RecipientProgramStatus } from '@socialincome/shared/src/types/recipient';
import { RecipientProgramStatus } from '@socialincome/shared/src/types/recipient';
import { Translator } from '@socialincome/shared/src/utils/i18n';
import {
OrganisationRecipientsByStatus,
Expand All @@ -36,12 +36,8 @@ export async function NgoList({ lang, region }: DefaultParams) {
});
const image_base_path = '/assets/partners/';

const ngos: string[] = recipientNGOs;
const ngoArray: NgoEntryJSON[] = [];
ngos.forEach((slug: string) => {
const ngo: NgoEntryJSON = translator.t(slug);
ngoArray.push(ngo);
});
const ngos = ['aurora', 'jamil', 'reachout', 'equal-rights', 'united-polio', 'slaes'];
const ngoArray: NgoEntryJSON[] = ngos.map((slug: string) => translator.t(slug));
const ngoCardPropsArray: NgoCardProps[] = [];

const recipientCalculator = await RecipientStatsCalculator.build(firestoreAdmin);
Expand All @@ -50,6 +46,8 @@ export async function NgoList({ lang, region }: DefaultParams) {

for (let i = 0; i < ngoArray.length; ++i) {
const currentOrgRecipientStats = recipientStats[ngos[i]];
if (!currentOrgRecipientStats) continue;

const recipientsBadge: RecipientsBadgeType = {
hoverCardOrgName: ngoArray[i]['org-long-name'],
hoverCardTotalRecipients: currentOrgRecipientStats['total'] ?? 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function Section1({ params, paymentStats, contributionStats, recipi
},
})}
</Typography>
<Badge variant="interactive-accent">
<Badge variant="accent" size="md">
{translator.t('section-1.activeRecipients', {
context: {
value: recipientStats.recipientsCountByStatus[RecipientProgramStatus.Active] ?? 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default function Page() {
const { currency } = useI18n();

useEffect(() => {
redirect('./finances/' + currency?.toLowerCase());
if (currency) redirect('./finances/' + currency.toLowerCase());
}, [currency]);
}
8 changes: 3 additions & 5 deletions website/src/components/navbar/navbar-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,15 @@ const DesktopNavigation = ({ lang, region, languages, regions, currencies, navig
</div>
<SIIcon className="-mb-2.5 block h-9 pr-20 lg:hidden" />
</Link>
<div className="absolute left-0 mt-[50px] hidden flex-col justify-start space-y-2 overflow-visible whitespace-nowrap group-hover/navbar:flex group-active/navbar:flex">
<NavbarLink href={`/${lang}/${region}/journal`}>{translations.journal}</NavbarLink>
<NavbarLink className="mt-auto" href={`/${lang}/${region}/me`}>
{translations.myProfile}
</NavbarLink>
<div className="absolute left-0 mt-[50px] hidden flex-col justify-start overflow-visible whitespace-nowrap group-hover/navbar:flex group-active/navbar:flex">
<NavbarLink href={`/${lang}/${region}/me`}>{translations.myProfile}</NavbarLink>
<div className="flex-inline mt-auto flex items-center space-x-2">
<DonateIcon className="h-4 w-4" />
<NavbarLink href={`/${lang}/${region}/donate/individual`} className="text-accent">
{translations.donate}
</NavbarLink>
</div>
<NavbarLink href={`/${lang}/${region}/journal`}>{translations.journal}</NavbarLink>
</div>
</div>
<div className="flex flex-row items-center justify-evenly gap-x-10 overflow-visible">
Expand Down

0 comments on commit 23ef67c

Please sign in to comment.