Skip to content

Commit

Permalink
(bug) unable to update availability slot end time for training
Browse files Browse the repository at this point in the history
  • Loading branch information
gnepud committed May 17, 2024
1 parent c2db982 commit 53b5b36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Next release

- Fix a bug: unable to update availability slot end time for training

## v6.3.22 2024 Avril 29

- Fix a security issue: updated rails to 7.0.8.1 to fix [CVE-2024-26143](https://github.com/rails/rails/security/advisories/GHSA-9822-6m93-xqf4)
Expand Down
21 changes: 9 additions & 12 deletions app/frontend/src/javascript/controllers/admin/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,18 +1009,6 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui
$scope.availability.start_at = $scope.start;
});

// Maintain consistency between the end time and the date object in the availability object
$scope.$watch('end', function (newValue, oldValue, scope) {
if (newValue.valueOf() !== oldValue.valueOf()) {
// we prevent the admin from setting the end of the availability before its beginning
if (moment($scope.start).add($scope.availability.slot_duration, 'minutes').isAfter(newValue)) {
$scope.end = oldValue;
}
// update availability object
$scope.availability.end_at = $scope.end;
}
});

$scope.$watch('startTime', function (newValue, oldValue, scope) {
// adjust the start/endTime
const start = moment($scope.start);
Expand All @@ -1031,6 +1019,15 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui
$scope.start = start.toDate();
$scope.endTime = endTime.toDate();
});

$scope.$watch('endTime', function (newValue, oldValue, scope) {
// adjust the start/endTime
const end = moment($scope.end);
const diff = moment.tz(newValue, moment.tz.guess()).diff(moment.tz(oldValue, moment.tz.guess()));
end.add(diff, 'milliseconds');
$scope.end = end.toDate();
$scope.availability.end_at = $scope.end;
});
};

/*
Expand Down

0 comments on commit 53b5b36

Please sign in to comment.