From 36f00f456bbd78276a91ff7372a086cc8d343920 Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Wed, 14 Aug 2024 10:38:20 +0200
Subject: [PATCH] 2000: Minor fixes
---
src/components/util/schedule/schedule.jsx | 30 +++++++++++++++--------
src/translations/da/common.json | 13 +++++-----
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/src/components/util/schedule/schedule.jsx b/src/components/util/schedule/schedule.jsx
index 22748bcd..7e931d4e 100644
--- a/src/components/util/schedule/schedule.jsx
+++ b/src/components/util/schedule/schedule.jsx
@@ -39,6 +39,7 @@ function Schedule({ schedules, onChange }) {
const byMonthOptions = getByMonthOptions(t);
const [localSchedules, setLocalSchedules] = useState([]);
const [durationError, setDurationError] = useState(false);
+ const [activatedRepeatIds, setActivatedRepeatIds] = useState({});
useEffect(() => {
const newSchedules = schedules.map((schedule) =>
@@ -209,7 +210,7 @@ function Schedule({ schedules, onChange }) {
}
const isRepeatingEvent = (schedule) => {
- return !(schedule.duration === 60 * 60 &&
+ return !(
schedule.freq === RRule.DAILY &&
schedule.count === 1 &&
schedule.until === undefined &&
@@ -221,11 +222,19 @@ function Schedule({ schedules, onChange }) {
schedule.byweekno === undefined);
}
+ const displayRepeat = (schedule) => {
+ return isRepeatingEvent(schedule) || activatedRepeatIds[schedule.id] === true;
+ }
+
+ const updateActivatedRepeats = (id, value) => {
+ const updated = {...activatedRepeatIds};
+ updated[id] = value;
+ setActivatedRepeatIds(updated);
+ }
+
const toggleRepeat = (schedule) => {
- if ((isRepeatingEvent(schedule) || schedule.repeatActivated)) {
+ if (displayRepeat(schedule)) {
// Disable repeating schedule.
- changeSchedule(schedule.id, 'repeatActivated', false);
- changeSchedule(schedule.id, 'duration', 60 * 60);
changeSchedule(schedule.id, 'freq', RRule.DAILY);
changeSchedule(schedule.id, 'count', 1);
changeSchedule(schedule.id, 'interval', null);
@@ -235,10 +244,11 @@ function Schedule({ schedules, onChange }) {
changeSchedule(schedule.id, 'byweekday', null);
changeSchedule(schedule.id, 'bymonth', null);
changeSchedule(schedule.id, 'byweekno', null);
+ updateActivatedRepeats(schedule.id, false);
} else {
// Activate repeating schedule.
- changeSchedule(schedule.id, 'repeatActivated', true);
changeSchedule(schedule.id, 'count', null);
+ updateActivatedRepeats(schedule.id, true);
}
}
@@ -307,13 +317,13 @@ function Schedule({ schedules, onChange }) {
onChange={() => toggleRepeat(schedule)}
name="enableRepeat"
type="checkbox"
- value={(isRepeatingEvent(schedule) || schedule.repeatActivated)}
+ value={displayRepeat(schedule)}
label={t('schedule.enable-repeat')}
formGroupClasses="d-inline-block mb-2"
/>