Files
medusa-store/packages/admin-next/dashboard/src/v2-routes/api-key-management/common/utils.ts
Kasper Fabricius Kristensen 21be6ff7ed feat(dashboard): Secret keys domain (#7030)
* setup secret keys

* add secret keys

* fix merge
2024-04-09 15:11:32 +02:00

49 lines
1.1 KiB
TypeScript

import { AdminApiKeyResponse } from "@medusajs/types"
import { TFunction } from "i18next"
import { ApiKeyType } from "./constants"
export function getApiKeyTypeFromPathname(pathname: string) {
const isSecretKey = pathname.startsWith("/settings/api-key-management/secret")
switch (isSecretKey) {
case true:
return ApiKeyType.SECRET
case false:
return ApiKeyType.PUBLISHABLE
}
}
export function getApiKeyStatusProps(
revokedAt: Date | string | null,
t: TFunction
): { color: "red" | "green"; label: string } {
if (!revokedAt) {
return {
color: "green",
label: t("apiKeyManagement.status.active"),
}
}
return {
color: "red",
label: t("apiKeyManagement.status.revoked"),
}
}
export function getApiKeyTypeProps(
type: AdminApiKeyResponse["api_key"]["type"],
t: TFunction
): { color: "green" | "blue"; label: string } {
if (type === ApiKeyType.PUBLISHABLE) {
return {
color: "green",
label: t("apiKeyManagement.type.publishable"),
}
}
return {
color: "blue",
label: t("apiKeyManagement.type.secret"),
}
}