Skip to content

Commit

Permalink
refactor(website): switch from daisyui to shadcn (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkue authored Sep 20, 2023
1 parent 8634cc6 commit 4b98307
Show file tree
Hide file tree
Showing 100 changed files with 4,227 additions and 2,569 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ seed/
dist/
.next/
*.hbs
ui/src/react-daisyui/
ui/README.md
ui/storybook-static/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Tailwind CSS independent of the website ([Readme](ui/README.md) /
our [Storybook](https://socialincome-san.github.io/public/).

\* The website socialincome.org is still on a private repo. In this
repo, we are rebuilding the existing website with Next.js, DaisyUI and
repo, we are rebuilding the existing website with Next.js, shadcn/ui and
Tailwind CSS. You can visit the website in the making on
[staging](https://staging.socialincome.org/) or
[production](https://prod.socialincome.org/).
Expand Down
11 changes: 3 additions & 8 deletions admin/src/actions/PaymentProcessAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const BOX_STYLE = {
p: 4,
};

const createNewPaymentsDescription = 'Set payment status to paid and create new payments for the upcoming month.';
const createNewPaymentsDescription =
'Update status of payments, create new payments for the upcoming month, and update status of recipients.';

export function PaymentProcessAction() {
const snackbarController = useSnackbarController();
Expand Down Expand Up @@ -85,12 +86,6 @@ export function PaymentProcessAction() {
if (value) setPaymentDate(toPaymentDate(DateTime.fromJSDate(value)));
}}
/>
<Button
variant="outlined"
onClick={() => triggerFirebaseFunction(PaymentProcessTaskType.UpdateRecipients)}
>
Update Recipients
</Button>
<Button
variant="outlined"
onClick={() => triggerFirebaseFunction(PaymentProcessTaskType.GetRegistrationCSV)}
Expand All @@ -103,7 +98,7 @@ export function PaymentProcessAction() {
{!confirmCreateNewPayments && (
<Tooltip title={createNewPaymentsDescription}>
<Button variant="outlined" onClick={() => setConfirmCreateNewPayments(true)}>
Create new payments
Update Database
</Button>
</Tooltip>
)}
Expand Down
8 changes: 2 additions & 6 deletions functions/src/webhooks/admin/payment-process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import * as functions from 'firebase-functions';
import { DateTime } from 'luxon';
import { FirestoreAdmin } from '../../../../../shared/src/firebase/admin/FirestoreAdmin';
import { PaymentProcessTaskType, toPaymentDate } from '../../../../../shared/src/types';
import { CreatePaymentsTask } from './tasks/CreatePaymentsTask';
import { PaymentCSVTask } from './tasks/PaymentCSVTask';
import { PaymentTask } from './tasks/PaymentTask';
import { RegistrationCSVTask } from './tasks/RegistrationCSVTask';
import { SendNotificationsTask } from './tasks/SendNotificationsTask';
import { UpdateRecipientsTask } from './tasks/UpdateRecipientsTask';
import { UpdateDatabaseEntriesTask } from './tasks/UpdateDatabaseEntriesTask';

export interface PaymentProcessProps {
type: PaymentProcessTaskType;
Expand All @@ -21,17 +20,14 @@ export default functions.https.onCall(async ({ type, timestamp }: PaymentProcess
let task: PaymentTask;

switch (type) {
case PaymentProcessTaskType.UpdateRecipients:
task = new UpdateRecipientsTask(firestoreAdmin);
break;
case PaymentProcessTaskType.GetRegistrationCSV:
task = new RegistrationCSVTask(firestoreAdmin);
break;
case PaymentProcessTaskType.GetPaymentCSV:
task = new PaymentCSVTask(firestoreAdmin);
break;
case PaymentProcessTaskType.CreatePayments:
task = new CreatePaymentsTask(firestoreAdmin);
task = new UpdateDatabaseEntriesTask(firestoreAdmin);
break;
case PaymentProcessTaskType.SendNotifications:
task = new SendNotificationsTask(firestoreAdmin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('GetPaymentCSV', async () => {

const rows = result.split('\n').map((row: string) => row.split(','));

expect(rows).toHaveLength(3);
expect(rows).toHaveLength(4);
expect(rows[0]).toEqual([
'Mobile Number*',
'Amount*',
Expand All @@ -38,4 +38,5 @@ test('GetPaymentCSV', async () => {
]);
expect(rows[1]).toEqual(['25000052', '700', 'Test2', 'User2', '2', `Social Income April 2023`, 'subscriber']);
expect(rows[2]).toEqual(['25000053', '700', 'Test3', 'User3', '3', `Social Income April 2023`, 'subscriber']);
expect(rows[3]).toEqual(['25000054', '700', 'Test4', 'User4', '4', `Social Income April 2023`, 'subscriber']);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ export class PaymentCSVTask extends PaymentTask {
const recipients = await this.getRecipients();
recipients.sort((a, b) => a.get('om_uid') - b.get('om_uid'));

for (const recipient of recipients) {
csvRows.push([
recipient.get('mobile_money_phone').phone.toString().slice(-8),
PAYMENT_AMOUNT.toString(),
recipient.get('first_name'),
recipient.get('last_name'),
recipient.get('om_uid').toString(),
`Social Income ${paymentDate.toFormat('LLLL yyyy')}`,
'subscriber',
]);
}
await Promise.all(
recipients.map(async (recipient) => {
csvRows.push([
recipient.get('mobile_money_phone').phone.toString().slice(-8),
PAYMENT_AMOUNT.toString(),
recipient.get('first_name'),
recipient.get('last_name'),
recipient.get('om_uid').toString(),
`Social Income ${paymentDate.toFormat('LLLL yyyy')}`,
'subscriber',
]);
}),
);
return csvRows.map((row) => row.join(',')).join('\n');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export abstract class PaymentTask {
}

public async getRecipients(
allowedStatus: RecipientProgramStatus[] = [RecipientProgramStatus.Active],
allowedStatus: RecipientProgramStatus[] = [RecipientProgramStatus.Active, RecipientProgramStatus.Designated],
): Promise<QueryDocumentSnapshot<Recipient>[]> {
return (
await this.firestoreAdmin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ test('GetRegistrationCSV', async () => {
);

const rows = result.split('\n').map((row: string) => row.split(','));
expect(rows).toHaveLength(3);
expect(rows).toHaveLength(4);
expect(rows[0]).toEqual(['Mobile Number*', 'Unique Code*', 'User Type*']);
expect(rows[1]).toEqual(['25000052', '2', 'subscriber']);
expect(rows[2]).toEqual(['25000053', '3', 'subscriber']);
expect(rows[3]).toEqual(['25000054', '4', 'subscriber']);
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as functions from 'firebase-functions';
import { PaymentTask } from './PaymentTask';

export class RegistrationCSVTask extends PaymentTask {
Expand All @@ -6,13 +7,17 @@ export class RegistrationCSVTask extends PaymentTask {
const recipients = await this.getRecipients();
recipients.sort((a, b) => a.get('om_uid') - b.get('om_uid'));

for (const recipient of recipients) {
csvRows.push([
recipient.get('mobile_money_phone').phone.toString().slice(-8),
recipient.get('om_uid').toString(),
'subscriber',
]);
}
await Promise.all(
recipients.map(async (recipient) => {
if (!recipient.get('om_uid'))
throw new functions.https.HttpsError('internal', 'Orange Money Id missing for designated recipient');
csvRows.push([
recipient.get('mobile_money_phone').phone.toString().slice(-8),
recipient.get('om_uid').toString(),
'subscriber',
]);
}),
);
return csvRows.map((row) => row.join(',')).join('\n');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ test('CreatePayments', async () => {
auth: { token: { email: '[email protected]' } },
},
);
expect(result).toEqual('Set 2 payments to paid and created 2 payments for next month');
expect(result).toEqual(
'Set status of 3 payments to paid and created 3 payments for next month. Set status to "former" for 0 recipients and status to active for 1 recipients.',
);

const recipientDocs = (
await firestoreAdmin
.collection<Recipient>(RECIPIENT_FIRESTORE_PATH)
.where('progr_status', '==', RecipientProgramStatus.Active)
.get()
).docs;
expect(recipientDocs).toHaveLength(2);
expect(recipientDocs).toHaveLength(3);

for (const recipientDoc of recipientDocs) {
const paymentDoc = await firestoreAdmin
Expand Down Expand Up @@ -81,5 +83,7 @@ test('CreatePayments', async () => {
{ type: PaymentProcessTaskType.CreatePayments, timestamp: paymentDate.toSeconds() },
{ auth: { token: { email: '[email protected]' } } },
);
expect(secondExecutionResult).toEqual('Set 0 payments to paid and created 0 payments for next month');
expect(secondExecutionResult).toEqual(
'Set status of 0 payments to paid and created 0 payments for next month. Set status to "former" for 0 recipients and status to active for 0 recipients.',
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
Payment,
PaymentStatus,
RECIPIENT_FIRESTORE_PATH,
RecipientProgramStatus,
} from '../../../../../../shared/src/types';
import { ExchangeRateImporter } from '../../../../cron/exchange-rate-import/ExchangeRateImporter';
import { PaymentTask } from './PaymentTask';

export class CreatePaymentsTask extends PaymentTask {
export class UpdateDatabaseEntriesTask extends PaymentTask {
async run(paymentDate: DateTime): Promise<string> {
let [paymentsPaid, paymentsCreated] = [0, 0];
let [paymentsPaid, paymentsCreated, setToActiveCount, setToFormerCount] = [0, 0, 0, 0];
const nextMonthPaymentDate = paymentDate.plus({ months: 1 });
const exchangeRates = await new ExchangeRateImporter().getExchangeRates(paymentDate);
const amountChf = Math.round((PAYMENT_AMOUNT / exchangeRates[PAYMENT_CURRENCY]) * 100) / 100;
Expand Down Expand Up @@ -61,9 +62,23 @@ export class CreatePaymentsTask extends PaymentTask {
});
paymentsCreated++;
}
if (paymentsCount == PAYMENTS_COUNT) {
// If a recipient has received all their payments, set their status to former
await recipient.ref.update({
progr_status: RecipientProgramStatus.Former,
});
setToFormerCount++;
}
if (recipient.get('progr_status') === RecipientProgramStatus.Designated) {
await recipient.ref.update({
si_start_date: paymentDate.toJSDate(),
progr_status: RecipientProgramStatus.Active,
});
setToActiveCount++;
}
}),
);

return `Set ${paymentsPaid} payments to paid and created ${paymentsCreated} payments for next month`;
return `Set status of ${paymentsPaid} payments to paid and created ${paymentsCreated} payments for next month. Set status to "former" for ${setToFormerCount} recipients and status to active for ${setToActiveCount} recipients.`;
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4b98307

Please sign in to comment.