From cd492f6ddf2fad78cff6a1a972b1dbcc508c2a78 Mon Sep 17 00:00:00 2001 From: brage-andreas Date: Fri, 13 Sep 2024 14:11:07 +0200 Subject: [PATCH] refactor: cleanup --- .../components/Settings/Penalties/Rules.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/profile/components/Settings/Penalties/Rules.tsx b/src/profile/components/Settings/Penalties/Rules.tsx index e52f1ad6..8c43efe3 100644 --- a/src/profile/components/Settings/Penalties/Rules.tsx +++ b/src/profile/components/Settings/Penalties/Rules.tsx @@ -21,16 +21,19 @@ const getLatestRuleSet = (rules: IMarkRule[]): IMarkRule | null => { return null; } - if (rules.length === 1) { - return inFuture(rules[0].valid_from_date) ? null : rules[0]; - } - const ruleset = rules.reduce((latest, rule) => { - if (inFuture(rule.valid_from_date)) { + const isLatestInFuture = inFuture(latest.valid_from_date); + const isRuleInFuture = inFuture(rule.valid_from_date); + + if (isRuleInFuture) { return latest; } - return rule.valid_from_date > latest.valid_from_date ? rule : latest; + if (isLatestInFuture || rule.valid_from_date > latest.valid_from_date) { + return rule; + } + + return latest; }, rules[0]); return inFuture(ruleset.valid_from_date) ? null : ruleset;