Skip to content

Commit dca6de3

Browse files
committed
fix(meetings): improve type safety in weekly day change handler
- Update onWeeklyDayChange method to accept Event instead of boolean - Remove need for $any() type casting in template - Add validation for parseInt conversion to prevent NaN values - Use Number() with isNaN checks to filter invalid weekly_days strings - Prevent accessing undefined array indices from malformed data LFXV2-483 Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Asitha de Silva <asithade@gmail.com>
1 parent 3168914 commit dca6de3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

apps/lfx-pcc/src/app/modules/project/meetings/components/meeting-recurrence-pattern/meeting-recurrence-pattern.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h4 class="text-base font-medium text-gray-900 mb-4">2. Pattern Details</h4>
5353
[class.bg-blue-50]="isWeeklyDaySelected(i)"
5454
[class.border-blue-300]="isWeeklyDaySelected(i)"
5555
[attr.data-testid]="'recurrence-day-' + day.label.toLowerCase()">
56-
<input type="checkbox" [checked]="isWeeklyDaySelected(i)" (change)="onWeeklyDayChange(i, $any($event.target).checked)" class="sr-only" />
56+
<input type="checkbox" [checked]="isWeeklyDaySelected(i)" (change)="onWeeklyDayChange(i, $event)" class="sr-only" />
5757
<span class="text-xs font-medium text-gray-700">{{ day.label }}</span>
5858
</label>
5959
}

apps/lfx-pcc/src/app/modules/project/meetings/components/meeting-recurrence-pattern/meeting-recurrence-pattern.component.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export class MeetingRecurrencePatternComponent implements OnInit {
6262
// Pattern type change handlers
6363

6464
// Weekly days handlers
65-
public onWeeklyDayChange(dayIndex: number, checked: boolean): void {
65+
public onWeeklyDayChange(dayIndex: number, event: Event): void {
66+
const checkbox = event.target as HTMLInputElement;
67+
const checked = checkbox.checked;
6668
const currentDays = this.weeklyDaysArray();
6769
let newDays: number[];
6870

@@ -262,7 +264,13 @@ export class MeetingRecurrencePatternComponent implements OnInit {
262264

263265
// Update weeklyDaysArray signal
264266
if (recurrenceValue.weekly_days) {
265-
const daysArray = recurrenceValue.weekly_days.split(',').map((d: string) => parseInt(d.trim()) - 1);
267+
const daysArray = recurrenceValue.weekly_days
268+
.split(',')
269+
.map((d: string) => {
270+
const num = Number(d.trim());
271+
return isNaN(num) ? null : num - 1;
272+
})
273+
.filter((d: number | null): d is number => d !== null);
266274
this.weeklyDaysArray.set(daysArray);
267275
} else {
268276
this.weeklyDaysArray.set([]);
@@ -295,7 +303,13 @@ export class MeetingRecurrencePatternComponent implements OnInit {
295303
const recurrenceForm = this.recurrenceForm();
296304
if (!recurrenceForm || !currentValue.weekly_days) return;
297305

298-
const currentDays = currentValue.weekly_days.split(',').map((d: string) => parseInt(d.trim()));
306+
const currentDays = currentValue.weekly_days
307+
.split(',')
308+
.map((d: string) => {
309+
const num = Number(d.trim());
310+
return isNaN(num) ? null : num;
311+
})
312+
.filter((d: number | null): d is number => d !== null);
299313

300314
// If only one day is selected, update it to the new day
301315
if (currentDays.length === 1) {

0 commit comments

Comments
 (0)