feat(student-portal): student account belongs to the adult in charge

- Inviting a kid with an adult in charge links the account to the adult
  (a legacy account linked to the kid moves to the adult and is renamed).
- `linkedPersonWhere` lets the account reach the kids of a linked adult, so
  the adult sees and manages all their kids, including ones added later.
- /me, link info and access status follow the adult; siblings share state.
- Web: greeting uses the account holder, profile lists each kid's group, and
  the invitation sheet/message address the adult.
- DB tests for the adult account flow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-11-11 14:04:25 -03:00
parent 9383841513
commit 5b3a035dcf
17 changed files with 336 additions and 66 deletions

View File

@@ -16,6 +16,8 @@ type InviteToAppSheetProps = {
groupName: string
attendeeId: string
fullName: string
/** Kids groups: the account (and the message) belong to the adult in charge. */
guardianName?: string | null
hasPhone: boolean
/** Reinviting closes the current access: the copy says so. */
reinvite: boolean
@@ -31,6 +33,7 @@ export function InviteToAppSheet({
groupName,
attendeeId,
fullName,
guardianName,
hasPhone,
reinvite,
}: InviteToAppSheetProps) {
@@ -39,6 +42,7 @@ export function InviteToAppSheet({
const [invitation, setInvitation] = useState<StudentInvitationDto | null>(null)
const [copied, setCopied] = useState(false)
const firstName = fullName.split(' ')[0] ?? fullName
const guardianFirstName = guardianName ? (guardianName.split(' ')[0] ?? guardianName) : null
const mutation = useMutation({
mutationFn: () => inviteStudent(groupId, attendeeId),
@@ -63,7 +67,7 @@ export function InviteToAppSheet({
const popup = window.open('', '_blank')
try {
const result = await ensureInvitation()
const text = encodeURIComponent(invitationMessage(firstName, groupName, result.url))
const text = encodeURIComponent(invitationMessage(firstName, groupName, result.url, guardianFirstName))
const target = result.whatsappPhone
? `https://wa.me/${result.whatsappPhone.replace(/\D/g, '')}?text=${text}`
: `https://wa.me/?text=${text}`
@@ -91,7 +95,12 @@ export function InviteToAppSheet({
}
}
const preview = invitationMessage(firstName, groupName, invitation?.url ?? t('inviteSheet.linkPlaceholder'))
const preview = invitationMessage(
firstName,
groupName,
invitation?.url ?? t('inviteSheet.linkPlaceholder'),
guardianFirstName,
)
return (
<Sheet
@@ -100,8 +109,10 @@ export function InviteToAppSheet({
title={reinvite ? t('inviteSheet.titleReinvite') : t('inviteSheet.title')}
description={
reinvite
? t('inviteSheet.descriptionReinvite', { name: firstName })
: t('inviteSheet.description', { name: firstName })
? t('inviteSheet.descriptionReinvite', { name: guardianFirstName ?? firstName })
: guardianFirstName
? t('inviteSheet.descriptionGuardian', { guardian: guardianFirstName, name: firstName })
: t('inviteSheet.description', { name: firstName })
}
>
<div className="space-y-4">

View File

@@ -76,6 +76,7 @@ export function StudentAccessSection() {
groupName={groupName ?? t('access.yourGroup')}
attendeeId={attendee.id}
fullName={attendee.fullName}
guardianName={attendee.guardianName}
hasPhone={hasPhone}
reinvite={invited}
/>

View File

@@ -38,6 +38,19 @@ export function formatSince(iso: string): string {
return new Date(iso).toLocaleDateString(i18n.language, { day: 'numeric', month: 'long' })
}
export function invitationMessage(firstName: string, groupName: string, url: string): string {
return i18n.t('attendeeDetail:inviteSheet.message', { name: firstName, group: groupName, url })
/* With an adult in charge the message goes to the adult, about the kid. */
export function invitationMessage(
firstName: string,
groupName: string,
url: string,
guardianFirstName?: string | null,
): string {
return guardianFirstName
? i18n.t('attendeeDetail:inviteSheet.messageGuardian', {
guardian: guardianFirstName,
name: firstName,
group: groupName,
url,
})
: i18n.t('attendeeDetail:inviteSheet.message', { name: firstName, group: groupName, url })
}

View File

@@ -9,7 +9,7 @@ import { WeekClassesList } from './WeekClassesList'
import { useTranslation } from 'react-i18next'
export function StudentHomeView() {
const { student, classes, classesPending, fees } = useStudentApp()
const { me, student, classes, classesPending, fees } = useStudentApp()
const { t } = useTranslation(['student', 'common'])
if (!student) return null
@@ -20,7 +20,8 @@ export function StudentHomeView() {
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold text-primary">{t('home.greeting', { name: firstName(student.fullName) })}</h1>
{/* The account holder: the student, or the adult in charge of several kids. */}
<h1 className="text-2xl font-bold text-primary">{t('home.greeting', { name: firstName(me?.account.name ?? student.fullName) })}</h1>
{fees ? <PaymentReviewBanner reports={fees.reports} /> : null}

View File

@@ -20,7 +20,14 @@ export function StudentProfileView() {
<div className="min-w-0">
<p className="truncate font-semibold text-primary">{me.account.name}</p>
<p className="truncate text-sm text-secondary">
{me.students.map((student) => `${student.groupName} · ${student.teacherName}`).join(' / ')}
{me.students
.map((student) =>
// An adult in charge sees whose group each one is.
student.fullName === me.account.name
? `${student.groupName} · ${student.teacherName}`
: `${student.fullName} · ${student.groupName}`,
)
.join(' / ')}
</p>
</div>
</section>

View File

@@ -58,6 +58,7 @@
"title": "Invite to the app",
"descriptionReinvite": "Send {{name}} a new link. The previous access stops working.",
"description": "{{name}} will be able to report absences, report payments and see their upcoming classes. No passwords or new details.",
"descriptionGuardian": "{{guardian}} will be able to report absences, report payments and see the classes of {{name}} and their other kids. No passwords or new details.",
"preview": "Message preview",
"linkPlaceholder": "🔗 personal link",
"security": "The link is personal, works only once and expires in 72 hours. The first phone that opens it stays connected.",
@@ -65,7 +66,8 @@
"sendWhatsapp": "Send on WhatsApp",
"copied": "Link copied",
"copy": "Copy link",
"message": "Hi {{name}}! I'm inviting you to gruperly to report absences and payments for {{group}}. {{url}}"
"message": "Hi {{name}}! I'm inviting you to gruperly to report absences and payments for {{group}}. {{url}}",
"messageGuardian": "Hi {{guardian}}! I'm inviting you to gruperly to report absences and payments for {{name}} in {{group}}. {{url}}"
},
"payments": {
"title": "Payments",

View File

@@ -58,6 +58,7 @@
"title": "Invitar a la app",
"descriptionReinvite": "Envíale un link nuevo a {{name}}. El acceso anterior deja de funcionar.",
"description": "{{name}} podrá avisar faltas, informar pagos y ver sus próximas clases. Sin contraseñas ni datos nuevos.",
"descriptionGuardian": "{{guardian}} podrá avisar faltas, informar pagos y ver las clases de {{name}} y del resto de sus hijos. Sin contraseñas ni datos nuevos.",
"preview": "Vista previa del mensaje",
"linkPlaceholder": "🔗 link personal",
"security": "El link es personal, sirve una sola vez y vence en 72 horas. Queda conectado el primer teléfono que lo abra.",
@@ -65,7 +66,8 @@
"sendWhatsapp": "Enviar por WhatsApp",
"copied": "Link copiado",
"copy": "Copiar link",
"message": "¡Hola {{name}}! Te invito a gruperly para avisar faltas e informar pagos de {{group}}. {{url}}"
"message": "¡Hola {{name}}! Te invito a gruperly para avisar faltas e informar pagos de {{group}}. {{url}}",
"messageGuardian": "¡Hola {{guardian}}! Te invito a gruperly para avisar faltas e informar pagos de {{name}} en {{group}}. {{url}}"
},
"payments": {
"title": "Cobros",

View File

@@ -58,6 +58,7 @@
"title": "Invitar a la app",
"descriptionReinvite": "Mandale un link nuevo a {{name}}. El acceso anterior deja de funcionar.",
"description": "{{name}} va a poder avisar faltas, informar pagos y ver sus próximas clases. Sin contraseñas ni datos nuevos.",
"descriptionGuardian": "{{guardian}} va a poder avisar faltas, informar pagos y ver las clases de {{name}} y del resto de sus chicos. Sin contraseñas ni datos nuevos.",
"preview": "Vista previa del mensaje",
"linkPlaceholder": "🔗 link personal",
"security": "El link es personal, sirve una sola vez y vence en 72 horas. Queda conectado el primer teléfono que lo abra.",
@@ -65,7 +66,8 @@
"sendWhatsapp": "Enviar por WhatsApp",
"copied": "Link copiado",
"copy": "Copiar link",
"message": "¡Hola {{name}}! Te invito a gruperly para avisar faltas e informar pagos de {{group}}. {{url}}"
"message": "¡Hola {{name}}! Te invito a gruperly para avisar faltas e informar pagos de {{group}}. {{url}}",
"messageGuardian": "¡Hola {{guardian}}! Te invito a gruperly para avisar faltas e informar pagos de {{name}} en {{group}}. {{url}}"
},
"payments": {
"title": "Cobros",

View File

@@ -58,6 +58,7 @@
"title": "Convidar para o app",
"descriptionReinvite": "Envie um novo link para {{name}}. O acesso anterior deixa de funcionar.",
"description": "{{name}} vai poder avisar faltas, informar pagamentos e ver as próximas aulas. Sem senhas nem dados novos.",
"descriptionGuardian": "{{guardian}} vai poder avisar faltas, informar pagamentos e ver as aulas de {{name}} e dos outros filhos. Sem senhas nem dados novos.",
"preview": "Prévia da mensagem",
"linkPlaceholder": "🔗 link pessoal",
"security": "O link é pessoal, vale uma única vez e vence em 72 horas. Fica conectado o primeiro celular que abrir.",
@@ -65,7 +66,8 @@
"sendWhatsapp": "Enviar pelo WhatsApp",
"copied": "Link copiado",
"copy": "Copiar link",
"message": "Olá, {{name}}! Te convido para o gruperly para avisar faltas e informar pagamentos de {{group}}. {{url}}"
"message": "Olá, {{name}}! Te convido para o gruperly para avisar faltas e informar pagamentos de {{group}}. {{url}}",
"messageGuardian": "Olá, {{guardian}}! Te convido para o gruperly para avisar faltas e informar pagamentos de {{name}} em {{group}}. {{url}}"
},
"payments": {
"title": "Cobranças",