All files / src/components/Disputes/DisputesList/hooks useDisputesQueryString.ts

71.42% Statements 10/14
25% Branches 2/8
100% Functions 3/3
76.92% Lines 10/13

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 29 30 31 32            263x 98x 116x   98x   98x 15x   15x                 15x   15x     98x    
import { useAppSelector } from "@redux/hooks";
import { selectDateFilter } from "@redux/slices/merchantFilters";
import { selectedQueryString } from "@redux/slices/tableFilters";
import { addDays, getUnixTime } from "date-fns";
import { useMemo } from "react";
 
export const useDisputesQueryString = () => {
  const selectedDate = useAppSelector((state) =>
    selectDateFilter(state, "dispute-date"),
  );
  const contextQueryString = useAppSelector(selectedQueryString);
 
  const queryString = useMemo(() => {
    let query = "";
 
    Iif (selectedDate) {
      const unixDate = selectedDate ? getUnixTime(new Date(selectedDate)) : 0;
      const maxDate = selectedDate
        ? getUnixTime(addDays(new Date(selectedDate), 1))
        : 0;
 
      query = `(createdAt:>d${unixDate}%3BcreatedAt:<=d${maxDate})%3B`;
    }
 
    Iif (contextQueryString) query += contextQueryString;
 
    return query;
  }, [selectedDate, contextQueryString]);
 
  return { queryString };
};