fix: clear start and end before applying a template to an availability selection

The start and end might already be set before selecting a template, it should always be cleared and if the template is uniform it can update the start and endtime to the correct value
This commit is contained in:
Freek van de Ven 2024-07-24 13:38:41 +02:00
parent 40d80801a0
commit 17fc6ad9f6

View file

@ -150,7 +150,7 @@ class AvailabilityViewModel {
} }
} }
return copyWith( return clearTimeAndBreak().copyWith(
templates: [template], templates: [template],
breaks: breaks, breaks: breaks,
conflictingPauses: conflictingPauses, conflictingPauses: conflictingPauses,
@ -161,12 +161,27 @@ class AvailabilityViewModel {
); );
} }
/// /// Removes the templates from the availability
AvailabilityViewModel removeTemplates() => copyWith( AvailabilityViewModel removeTemplates() => copyWith(
templates: [], templates: [],
templateSelected: false, templateSelected: false,
); );
/// Removes the time and breaks from the availability
AvailabilityViewModel clearTimeAndBreak() => AvailabilityViewModel(
selectedRange: selectedRange,
templates: templates,
ids: ids,
userId: userId,
startTime: null,
endTime: null,
breaks: [],
clearAvailability: clearAvailability,
conflictingPauses: conflictingPauses,
conflictingTime: conflictingTime,
templateSelected: templateSelected,
);
/// create a AvailabilityModel from the current AvailabilityViewModel /// create a AvailabilityModel from the current AvailabilityViewModel
AvailabilityModel toModel() { AvailabilityModel toModel() {
var startDate = DateTime( var startDate = DateTime(