diff --git a/apps/backend/src/modules/groups/features/get-all/use-case.ts b/apps/backend/src/modules/groups/features/get-all/use-case.ts index fd2bdfe..4873461 100644 --- a/apps/backend/src/modules/groups/features/get-all/use-case.ts +++ b/apps/backend/src/modules/groups/features/get-all/use-case.ts @@ -21,13 +21,15 @@ type ListGroupsDeps = { now?: Date; }; -const OCCUPANCY_COUNT_INCLUDE = { +const LIST_COUNT_INCLUDE = { _count: { select: { // Group members. No status filter, same as the detail page counts. attendees: true, // Waitlist: the ones still waiting for a spot (the reviewed ones drop out). waitlist: { where: { status: 'PENDING' as const } }, + // Payments still to collect: the ones pending and the overdue ones. + payments: { where: { status: { in: ['PENDING' as const, 'OVERDUE' as const] } } }, }, }, } satisfies Prisma.GroupInclude; @@ -49,7 +51,7 @@ export class ListGroups { // time zone (or the server's if it doesn't come along). const records: GroupListRecord[] = await db.group.findMany({ where, - include: OCCUPANCY_COUNT_INCLUDE, + include: LIST_COUNT_INCLUDE, }); const timeZone = query.timeZone ?? DEFAULT_TIME_ZONE; diff --git a/apps/backend/src/modules/groups/lib/helpers.ts b/apps/backend/src/modules/groups/lib/helpers.ts index 71532f6..c6f6dd8 100644 --- a/apps/backend/src/modules/groups/lib/helpers.ts +++ b/apps/backend/src/modules/groups/lib/helpers.ts @@ -26,9 +26,10 @@ export type GroupRecord = { /* The listing adds the occupancy counters to each group so the card can show them without asking for one endpoint per group. They come from the `_count` of the same query: all the members (same as the detail page counts) and only the - waitlist entries still waiting for a spot (PENDING). */ + waitlist entries still waiting for a spot (PENDING), plus the payments still + to collect (PENDING and OVERDUE). */ export type GroupListRecord = GroupRecord & { - _count?: { attendees: number; waitlist: number }; + _count?: { attendees: number; waitlist: number; payments?: number }; }; export function toGroupDto(record: GroupRecord): GroupDto { @@ -56,6 +57,7 @@ export function toGroupListItemDto(record: GroupListRecord): GroupListItem { ...toGroupDto(record), attendeesCount: record._count?.attendees ?? 0, waitlistCount: record._count?.waitlist ?? 0, + unpaidPaymentsCount: record._count?.payments ?? 0, }; } diff --git a/apps/backend/test/groups.test.ts b/apps/backend/test/groups.test.ts index bdca845..af70646 100644 --- a/apps/backend/test/groups.test.ts +++ b/apps/backend/test/groups.test.ts @@ -61,7 +61,7 @@ describe('groups routes', () => { it('lists groups scoped to the current user', async () => { prisma.group.findMany.mockResolvedValue([ - { ...group, _count: { attendees: 4, waitlist: 1 } }, + { ...group, _count: { attendees: 4, waitlist: 1, payments: 3 } }, ]); prisma.group.count.mockResolvedValue(1); @@ -76,6 +76,7 @@ describe('groups routes', () => { updatedAt: group.updatedAt.toISOString(), attendeesCount: 4, waitlistCount: 1, + unpaidPaymentsCount: 3, }, ], pagination: { page: 1, pageSize: 10, total: 1, totalPages: 1 }, @@ -89,7 +90,11 @@ describe('groups routes', () => { where, include: { _count: { - select: { attendees: true, waitlist: { where: { status: 'PENDING' } } }, + select: { + attendees: true, + waitlist: { where: { status: 'PENDING' } }, + payments: { where: { status: { in: ['PENDING', 'OVERDUE'] } } }, + }, }, }, }); diff --git a/apps/web/src/components/ui/sheet.tsx b/apps/web/src/components/ui/sheet.tsx index e7799a0..3163e73 100644 --- a/apps/web/src/components/ui/sheet.tsx +++ b/apps/web/src/components/ui/sheet.tsx @@ -12,7 +12,8 @@ export type SheetProps = { } /* Bottom sheet on mobile (anchored to the bottom edge, above the home - indicator) and a centered dialog from `sm` up. Escape and the backdrop close + indicator, sliding up unless reduced motion is on) and a centered dialog + from `sm` up. Escape and the backdrop close it; focus moves into the panel on open and goes back where it was on close. */ export function Sheet({ isOpen, onClose, title, description, children, className }: SheetProps) { const titleId = useId() @@ -50,7 +51,7 @@ export function Sheet({ isOpen, onClose, title, description, children, className ref={panelRef} tabIndex={-1} className={cn( - 'relative max-h-[90dvh] w-full overflow-y-auto rounded-t-2xl border border-border bg-surface p-5 pb-[calc(1.25rem+env(safe-area-inset-bottom))] shadow-2xl outline-none animate-fade-in sm:max-w-md sm:rounded-2xl sm:pb-5', + 'relative max-h-[90dvh] w-full overflow-y-auto rounded-t-2xl border border-border bg-surface p-5 pb-[calc(1.25rem+env(safe-area-inset-bottom))] shadow-2xl outline-none animate-sheet-up motion-reduce:animate-fade-in sm:animate-fade-in sm:max-w-md sm:rounded-2xl sm:pb-5', className, )} > diff --git a/apps/web/src/features/payments/CreateGroupLink.tsx b/apps/web/src/features/payments/CreateGroupLink.tsx new file mode 100644 index 0000000..12715b3 --- /dev/null +++ b/apps/web/src/features/payments/CreateGroupLink.tsx @@ -0,0 +1,19 @@ +import { Link } from '@tanstack/react-router' +import { Plus } from 'lucide-react' +import { cn } from '../../lib/utils' + +/* Pie del selector de grupos de Cobros: lleva al alta de grupo. */ +export function CreateGroupLink({ compact = false }: { compact?: boolean }) { + return ( + +