Files
gruperly/apps/web/src/features/groups/add/ExistingGuardianNotice.tsx
Jose Selesan 58c776e18c feat(groups): kids groups with an adult in charge
- Add the `kidsGroups` plan feature (Pro) and `Group.audience` (ADULTS | KIDS);
  creating or switching a group to KIDS requires the feature, existing KIDS
  groups keep working after a downgrade.
- Model the adult in charge as a Person linked through `person_guardians`;
  migrate the old guardian_name/guardian_phone columns and drop them.
- Kids quick add: kid + guardian form, guardian lookup by phone to pick an
  existing kid or add a sibling; backend rejects KIDS adds without guardian.
- Attendee page: "Adulto a cargo" section with siblings, editable via
  PATCH /groups/:gid/attendees/:aid/guardian.
- Contact phone (WhatsApp jobs, attention, student access invite, students at
  risk, attendee actions) prefers the guardian's phone.
- Edit group screen (PATCH /groups/:gid, owner only); switching back to ADULTS
  is blocked while kids have no phone of their own.
- Hide bulk import in KIDS groups until it carries guardian data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 13:27:13 -03:00

76 lines
3.0 KiB
TypeScript

import { UserCheck } from 'lucide-react'
import { Trans, useTranslation } from 'react-i18next'
import type { PersonSummary } from '@gruperly/shared'
import { cn } from '../../../lib/utils'
type ExistingGuardianNoticeProps = {
guardian: PersonSummary
groupId: string
/** El chico ya cargado que se eligió, o `null` si es un chico nuevo. */
selectedKidId: string | null
onSelectKid: (kidId: string | null) => void
}
/* El teléfono del adulto ya es de alguien que el profe tiene: queda como adulto
a cargo con sus datos, y si ya tiene chicos se ofrece elegir uno (para no
duplicarlo) o seguir con un hermano nuevo. */
export function ExistingGuardianNotice({ guardian, groupId, selectedKidId, onSelectKid }: ExistingGuardianNoticeProps) {
const { t } = useTranslation('groupAdd')
const kids = guardian.children
return (
<div role="status" className="mt-2 rounded-xl border border-border bg-accent-soft/40 px-3 py-3 text-sm text-primary">
<div className="flex items-start gap-2.5">
<UserCheck className="mt-0.5 size-4 shrink-0 text-accent-fg" aria-hidden="true" />
<p className="min-w-0">
<Trans
t={t}
i18nKey={kids.length > 0 ? 'kid.existing.foundWithKids' : 'kid.existing.found'}
values={{ name: guardian.fullName }}
components={{ strong: <strong /> }}
/>
</p>
</div>
{kids.length > 0 ? (
<div className="mt-2.5 flex flex-wrap gap-2" role="group" aria-label={t('kid.existing.pickLabel')}>
{kids.map((kid) => {
const inGroup = kid.groups.some((group) => group.groupId === groupId && group.status !== 'DROPPED')
const isSelected = selectedKidId === kid.id
return (
<button
key={kid.id}
type="button"
disabled={inGroup}
aria-pressed={isSelected}
onClick={() => onSelectKid(isSelected ? null : kid.id)}
className={cn(
'rounded-full border px-3 py-1.5 text-xs font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50',
isSelected
? 'border-accent bg-accent text-on-accent'
: 'border-border bg-surface text-primary hover:bg-primary-soft',
)}
>
{inGroup ? t('kid.existing.kidInGroup', { name: kid.fullName }) : kid.fullName}
</button>
)
})}
<button
type="button"
aria-pressed={selectedKidId === null}
onClick={() => onSelectKid(null)}
className={cn(
'rounded-full border px-3 py-1.5 text-xs font-medium transition-colors',
selectedKidId === null
? 'border-accent bg-accent text-on-accent'
: 'border-border bg-surface text-primary hover:bg-primary-soft',
)}
>
{t('kid.existing.newSibling')}
</button>
</div>
) : null}
</div>
)
}