- 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.
130 lines
4.3 KiB
TypeScript
130 lines
4.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { useNavigate } from '@tanstack/react-router'
|
|
import { CalendarPlus, Loader2, Plus } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { Button } from '../../components/ui'
|
|
import { getGroups, getGroupsRiskOverview } from '../../lib/api'
|
|
import { GroupCard } from './GroupCard'
|
|
import { MOCK_TEST_CASES } from './card'
|
|
|
|
export function GroupsView() {
|
|
const navigate = useNavigate()
|
|
const groupsQuery = useQuery({
|
|
queryKey: ['groups'],
|
|
queryFn: getGroups,
|
|
})
|
|
const riskQuery = useQuery({
|
|
queryKey: ['groups-risk-overview'],
|
|
queryFn: getGroupsRiskOverview,
|
|
})
|
|
|
|
const [showExamples, setShowExamples] = useState(() => {
|
|
if (typeof window !== 'undefined') {
|
|
return new URLSearchParams(window.location.search).get('mock') === 'true'
|
|
}
|
|
return false
|
|
})
|
|
|
|
const riskByGroup = new Map(
|
|
(riskQuery.data?.items ?? []).map((item) => [item.groupId, item]),
|
|
)
|
|
|
|
const hasGroups = groupsQuery.isSuccess && groupsQuery.data.data.length > 0
|
|
|
|
return (
|
|
<section>
|
|
<div className="flex items-center justify-between gap-3">
|
|
<h1 className="text-2xl font-bold text-primary">Grupos</h1>
|
|
<div className="flex items-center gap-2">
|
|
{!hasGroups && groupsQuery.isSuccess ? (
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="h-11"
|
|
onClick={() => setShowExamples((prev) => !prev)}
|
|
>
|
|
{showExamples ? 'Ocultar ejemplos' : 'Ver ejemplos'}
|
|
</Button>
|
|
) : null}
|
|
<Button
|
|
variant="primary"
|
|
className="h-11"
|
|
onClick={() => void navigate({ to: '/groups/new' })}
|
|
>
|
|
<Plus className="size-4" />
|
|
Nuevo grupo
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{groupsQuery.isPending ? (
|
|
<div className="mt-8 flex items-center justify-center py-16" role="status">
|
|
<Loader2 className="size-6 animate-spin text-secondary/50" aria-hidden="true" />
|
|
<span className="sr-only">Cargando grupos</span>
|
|
</div>
|
|
) : null}
|
|
|
|
{groupsQuery.isError ? (
|
|
<div className="mt-8 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
|
<p>No pudimos cargar tus grupos.</p>
|
|
<Button variant="outline" size="sm" onClick={() => void groupsQuery.refetch()}>
|
|
Reintentar
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
|
|
{showExamples ? (
|
|
<div className="mt-6 grid gap-4">
|
|
{MOCK_TEST_CASES.map((group) => (
|
|
<GroupCard key={group.id} {...group} />
|
|
))}
|
|
</div>
|
|
) : null}
|
|
|
|
{groupsQuery.isSuccess && groupsQuery.data.data.length === 0 && !showExamples ? (
|
|
/* A single icon, one focal point, and the text in secondary: the empty
|
|
state competes with the action and must not win. */
|
|
<div className="mt-8 rounded-xl bg-primary-soft px-5 py-12 text-center">
|
|
<span className="mx-auto flex size-14 items-center justify-center rounded-2xl bg-accent-soft text-accent-fg">
|
|
<CalendarPlus className="size-7" aria-hidden="true" />
|
|
</span>
|
|
<p className="mt-4 text-base font-semibold text-primary">Todavía no tenés grupos</p>
|
|
<p className="mx-auto mt-1.5 max-w-[30ch] text-sm leading-relaxed text-secondary">
|
|
Creá tu primer grupo y empezá a cobrar las cuotas de tus alumnos.
|
|
</p>
|
|
<div className="mt-6 flex items-center justify-center gap-3">
|
|
<Button
|
|
variant="outline"
|
|
className="h-11"
|
|
onClick={() => setShowExamples(true)}
|
|
>
|
|
Ver tarjetas de ejemplo
|
|
</Button>
|
|
<Button
|
|
variant="primary"
|
|
className="h-11"
|
|
onClick={() => void navigate({ to: '/groups/new' })}
|
|
>
|
|
<Plus className="size-4" />
|
|
Crear primer grupo
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{hasGroups && !showExamples ? (
|
|
<div className="mt-6 grid gap-4">
|
|
{groupsQuery.data.data.map((group) => (
|
|
<GroupCard
|
|
key={group.id}
|
|
group={group}
|
|
risk={riskByGroup.get(group.id)}
|
|
/>
|
|
))}
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
)
|
|
}
|
|
|