Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ <h2 id="modal-title" class="text-xl font-semibold" data-testid="add-event-title"
<!-- Food Tab -->
<mat-tab [label]="foodTab" data-testid="food-tab">
<form [formGroup]="foodForm" class="event-form" data-testid="food-form">
<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ eventTimeLabel }}</mat-label>
<input
matInput
type="datetime-local"
formControlName="eventTime"
[attr.aria-label]="eventTimeLabel"
data-testid="food-event-time-input"
/>
@if (foodForm.controls.eventTime.hasError('required')) {
<mat-error>{{ eventTimeRequiredLabel }}</mat-error>
}
</mat-form-field>

<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ carbsLabel }}</mat-label>
<input
Expand Down Expand Up @@ -85,6 +99,20 @@ <h2 id="modal-title" class="text-xl font-semibold" data-testid="add-event-title"
<!-- Insulin Tab -->
<mat-tab [label]="insulinTab" data-testid="insulin-tab">
<form [formGroup]="insulinForm" class="event-form" data-testid="insulin-form">
<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ eventTimeLabel }}</mat-label>
<input
matInput
type="datetime-local"
formControlName="eventTime"
[attr.aria-label]="eventTimeLabel"
data-testid="insulin-event-time-input"
/>
@if (insulinForm.controls.eventTime.hasError('required')) {
<mat-error>{{ eventTimeRequiredLabel }}</mat-error>
}
</mat-form-field>

<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ insulinTypeLabel }}</mat-label>
<mat-select formControlName="insulinType" data-testid="insulin-type-select">
Expand Down Expand Up @@ -166,6 +194,20 @@ <h2 id="modal-title" class="text-xl font-semibold" data-testid="add-event-title"
<!-- Exercise Tab -->
<mat-tab [label]="exerciseTab" data-testid="exercise-tab">
<form [formGroup]="exerciseForm" class="event-form" data-testid="exercise-form">
<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ eventTimeLabel }}</mat-label>
<input
matInput
type="datetime-local"
formControlName="eventTime"
[attr.aria-label]="eventTimeLabel"
data-testid="exercise-event-time-input"
/>
@if (exerciseForm.controls.eventTime.hasError('required')) {
<mat-error>{{ eventTimeRequiredLabel }}</mat-error>
}
</mat-form-field>

<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ exerciseTypeLabel }}</mat-label>
<mat-select formControlName="exerciseTypeId">
Expand Down Expand Up @@ -226,6 +268,20 @@ <h2 id="modal-title" class="text-xl font-semibold" data-testid="add-event-title"
<!-- Note Tab -->
<mat-tab [label]="noteTab" data-testid="note-tab">
<form [formGroup]="noteForm" class="event-form" data-testid="note-form">
<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ eventTimeLabel }}</mat-label>
<input
matInput
type="datetime-local"
formControlName="eventTime"
[attr.aria-label]="eventTimeLabel"
data-testid="note-event-time-input"
/>
@if (noteForm.controls.eventTime.hasError('required')) {
<mat-error>{{ eventTimeRequiredLabel }}</mat-error>
}
</mat-form-field>

<mat-form-field appearance="outline" class="form-field">
<mat-label>{{ noteLabel }}</mat-label>
<textarea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,18 @@ export class AddEventModalComponent {
readonly isSubmitting = signal<boolean>(false);
readonly error = signal<string | undefined>(undefined);

/**
* Returns a datetime-local formatted string for "now" (YYYY-MM-DDTHH:mm)
*/
private getNowLocalDateTime(): string {
const d = new Date();
const pad = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
}

// Forms
readonly foodForm = this.fb.group({
eventTime: [this.getNowLocalDateTime(), [Validators.required]],
carbohydratesGrams: [
null as number | null,
[Validators.required, Validators.min(0), Validators.max(300)]
Expand All @@ -63,6 +73,7 @@ export class AddEventModalComponent {
});

readonly insulinForm = this.fb.group({
eventTime: [this.getNowLocalDateTime(), [Validators.required]],
insulinType: ['Fast', Validators.required],
insulinUnits: [
null as number | null,
Expand All @@ -75,6 +86,7 @@ export class AddEventModalComponent {
});

readonly exerciseForm = this.fb.group({
eventTime: [this.getNowLocalDateTime(), [Validators.required]],
exerciseTypeId: [null as number | null, Validators.required],
durationMinutes: [
null as number | null,
Expand All @@ -85,6 +97,7 @@ export class AddEventModalComponent {
});

readonly noteForm = this.fb.group({
eventTime: [this.getNowLocalDateTime(), [Validators.required]],
noteText: ['', [Validators.required, Validators.maxLength(500)]]
});

Expand Down Expand Up @@ -139,6 +152,10 @@ export class AddEventModalComponent {
readonly intensityLabel = $localize`:@@dashboard.addEvent.exercise.intensity:Intensity`;
readonly exerciseNoteLabel = $localize`:@@dashboard.addEvent.exercise.note:Note`;

// Common date & time label
readonly eventTimeLabel = $localize`:@@dashboard.addEvent.eventTime:Date & Time`;
readonly eventTimeRequiredLabel = $localize`:@@dashboard.addEvent.eventTime.required:Date & time are required`;

/**
* Handles tab change and resets forms
*/
Expand All @@ -153,12 +170,14 @@ export class AddEventModalComponent {
*/
private resetAllForms(): void {
this.foodForm.reset({
eventTime: this.getNowLocalDateTime(),
carbohydratesGrams: null,
mealTagId: null,
absorptionHint: '',
note: ''
});
this.insulinForm.reset({
eventTime: this.getNowLocalDateTime(),
insulinType: 'Fast',
insulinUnits: null,
preparation: '',
Expand All @@ -167,12 +186,14 @@ export class AddEventModalComponent {
note: ''
});
this.exerciseForm.reset({
eventTime: this.getNowLocalDateTime(),
exerciseTypeId: null,
durationMinutes: null,
intensity: '',
note: ''
});
this.noteForm.reset({
eventTime: this.getNowLocalDateTime(),
noteText: ''
});
}
Expand Down Expand Up @@ -213,7 +234,7 @@ export class AddEventModalComponent {

const value = this.foodForm.value;
const payload = {
eventTime: new Date().toISOString(),
eventTime: new Date(value.eventTime!).toISOString(),
carbohydratesGrams: value.carbohydratesGrams!,
mealTagId: value.mealTagId ?? undefined,
absorptionHint: value.absorptionHint || undefined,
Expand Down Expand Up @@ -250,7 +271,7 @@ export class AddEventModalComponent {

const value = this.insulinForm.value;
const payload = {
eventTime: new Date().toISOString(),
eventTime: new Date(value.eventTime!).toISOString(),
insulinType: value.insulinType!,
insulinUnits: value.insulinUnits!,
preparation: value.preparation || undefined,
Expand Down Expand Up @@ -289,7 +310,7 @@ export class AddEventModalComponent {

const value = this.exerciseForm.value;
const payload = {
eventTime: new Date().toISOString(),
eventTime: new Date(value.eventTime!).toISOString(),
exerciseTypeId: value.exerciseTypeId!,
durationMinutes: value.durationMinutes!,
intensity: value.intensity || undefined,
Expand Down Expand Up @@ -326,7 +347,7 @@ export class AddEventModalComponent {

const value = this.noteForm.value;
const payload = {
eventTime: new Date().toISOString(),
eventTime: new Date(value.eventTime!).toISOString(),
noteText: value.noteText!
};

Expand Down
Loading
Loading