diff --git a/admin-wcc-app/components/EditMentor/EditMentorForm.tsx b/admin-wcc-app/components/EditMentor/EditMentorForm.tsx index cf2845f5..0bfda8b9 100644 --- a/admin-wcc-app/components/EditMentor/EditMentorForm.tsx +++ b/admin-wcc-app/components/EditMentor/EditMentorForm.tsx @@ -101,6 +101,7 @@ export default function EditMentorForm({ mentorId }: EditMentorFormProps) { control, handleSubmit, reset, + setValue, formState: { errors }, } = useForm({ resolver: zodResolver(editMentorSchema), @@ -165,7 +166,7 @@ export default function EditMentorForm({ mentorId }: EditMentorFormProps) { longTerm: data.mentorshipType.includes('LONG_TERM') ? { numMentee: 1, hours: 2 } : null, adHoc: data.mentorshipType.includes('AD_HOC') ? data.monthAvailability - .filter((m) => m.enabled) + .filter((m) => m.enabled && m.hours > 0) .map((m) => ({ month: m.month, hours: m.hours })) : [], }, @@ -321,7 +322,7 @@ export default function EditMentorForm({ mentorId }: EditMentorFormProps) { - + diff --git a/admin-wcc-app/components/EditMentor/MentorshipAvailabilitySection.tsx b/admin-wcc-app/components/EditMentor/MentorshipAvailabilitySection.tsx index 6ec1def6..c8718080 100644 --- a/admin-wcc-app/components/EditMentor/MentorshipAvailabilitySection.tsx +++ b/admin-wcc-app/components/EditMentor/MentorshipAvailabilitySection.tsx @@ -30,7 +30,11 @@ const MONTHS = [ const monthLabel = (month: string) => month.charAt(0) + month.slice(1).toLowerCase(); -export default function MentorshipAvailabilitySection({ control, errors }: FormSectionProps) { +export default function MentorshipAvailabilitySection({ + control, + errors, + setValue, +}: FormSectionProps) { const mentorshipType = useWatch({ control, name: 'mentorshipType', @@ -143,7 +147,12 @@ export default function MentorshipAvailabilitySection({ control, errors }: FormS control={ field.onChange(e.target.checked)} + onChange={(e) => { + field.onChange(e.target.checked); + if (!e.target.checked) { + setValue?.(`monthAvailability.${index}.hours`, 0); + } + }} size="small" /> } @@ -159,9 +168,11 @@ export default function MentorshipAvailabilitySection({ control, errors }: FormS - onChange(e.target.value === '' ? 0 : Number(e.target.value)) - } + onChange={(e) => { + const nextHours = e.target.value === '' ? 0 : Number(e.target.value); + onChange(nextHours); + setValue?.(`monthAvailability.${index}.enabled`, nextHours > 0); + }} type="number" size="small" label="hours" diff --git a/admin-wcc-app/components/EditMentor/types.ts b/admin-wcc-app/components/EditMentor/types.ts index 133e843c..b2b59ce8 100644 --- a/admin-wcc-app/components/EditMentor/types.ts +++ b/admin-wcc-app/components/EditMentor/types.ts @@ -1,4 +1,4 @@ -import { Control, FieldErrors } from 'react-hook-form'; +import { Control, FieldErrors, UseFormSetValue } from 'react-hook-form'; import { EditMentorFormData } from './schema'; export type { EditMentorFormData } from './schema'; @@ -6,4 +6,5 @@ export type { EditMentorFormData } from './schema'; export interface FormSectionProps { control: Control; errors: FieldErrors; + setValue?: UseFormSetValue; } diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MenteeSection.java b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MenteeSection.java index 02163240..bb345c6e 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MenteeSection.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MenteeSection.java @@ -52,11 +52,13 @@ public MenteeSection toDto() { /** * Converts to a DTO scoped to the given mentorship cycle. For AD_HOC cycles the adHoc - * availability list is filtered to only the entries whose month matches the cycle month, so that - * mentors unavailable in the current cycle month are not surfaced by the AD_HOC type filter. + * availability list is filtered to only the entries whose month matches the cycle month and that + * declare more than zero hours, so that mentors unavailable in the current cycle month (or with no + * real availability, i.e. 0 hours) are not surfaced by the AD_HOC type filter. * * @param cycle the active mentorship cycle; when null or LONG_TERM the full adHoc list is kept - * @return a MenteeSection DTO with adHoc availability filtered to the current cycle month + * @return a MenteeSection DTO with adHoc availability filtered to the current cycle month and to + * entries with positive hours */ public MenteeSection toDtoForCycle(final MentorshipCycle cycle) { if (cycle == null @@ -66,7 +68,10 @@ public MenteeSection toDtoForCycle(final MentorshipCycle cycle) { return toDto(); } final List filteredAdHoc = - adHoc.stream().filter(a -> Objects.equals(a.month(), cycle.month())).toList(); + adHoc.stream() + .filter(a -> Objects.equals(a.month(), cycle.month())) + .filter(a -> a.hours() != null && a.hours() > 0) + .toList(); return new MenteeSection(idealMentee, additional, longTerm, filteredAdHoc); } }