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:
Jose Selesan
2026-11-11 13:27:13 -03:00
parent aac142d324
commit 58c776e18c
89 changed files with 1805 additions and 110 deletions

View File

@@ -1,12 +1,12 @@
import { z } from 'zod';
import { planSchema, subscriptionStatusSchema } from './billing.js';
import { countryCodeSchema, DEFAULT_COUNTRY } from './country.js';
import { billingTypeSchema, weekdaySchema } from './enums.js';
import { billingTypeSchema, groupAudienceSchema, weekdaySchema } from './enums.js';
import { GroupDtoSchema } from './groups.js';
export { countryCodeSchema } from './country.js';
export type { BillingType, WeekDay } from './enums.js';
export { billingTypeSchema, weekdaySchema } from './enums.js';
export type { BillingType, GroupAudience, WeekDay } from './enums.js';
export { billingTypeSchema, groupAudienceSchema, weekdaySchema } from './enums.js';
// Step 4: create the teacher's first group. Linking Mercado Pago is step 2 and
// is skippable, so nothing here may require a linked account. The country is
@@ -37,9 +37,21 @@ export const CreateFirstGroupSchema = z.strictObject({
.min(1, 'group.dueDayRange')
.max(28, 'group.dueDayRange'),
country: countryCodeSchema.default(DEFAULT_COUNTRY),
// A KIDS group needs the `kidsGroups` plan feature.
audience: groupAudienceSchema.default('ADULTS'),
});
export type CreateFirstGroup = z.output<typeof CreateFirstGroupSchema>;
// "Editar grupo" (`PATCH /groups/:id`): the same fields as the group form, any
// subset. The country lives on the user, not on the group. Turning the group
// into KIDS needs the `kidsGroups` plan feature; going back to ADULTS is blocked
// while it has kids with no phone of their own.
export const UpdateGroupSchema = CreateFirstGroupSchema.omit({ country: true, audience: true })
.extend({ audience: groupAudienceSchema })
.partial()
.refine((value) => Object.keys(value).length > 0, 'update.empty');
export type UpdateGroup = z.output<typeof UpdateGroupSchema>;
export const OnboardingGroupDtoSchema = GroupDtoSchema.extend({
days: z.array(weekdaySchema).nullable(),
time: z.string().nullable(),