All files / src/features/MerchantPortal/DeveloperApi apiKeyUtils.tsx

100% Statements 3/3
50% Branches 6/12
100% Functions 2/2
100% Lines 3/3

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                2x 7x                                                                                                           7x            
import { format } from "date-fns";
import ApiKeyStatus from "./components/ApiKeyStatus";
import ApiKeyCreatorInfo from "./components/ApiKeyCreatorInfo";
 
interface RowData {
  isSandbox: boolean;
  statusDisplayName: string;
  createdAt: number;
  createdBy: string;
  createdByAvatarURL?: string;
  createdByRole: string;
  lastUsedAt?: number;
  allowedOrigins: string[];
  isDisabled?: boolean;
}
 
export const getApiKeyValues = (rowData: RowData) => {
  return [
    {
      id: 0,
      key: "Environment",
      value: rowData.isSandbox ? "Sandbox" : "Production",
    },
    {
      id: 1,
      key: "Status",
      value: (
        <ApiKeyStatus
          label={
            rowData.isDisabled
              ? "Declined"
              : rowData.statusDisplayName === "Rolled"
              ? "Suspended"
              : rowData.statusDisplayName
          }
        />
      ),
    },
    {
      id: 2,
      key: "Creation Date",
      value: format(rowData.createdAt * 1000, "MMM dd, yyyy, p"),
    },
    {
      id: 3,
      key: "Created By",
      value: (
        <ApiKeyCreatorInfo
          createdBy={rowData.createdBy}
          createdByRole={rowData.createdByRole}
          createdByAvatarURL={rowData.createdByAvatarURL}
        />
      ),
    },
    {
      id: 4,
      key: "Last Used",
      value: rowData.lastUsedAt
        ? format(rowData.lastUsedAt * 1000, "MMM d, yyyy, p")
        : "-",
    },
    {
      id: 5,
      key: "Rate Limit",
      value: "1000/Day", // We dont have this value backend wise, it remains static
    },
    {
      id: 6,
      key: "Allowed Origin",
      value: rowData.allowedOrigins.length
        ? rowData.allowedOrigins
            .map((item) => (item === "*" ? "All" : item))
            .join(", ")
        : "-",
    },
  ];
};