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>
This commit is contained in:
@@ -24,8 +24,11 @@ export const AttendeeDtoSchema = z.object({
|
||||
fullName: z.string(),
|
||||
email: z.string().nullable(),
|
||||
phone: z.string().nullable(),
|
||||
/** The adult in charge (kids groups): a person of their own, flattened here. */
|
||||
guardianPersonId: z.string().nullable(),
|
||||
guardianName: z.string().nullable(),
|
||||
guardianPhone: z.string().nullable(),
|
||||
guardianEmail: z.string().nullable(),
|
||||
notes: z.string().nullable(),
|
||||
notifyToken: z.string().nullable().optional(),
|
||||
createdAt: isoDateTimeSchema,
|
||||
@@ -76,6 +79,8 @@ export const AttendeeDetailDtoSchema = AttendeeDtoSchema.extend({
|
||||
payment: AttendeePaymentSummarySchema.nullable(),
|
||||
/** The person's memberships in the teacher's other groups. */
|
||||
otherGroups: z.array(PersonMembershipSchema),
|
||||
/** Other kids of the same adult in charge (kids groups). */
|
||||
siblings: z.array(z.object({ personId: z.string(), fullName: z.string() })),
|
||||
});
|
||||
export type AttendeeDetailDto = z.output<typeof AttendeeDetailDtoSchema>;
|
||||
|
||||
@@ -115,16 +120,35 @@ export const AttendeeListSchema = z.object({
|
||||
});
|
||||
export type AttendeeList = z.output<typeof AttendeeListSchema>;
|
||||
|
||||
export const CreateAttendeeSchema = z.object({
|
||||
firstName: z.string().trim().min(1, 'name.required'),
|
||||
lastName: z.string().trim().optional().default(''),
|
||||
/* The adult in charge of a kid (kids groups). Found by phone among the
|
||||
teacher's people, so siblings share the same adult. */
|
||||
export const GuardianInputSchema = z.object({
|
||||
fullName: z.string().trim().min(1, 'guardian.nameRequired'),
|
||||
phone: z.string().trim().min(6, 'phone.invalid'),
|
||||
email: z.string().trim().email('email.invalid').optional().or(z.literal('')),
|
||||
notes: z.string().trim().optional(),
|
||||
/* Adds an existing person of the teacher (found by phone) instead of creating
|
||||
a new one: the name/email fields are ignored then. */
|
||||
personId: z.string().min(1).optional(),
|
||||
});
|
||||
export type GuardianInput = z.output<typeof GuardianInputSchema>;
|
||||
|
||||
export const CreateAttendeeSchema = z
|
||||
.object({
|
||||
firstName: z.string().trim().min(1, 'name.required'),
|
||||
lastName: z.string().trim().optional().default(''),
|
||||
/* Optional only for a kid with an adult in charge (`guardian`) or when
|
||||
adding an existing person (`personId`). */
|
||||
phone: z.string().trim().min(6, 'phone.invalid').optional().or(z.literal('')),
|
||||
email: z.string().trim().email('email.invalid').optional().or(z.literal('')),
|
||||
notes: z.string().trim().optional(),
|
||||
/* Adds an existing person of the teacher (found by phone) instead of creating
|
||||
a new one: the name/email fields are ignored then. */
|
||||
personId: z.string().min(1).optional(),
|
||||
/* Kids groups: the adult in charge of a new kid. */
|
||||
guardian: GuardianInputSchema.optional(),
|
||||
})
|
||||
.superRefine((value, ctx) => {
|
||||
if (!value.phone && !value.guardian && !value.personId) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['phone'], message: 'phone.invalid' });
|
||||
}
|
||||
});
|
||||
export type CreateAttendee = z.output<typeof CreateAttendeeSchema>;
|
||||
|
||||
export const CreateAttendeeResultSchema = z.discriminatedUnion('outcome', [
|
||||
@@ -216,6 +240,10 @@ export const PersonSummarySchema = z.object({
|
||||
email: z.string().nullable(),
|
||||
phone: z.string().nullable(),
|
||||
groups: z.array(PersonMembershipSchema),
|
||||
/** When the phone is an adult in charge: their kids, to add one of them or a sibling. */
|
||||
children: z.array(
|
||||
z.object({ id: z.string(), fullName: z.string(), groups: z.array(PersonMembershipSchema) }),
|
||||
),
|
||||
});
|
||||
export type PersonSummary = z.output<typeof PersonSummarySchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user