feat: add country selection during onboarding and implement payment management features

- Introduced CountryStep component for selecting the country during onboarding, affecting payment currency.
- Updated FirstGroupStep to include country information.
- Enhanced PaymentsProvider to manage payment states and renewals.
- Created PaymentRow component for displaying individual payment details.
- Implemented PaymentsView for listing and filtering payments by group and status.
- Added API endpoints for fetching and creating payments, including batch processing.
- Defined payment schemas for validation and data handling.
- Updated GroupHeader and GroupDetailView to include charging functionality for group members.
This commit is contained in:
Jose Selesan
2026-10-08 11:42:13 -03:00
parent b11dd47534
commit 8c5caecdda
49 changed files with 2367 additions and 90 deletions

View File

@@ -4,6 +4,7 @@ export * from './lib/result.js';
export * from './schemas/analytics.js';
export * from './schemas/attendance.js';
export * from './schemas/attendees.js';
export * from './schemas/country.js';
export * from './schemas/enums.js';
export * from './schemas/groups.js';
export * from './schemas/health-check.js';

View File

@@ -0,0 +1,33 @@
import { z } from 'zod';
// Countries where Mercado Pago operates and Gruperly collects. The professor
// picks one during onboarding; it drives the currency of the payment links.
export const countryCodeSchema = z.enum(['AR', 'BR', 'CL', 'CO', 'MX', 'PE', 'UY']);
export type CountryCode = z.output<typeof countryCodeSchema>;
export const COUNTRY_CURRENCY: Record<CountryCode, string> = {
AR: 'ARS',
BR: 'BRL',
CL: 'CLP',
CO: 'COP',
MX: 'MXN',
PE: 'PEN',
UY: 'UYU',
};
export const COUNTRY_LABELS: Record<CountryCode, string> = {
AR: 'Argentina',
BR: 'Brasil',
CL: 'Chile',
CO: 'Colombia',
MX: 'México',
PE: 'Perú',
UY: 'Uruguay',
};
export const DEFAULT_COUNTRY: CountryCode = 'AR';
export const DEFAULT_CURRENCY = COUNTRY_CURRENCY[DEFAULT_COUNTRY];
export function currencyForCountry(country: CountryCode | null | undefined): string {
return country ? COUNTRY_CURRENCY[country] : DEFAULT_CURRENCY;
}

View File

@@ -1,12 +1,17 @@
import { z } from 'zod';
import { countryCodeSchema, DEFAULT_COUNTRY } from './country.js';
import { billingTypeSchema, weekdaySchema } from './enums.js';
import { GroupDtoSchema } from './groups.js';
export { countryCodeSchema } from './country.js';
export type { BillingType, WeekDay } from './enums.js';
export { billingTypeSchema, weekdaySchema } from './enums.js';
// Step 3: create the teacher's first group. Linking Mercado Pago is step 2 and
// is skippable, so nothing here may require a linked account.
// Step 4: create the teacher's first group. Linking Mercado Pago is step 2 and
// is skippable, so nothing here may require a linked account. The country is
// stored on the user and drives the currency of the payment links later. It
// defaults to Argentina because the group form (also used outside onboarding)
// has no country field: the country lives on the user, not on the group.
export const CreateFirstGroupSchema = z.strictObject({
name: z
.string()
@@ -30,6 +35,7 @@ export const CreateFirstGroupSchema = z.strictObject({
.int({ message: 'El día debe ser un número entero' })
.min(1, 'El día de vencimiento debe estar entre 1 y 28')
.max(28, 'El día de vencimiento debe estar entre 1 y 28'),
country: countryCodeSchema.default(DEFAULT_COUNTRY),
});
export type CreateFirstGroup = z.output<typeof CreateFirstGroupSchema>;

View File

@@ -7,14 +7,19 @@ const pageSizeSchema = createPageSizeSchema(10);
const paginationSchema = createPaginationSchema();
export const paymentStatusSchema = z.enum(['PENDING', 'PAID', 'OVERDUE', 'CANCELLED']);
export type PaymentStatus = z.output<typeof paymentStatusSchema>;
export const PaymentDtoSchema = z.object({
id: z.string(),
groupId: z.string(),
groupName: z.string(),
attendeeId: z.string(),
attendeeName: z.string(),
amount: z.coerce.number().positive(),
currency: z.string(),
status: paymentStatusSchema,
description: z.string().nullable(),
checkoutUrl: z.string().nullable(),
dueDate: isoDateTimeSchema,
paidAt: isoDateTimeSchema.nullable(),
createdAt: isoDateTimeSchema,
@@ -25,6 +30,8 @@ export type PaymentDto = z.output<typeof PaymentDtoSchema>;
export const PaymentQuerySchema = z.object({
page: pageSchema,
pageSize: pageSizeSchema,
groupId: z.string().min(1).optional(),
status: paymentStatusSchema.optional(),
});
export type PaymentQuery = z.output<typeof PaymentQuerySchema>;
@@ -32,4 +39,36 @@ export const PaymentListSchema = z.object({
data: z.array(PaymentDtoSchema),
pagination: paginationSchema,
});
export type PaymentList = z.output<typeof PaymentListSchema>;
export type PaymentList = z.output<typeof PaymentListSchema>;
// Creates one payment link per active attendee of a group. The professor
// triggers it from the group page for a period (e.g. June's monthly fee).
export const CreatePaymentsBatchSchema = z.strictObject({
dueDate: isoDateTimeSchema,
description: z.string().trim().max(120, 'La descripción es demasiado larga').optional(),
attendeeIds: z.array(z.string().min(1)).min(1).optional(),
});
export type CreatePaymentsBatch = z.output<typeof CreatePaymentsBatchSchema>;
export const paymentBatchOutcomeSchema = z.enum(['CREATED', 'LINKED', 'FAILED']);
export const PaymentBatchItemSchema = z.object({
paymentId: z.string(),
attendeeId: z.string(),
attendeeName: z.string(),
amount: z.number().positive(),
currency: z.string(),
checkoutUrl: z.string().nullable(),
outcome: paymentBatchOutcomeSchema,
reason: z.string().nullable(),
});
export type PaymentBatchItem = z.output<typeof PaymentBatchItemSchema>;
export const CreatePaymentsBatchResultSchema = z.object({
groupId: z.string(),
total: z.number().int().min(0),
linked: z.number().int().min(0),
failed: z.number().int().min(0),
items: z.array(PaymentBatchItemSchema),
});
export type CreatePaymentsBatchResult = z.output<typeof CreatePaymentsBatchResultSchema>;