From 90f31290d44bac8905d86f4b7217562a8790aa84 Mon Sep 17 00:00:00 2001 From: Jose Selesan Date: Tue, 27 Oct 2026 14:33:37 -0300 Subject: [PATCH] feat(web): pulido mobile de ficha de grupo, alumno, nuevo grupo y ajustes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ficha de grupo: "Agregar miembro" a todo el ancho y debajo Estadísticas, Cobrar y Compartir con icono y texto (antes iconos sueltos en mobile). Los mensajes automáticos de WhatsApp quedan en una fila plegable que arranca cerrada si no hay ninguno activo. - Historial del alumno: arranca en la primera clase registrada si es anterior al alta, como la lista y la regla de riesgo ("1 de 5" en ambos). - Nuevo grupo: cupo 10 por defecto, precio vacío obligatorio y foco inicial en el nombre. - Ajustes: chevron en Seguridad; el botón de tema del header queda solo en desktop (en mobile vive en Apariencia). Co-Authored-By: Claude Opus 5.5 --- .../features/get-attendee-history/use-case.ts | 15 ++- apps/backend/test/analytics.test.ts | 24 ++++ apps/web/src/components/layout/Header.tsx | 7 +- apps/web/src/features/groups/GroupForm.tsx | 13 +- .../groups/detail/GroupAutomationsCard.tsx | 122 +++++++++++------- .../features/groups/detail/GroupHeader.tsx | 52 ++++---- .../src/features/settings/SettingsView.tsx | 3 +- 7 files changed, 156 insertions(+), 80 deletions(-) diff --git a/apps/backend/src/modules/analytics/features/get-attendee-history/use-case.ts b/apps/backend/src/modules/analytics/features/get-attendee-history/use-case.ts index 8001e47..827c85d 100644 --- a/apps/backend/src/modules/analytics/features/get-attendee-history/use-case.ts +++ b/apps/backend/src/modules/analytics/features/get-attendee-history/use-case.ts @@ -39,8 +39,21 @@ export class GetAttendeeHistory { return err(notFoundResourceProblem('Attendee', attendeeId)); } + // Same effective join date as the risk rule (`toMemberAttendance`): an + // attendee loaded after their first classes were already recorded starts + // at that first class, not at `createdAt`. Otherwise this screen said + // "1 de 3 clases" while the group list said "1 de 5" for the same person. + const firstAttendance = await db.attendance.findFirst({ + where: { attendeeId }, + orderBy: { classSession: { startsAt: 'asc' } }, + select: { classSession: { select: { startsAt: true } } }, + }); + const firstClassAt = firstAttendance?.classSession.startsAt; + const since = + firstClassAt && firstClassAt < attendee.createdAt ? firstClassAt : attendee.createdAt; + const sessions = await db.classSession.findMany({ - where: { groupId, startsAt: { gte: attendee.createdAt } }, + where: { groupId, startsAt: { gte: since } }, orderBy: { startsAt: 'desc' }, take: HISTORY_SESSIONS_LIMIT, select: { id: true, startsAt: true }, diff --git a/apps/backend/test/analytics.test.ts b/apps/backend/test/analytics.test.ts index 0ec23a0..e1228b5 100644 --- a/apps/backend/test/analytics.test.ts +++ b/apps/backend/test/analytics.test.ts @@ -16,6 +16,7 @@ const db = { }, attendance: { findMany: mock(), + findFirst: mock(), }, slotRelease: { count: mock(), @@ -251,6 +252,29 @@ describe('analytics routes', () => { }); }); + it('arranca en la primera clase registrada si es anterior al alta', async () => { + // Loaded on 1/10 with classes already marked since 20/9: the history + // starts at the first one, as the risk rule and the group list count it. + prisma.group.findUnique.mockResolvedValue(makeGroup()); + prisma.attendee.findFirst.mockResolvedValue({ + id: 'a-1', + fullName: 'Ana Pérez', + createdAt: new Date('2026-10-01T00:00:00.000Z'), + }); + prisma.attendance.findFirst.mockResolvedValueOnce({ + classSession: { startsAt: new Date('2026-09-20T10:00:00.000Z') }, + }); + prisma.classSession.findMany.mockResolvedValue([]); + + await makeApp({ id: userId }).request('/groups/group-1/attendees/a-1/history'); + + expect(prisma.classSession.findMany).toHaveBeenCalledWith( + expect.objectContaining({ + where: { groupId: 'group-1', startsAt: { gte: new Date('2026-09-20T10:00:00.000Z') } }, + }), + ); + }); + it('devuelve 404 si el alumno no pertenece al grupo', async () => { prisma.group.findUnique.mockResolvedValue(makeGroup()); prisma.attendee.findFirst.mockResolvedValue(null); diff --git a/apps/web/src/components/layout/Header.tsx b/apps/web/src/components/layout/Header.tsx index 2d61375..34bd745 100644 --- a/apps/web/src/components/layout/Header.tsx +++ b/apps/web/src/components/layout/Header.tsx @@ -18,7 +18,12 @@ export function Header() {
- + {/* On mobile the theme lives only in Ajustes → Apariencia: in the + header it took the space next to the avatar for something you + change once. On desktop there is room for the shortcut. */} +
+ +
diff --git a/apps/web/src/features/groups/GroupForm.tsx b/apps/web/src/features/groups/GroupForm.tsx index f482103..000ac88 100644 --- a/apps/web/src/features/groups/GroupForm.tsx +++ b/apps/web/src/features/groups/GroupForm.tsx @@ -1,4 +1,4 @@ -import { useForm } from 'react-hook-form' +import { type DefaultValues, useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import type { BillingType, CountryCode, CreateFirstGroup, WeekDay } from '@gruperly/shared' import { CreateFirstGroupSchema, DEFAULT_COUNTRY } from '@gruperly/shared' @@ -30,12 +30,14 @@ export function GroupForm({ onSubmit, onBack, }: GroupFormProps) { - const defaultValues: CreateFirstGroup = { + // The price starts empty on purpose: a pre-filled $0 got submitted as is and + // the group ended up unable to charge. The capacity starts at a typical + // class size instead of 1, which had to be overwritten every time. + const defaultValues: DefaultValues = { name: '', days: [], time: '09:00', - capacity: 1, - price: 0, + capacity: 10, billingType: 'MONTHLY', dueDay: 1, country, @@ -77,6 +79,7 @@ export function GroupForm({ (null) if (!group || !isGroupOwner) return null const includedInPlan = hasPlanFeature(billingQuery.data, 'whatsappAutomations') + const activeCount = AUTOMATIONS.filter((automation) => group[automation.key]).length + const expanded = expandedByUser ?? activeCount > 0 + const summary = + activeCount === 0 ? 'Apagados' : activeCount === 1 ? '1 activo' : `${activeCount} activos` return (
-
+ + + {expanded ? ( +
+

{WEEKLY_SEND_LABEL} {includedInPlan ? null : ( <> @@ -63,46 +95,46 @@ export function GroupAutomationsCard() { )}

-
-
-
    - {AUTOMATIONS.map((automation) => { - const checked = group[automation.key] - const blocked = automationBlockedReason(whatsappQuery.data, automation.kind) - const hintId = `automation-${automation.key}-hint` - return ( -
  • -
    -

    {automation.title}

    -

    - {automation.description} - {blocked && !checked ? ( - <> - {' '} - {blocked}{' '} - {whatsappQuery.data?.status !== 'active' ? ( - - Ir a Ajustes - +

      + {AUTOMATIONS.map((automation) => { + const checked = group[automation.key] + const blocked = automationBlockedReason(whatsappQuery.data, automation.kind) + const hintId = `automation-${automation.key}-hint` + return ( +
    • +
      +

      {automation.title}

      +

      + {automation.description} + {blocked && !checked ? ( + <> + {' '} + {blocked}{' '} + {whatsappQuery.data?.status !== 'active' ? ( + + Ir a Ajustes + + ) : null} + ) : null} - - ) : null} -

      -
      - updateAutomations({ [automation.key]: next })} - /> -
    • - ) - })} -
    +

    +
    + updateAutomations({ [automation.key]: next })} + /> +
  • + ) + })} +
+ + ) : null}
) } diff --git a/apps/web/src/features/groups/detail/GroupHeader.tsx b/apps/web/src/features/groups/detail/GroupHeader.tsx index 9716ece..d1a7279 100644 --- a/apps/web/src/features/groups/detail/GroupHeader.tsx +++ b/apps/web/src/features/groups/detail/GroupHeader.tsx @@ -88,11 +88,16 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) { {hasGroup ? ( - // A single row on mobile: the primary takes the leftover width and the two - // supporting actions collapse into 44px icons. At sm+ they get their text - // back because there is plenty of width and the label makes the - // destination clearer. -
+ // On mobile the primary takes its own row and the supporting actions go + // below as three equal buttons with their label: as bare 44px icons + // nobody could tell "Cobrar" from "Estadísticas". At sm+ everything goes + // back to a single row aligned to the right. +
{!isEmptyGroup ? ( // One primary per screen: "Agregar" heads the hierarchy and the // supporting actions sit beside it, in outline. @@ -101,7 +106,7 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) { onClick={() => void navigate({ to: '/groups/$groupId/attendees/new', params: { groupId } }) } - className="h-11 flex-1 justify-center sm:flex-none sm:w-auto" + className="col-span-3 h-11 justify-center sm:w-auto" > Agregar miembro @@ -110,41 +115,29 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) { {!isEmptyGroup ? ( ) : null}
@@ -152,3 +145,8 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
) } + +// Icon over label on mobile: side by side, "Estadísticas" didn't fit a third of +// a 402px row. +const SECONDARY_ACTION_CLASS_NAME = + 'h-14 min-w-0 flex-col justify-center gap-1 border-border px-1 text-xs sm:h-11 sm:w-auto sm:flex-row sm:gap-1.5 sm:px-4 sm:text-sm' diff --git a/apps/web/src/features/settings/SettingsView.tsx b/apps/web/src/features/settings/SettingsView.tsx index 897a588..c929049 100644 --- a/apps/web/src/features/settings/SettingsView.tsx +++ b/apps/web/src/features/settings/SettingsView.tsx @@ -1,5 +1,5 @@ import { Link } from '@tanstack/react-router' -import { Fingerprint } from 'lucide-react' +import { ChevronRight, Fingerprint } from 'lucide-react' import { Button } from '../../components/ui' import { signOut } from '../../lib/auth-client' import { PlanSettingsCard } from '../billing' @@ -34,6 +34,7 @@ export function SettingsView() {

Seguridad

Contraseña y passkeys

+