All files / packages/ui/src/components/QuickSelect utils.ts

100% Statements 8/8
100% Branches 8/8
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28        3x       18x         3x       4x 1x     3x 3x     3x    
import { isSameDay } from "@repo/utils/date";
 
import type { QuickSelectOption, QuickSelectValue } from "./types";
 
export const isMatchingQuickSelectOption = (
  current: QuickSelectValue | null,
  option: QuickSelectValue,
): boolean =>
  !!current &&
  isSameDay(current.startDate, option.startDate) &&
  isSameDay(current.endDate, option.endDate) &&
  current.timeSlot === option.timeSlot;
 
export const findMatchingQuickSelectValue = (
  value: QuickSelectValue | null,
  options: QuickSelectOption[],
): QuickSelectValue | null => {
  if (!value) {
    return null;
  }
 
  const matchedOption = options.find((option) =>
    isMatchingQuickSelectOption(value, option.value),
  );
 
  return matchedOption ? matchedOption.value : null;
};