All files / src/components/common/Modal/DeleteModal utils.tsx

92.3% Statements 12/13
83.33% Branches 5/6
100% Functions 4/4
100% Lines 10/10

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 33 34 35 36 37 38 39 40 41 42 43                          13x 13x     9x   76x 15x 13x       12x     9x 9x                     9x    
import { CampaignType } from "@common/Campaigns/hooks/useReportMenuActions";
import {
  QKEY_LIST_EVENTS,
  QKEY_LIST_FUNDRAISERS,
  QKEY_LIST_INVOICES,
  QKEY_LIST_MEMBERSHIPS,
  QKEY_LIST_PAYMENT_FORMS,
  QKEY_LIST_PRODUCTS,
  QKEY_LIST_SWEEPSTAKES,
} from "@constants/queryKeys";
import { replace, startCase, toLower } from "lodash";
 
function appendLetter(str: string, letter: string) {
  Iif (!str) return "";
  return `${str}${letter}`;
}
 
export const parsedNavigationKey = (productVariant?: string) => {
  // ensure the navigation key is always in plural form (ends with 's')
  if (!productVariant) return "";
  if (productVariant[productVariant.length - 1] === "s") return productVariant;
  else return appendLetter(productVariant, "s");
};
 
export function productVarinatParser(value: string) {
  return startCase(toLower(replace(value, /-/g, " ")));
}
 
export const getProductRefetchQuery = (variant: CampaignType) => {
  const productRefetchQuery: Record<CampaignType, string> = {
    fundraiser: QKEY_LIST_FUNDRAISERS,
    event: QKEY_LIST_EVENTS,
    invoice: QKEY_LIST_INVOICES,
    membership: QKEY_LIST_MEMBERSHIPS,
    sweepstake: QKEY_LIST_SWEEPSTAKES,
    "payment-form": QKEY_LIST_PAYMENT_FORMS,
    standard: QKEY_LIST_PRODUCTS,
    product: QKEY_LIST_PRODUCTS,
  };
 
  return productRefetchQuery[variant];
};