Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brage-andreas committed Sep 13, 2024
1 parent bc56fa7 commit cd492f6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/profile/components/Settings/Penalties/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd492f6

Please sign in to comment.