Files
gruperly/apps/web/src/features/groups/detail/MembersView.tsx
Jose Selesan 69275c37b4 chore: update comments and documentation for clarity and consistency across various files
- Translated comments from Spanish to English in vite.config.ts, docker-compose.yml, attendance-risk.ts, analytics.ts, attendance.ts, attendees.ts, enums.ts, groups.ts, and onboarding.ts.
- Improved descriptions for better understanding of code functionality and purpose.
- Ensured uniformity in terminology and phrasing throughout the codebase.
2026-10-01 16:06:54 -03:00

132 lines
4.7 KiB
TypeScript

import { useNavigate } from '@tanstack/react-router'
import { Loader2, Plus, Share2, Users, X } from 'lucide-react'
import { Button } from '../../../components/ui'
import { cn } from '../../../lib/utils'
import { useGroupDetail } from './GroupDetailProvider'
import { MembersList } from './MembersList'
import { byFullName, isOverdue, resolvePaymentState } from './member-row'
function OverdueFilter({ count }: { count: number }) {
const { overdueOnly, setOverdueOnly } = useGroupDetail()
return (
<div className="px-3 pb-1.5">
<button
type="button"
aria-pressed={overdueOnly}
onClick={() => setOverdueOnly(!overdueOnly)}
className={cn(
// min-h-11 (44px): minimum touch target, same as the section chips.
'inline-flex min-h-11 items-center gap-1.5 rounded-full border px-3.5 text-xs font-semibold',
'transition-[background-color,color,border-color,box-shadow] duration-150',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-primary-soft',
overdueOnly
? 'border-transparent bg-danger-soft text-danger'
: 'border-border bg-surface text-foreground hover:border-danger/40 hover:text-danger',
)}
>
{/* The ✕ only shows with the filter on: it is the signal that tapping it
takes the filter off, without having to say so. */}
{overdueOnly ? <X className="size-3.5 shrink-0" aria-hidden="true" /> : null}
<span className="whitespace-nowrap">{count} con pago vencido</span>
</button>
</div>
)
}
export function MembersView() {
const {
groupId,
attendees,
attendeesPending,
searchFilter,
overdueOnly,
openInviteModal,
} = useGroupDetail()
const navigate = useNavigate()
const query = searchFilter.trim().toLowerCase()
// The phone is not shown on the row but is still a search path: it is how most
// people know the group's attendees.
const matchesQuery = (attendee: (typeof attendees)[number]) =>
!query ||
attendee.fullName.toLowerCase().includes(query) ||
(attendee.phone != null && attendee.phone.includes(query)) ||
(attendee.email != null && attendee.email.toLowerCase().includes(query))
const overdueCount = attendees.filter((attendee) =>
isOverdue(resolvePaymentState(attendee.payment)),
).length
const visible = attendees
.filter((attendee) => !overdueOnly || isOverdue(resolvePaymentState(attendee.payment)))
.filter(matchesQuery)
// Fixed alphabetical order: if it were sorted by charge or attendance the
// rows would jump around every time someone pays or misses, and the name is
// the only stable column in the list.
.sort(byFullName)
if (attendeesPending) {
return (
<div className="flex items-center justify-center py-12">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
)
}
if (attendees.length === 0) {
return (
<div className="bg-surface px-4 py-10 text-center">
<Users className="mx-auto mb-2 size-10 text-foreground/40" />
<p className="text-sm font-semibold text-primary">
Todavía no hay miembros en este grupo
</p>
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
Puedes compartir el enlace de invitación único o agregar miembros de forma manual o
masiva.
</p>
<div className="mt-4 flex flex-col gap-2.5 sm:flex-row sm:items-center sm:justify-center sm:gap-3">
<Button variant="outline" onClick={openInviteModal} className="h-11 w-full sm:w-auto">
<Share2 className="size-4" />
Compartir enlace
</Button>
<Button
variant="primary"
onClick={() =>
void navigate({ to: '/groups/$groupId/attendees/new', params: { groupId } })
}
className="h-11 w-full sm:w-auto"
>
<Plus className="size-4" />
Agregar miembros
</Button>
</div>
</div>
)
}
const filterBar = overdueCount > 0 ? <OverdueFilter count={overdueCount} /> : null
if (visible.length === 0) {
// The overdue filter never ends up empty on its own (the chip is not shown
// if there are none overdue), so an empty list here is always the search.
return (
<>
{filterBar}
<div className="px-4 py-8 text-center text-sm text-foreground">
{overdueOnly
? 'Ningún miembro con pago vencido coincide con la búsqueda.'
: 'No se encontraron miembros que coincidan con la búsqueda.'}
</div>
</>
)
}
return (
<>
{filterBar}
<MembersList attendees={visible} />
</>
)
}