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:
@@ -108,6 +108,7 @@ export const UpdatePlanLimitsInputSchema = z.strictObject({
|
||||
maxAttendees: limitValueSchema,
|
||||
whatsappAutomations: z.boolean(),
|
||||
mpCharges: z.boolean(),
|
||||
kidsGroups: z.boolean(),
|
||||
});
|
||||
export type UpdatePlanLimitsInput = z.output<typeof UpdatePlanLimitsInputSchema>;
|
||||
|
||||
|
||||
@@ -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>;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const isoDateTimeSchema = z.string().datetime();
|
||||
export const planSchema = z.enum(['FREE', 'PRO']);
|
||||
export type Plan = z.output<typeof planSchema>;
|
||||
|
||||
export const planFeatureSchema = z.enum(['whatsappAutomations', 'mpCharges']);
|
||||
export const planFeatureSchema = z.enum(['whatsappAutomations', 'mpCharges', 'kidsGroups']);
|
||||
export type PlanFeature = z.output<typeof planFeatureSchema>;
|
||||
|
||||
export type PlanLimits = {
|
||||
@@ -18,14 +18,16 @@ export type PlanLimits = {
|
||||
maxAttendees: number | null;
|
||||
whatsappAutomations: boolean;
|
||||
mpCharges: boolean;
|
||||
/** Groups of kids whose contact is the adult in charge. */
|
||||
kidsGroups: boolean;
|
||||
};
|
||||
|
||||
// Defaults only: the live limits and prices are edited from the backoffice and
|
||||
// live in `plan_configs` / `plan_prices` (seeded with these values). The backend
|
||||
// falls back to them when a row is missing; the web asks `GET /billing/plans`.
|
||||
export const PLAN_LIMITS: Record<Plan, PlanLimits> = {
|
||||
FREE: { maxGroups: 1, maxAttendees: 15, whatsappAutomations: false, mpCharges: false },
|
||||
PRO: { maxGroups: null, maxAttendees: null, whatsappAutomations: true, mpCharges: true },
|
||||
FREE: { maxGroups: 1, maxAttendees: 15, whatsappAutomations: false, mpCharges: false, kidsGroups: false },
|
||||
PRO: { maxGroups: null, maxAttendees: null, whatsappAutomations: true, mpCharges: true, kidsGroups: true },
|
||||
};
|
||||
|
||||
// Monthly price of Pro, in the currency of each country (COUNTRY_CURRENCY),
|
||||
@@ -74,6 +76,7 @@ export const PlanLimitsSchema = z.object({
|
||||
maxAttendees: z.number().int().nullable(),
|
||||
whatsappAutomations: z.boolean(),
|
||||
mpCharges: z.boolean(),
|
||||
kidsGroups: z.boolean(),
|
||||
});
|
||||
|
||||
/** What each plan allows and what Pro costs in each country, as configured now. */
|
||||
|
||||
@@ -14,4 +14,9 @@ export type WeekDay = z.output<typeof weekdaySchema>;
|
||||
|
||||
// Billing frequency of a group.
|
||||
export const billingTypeSchema = z.enum(['MONTHLY', 'PER_CLASS']);
|
||||
export type BillingType = z.output<typeof billingTypeSchema>;
|
||||
export type BillingType = z.output<typeof billingTypeSchema>;
|
||||
|
||||
// Who attends a group. In a KIDS group each student is a kid and the contact
|
||||
// (messages, student app) is the adult in charge.
|
||||
export const groupAudienceSchema = z.enum(['ADULTS', 'KIDS']);
|
||||
export type GroupAudience = z.output<typeof groupAudienceSchema>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { billingTypeSchema, weekdaySchema } from './enums.js';
|
||||
import { billingTypeSchema, groupAudienceSchema, weekdaySchema } from './enums.js';
|
||||
import { timeZoneSchema } from './home.js';
|
||||
import { createPageSchema, createPageSizeSchema, createPaginationSchema } from './pagination.js';
|
||||
|
||||
@@ -26,6 +26,7 @@ export const GroupDtoSchema = z.object({
|
||||
// Weekly WhatsApp automations (payment reminder and re-engagement).
|
||||
autoPaymentReminders: z.boolean(),
|
||||
autoReengagement: z.boolean(),
|
||||
audience: groupAudienceSchema,
|
||||
});
|
||||
export type GroupDto = z.output<typeof GroupDtoSchema>;
|
||||
|
||||
@@ -79,4 +80,4 @@ export type GroupList = z.output<typeof GroupListSchema>;
|
||||
export const CreateGroupResultSchema = z.object({
|
||||
group: GroupDtoSchema,
|
||||
});
|
||||
export type CreateGroupResult = z.output<typeof CreateGroupResultSchema>;
|
||||
export type CreateGroupResult = z.output<typeof CreateGroupResultSchema>;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user