feat(dashboard): Admin UI regions v2 (#6943)
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export * from "./auth"
|
||||
export * from "./store"
|
||||
export * from "./campaign"
|
||||
export * from "./currencies"
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { RegionDTO } from "@medusajs/types"
|
||||
import { adminRegionKeys, useAdminCustomQuery } from "medusa-react"
|
||||
import { V2ListRes } from "./types/common"
|
||||
|
||||
export const useV2Regions = (query?: any, options?: any) => {
|
||||
const { data, ...rest } = useAdminCustomQuery(
|
||||
"/regions",
|
||||
adminRegionKeys.list(query),
|
||||
query,
|
||||
options
|
||||
)
|
||||
|
||||
const typedData: {
|
||||
regions: RegionDTO[] | undefined
|
||||
} & V2ListRes = {
|
||||
regions: data?.regions,
|
||||
count: data?.count,
|
||||
offset: data?.offset,
|
||||
limit: data?.limit,
|
||||
}
|
||||
|
||||
return { ...typedData, ...rest }
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import {
|
||||
adminStoreKeys,
|
||||
useAdminCustomPost,
|
||||
useAdminCustomQuery,
|
||||
} from "medusa-react"
|
||||
import { Store } from "./types/store"
|
||||
|
||||
// TODO: Add types once we export V2 API types
|
||||
export const useV2Store = (options?: any) => {
|
||||
const { data, isLoading, isError, error, ...rest } = useAdminCustomQuery(
|
||||
"/admin/stores",
|
||||
adminStoreKeys.details(),
|
||||
undefined,
|
||||
options
|
||||
)
|
||||
|
||||
const store = data?.stores[0] as Store | undefined
|
||||
|
||||
let hasError = isError
|
||||
let err: Error | null = error
|
||||
|
||||
if (!isLoading && !isError && typeof store === "undefined") {
|
||||
hasError = true
|
||||
err = new Error("Store not found")
|
||||
}
|
||||
|
||||
return { store, isLoading, isError: hasError, error: err, ...rest }
|
||||
}
|
||||
|
||||
export const useV2UpdateStore = (id: string) => {
|
||||
return useAdminCustomPost(`/admin/stores/${id}`, adminStoreKeys.detail(id))
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { CurrencyDTO, StoreDTO } from "@medusajs/types"
|
||||
import { CurrencyDTO, PaymentProviderDTO, StoreDTO } from "@medusajs/types"
|
||||
|
||||
export type Store = StoreDTO & {
|
||||
default_currency: CurrencyDTO | null
|
||||
currencies?: CurrencyDTO[]
|
||||
payment_providers?: PaymentProviderDTO[]
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { customers } from "./customers"
|
||||
import { invites } from "./invites"
|
||||
import { productTypes } from "./product-types"
|
||||
import { products } from "./products"
|
||||
import { payments } from "./payments"
|
||||
import { promotions } from "./promotions"
|
||||
import { regions } from "./regions"
|
||||
import { salesChannels } from "./sales-channels"
|
||||
@@ -26,6 +27,7 @@ export const client = {
|
||||
currencies: currencies,
|
||||
collections: collections,
|
||||
promotions: promotions,
|
||||
payments: payments,
|
||||
stores: stores,
|
||||
salesChannels: salesChannels,
|
||||
tags: tags,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { getRequest } from "./common"
|
||||
import { PaymentProvidersListRes } from "../../types/api-responses"
|
||||
|
||||
async function listPaymentProviders(query?: Record<string, any>) {
|
||||
return getRequest<PaymentProvidersListRes, Record<string, any>>(
|
||||
`/admin/payments/payment-providers`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
export const payments = {
|
||||
listPaymentProviders,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/** This file is auto-generated. Do not modify it manually. */
|
||||
import type { Country } from "@medusajs/medusa"
|
||||
import type { RegionCountryDTO } from "@medusajs/types"
|
||||
|
||||
export const countries: Omit<Country, "region" | "region_id" | "id">[] = [
|
||||
export const countries: Omit<RegionCountryDTO, "id">[] = [
|
||||
{
|
||||
iso_2: "af",
|
||||
iso_3: "afg",
|
||||
@@ -888,8 +888,8 @@ export const countries: Omit<Country, "region" | "region_id" | "id">[] = [
|
||||
iso_2: "ly",
|
||||
iso_3: "lby",
|
||||
num_code: 434,
|
||||
name: "LIBYAN ARAB JAMAHIRIYA",
|
||||
display_name: "Libyan Arab Jamahiriya",
|
||||
name: "LIBYA",
|
||||
display_name: "Libya",
|
||||
},
|
||||
{
|
||||
iso_2: "li",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** This file is auto-generated. Do not modify it manually. */
|
||||
type CurrencyInfo = {
|
||||
export type CurrencyInfo = {
|
||||
code: string
|
||||
name: string
|
||||
symbol_native: string
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
/**
|
||||
* Providers only have an ID to identify them. This function formats the ID
|
||||
* into a human-readable string.
|
||||
*
|
||||
* Format example: pp_stripe-blik_dkk
|
||||
*
|
||||
* @param id - The ID of the provider
|
||||
* @returns A formatted string
|
||||
*/
|
||||
export const formatProvider = (id: string) => {
|
||||
return id
|
||||
.split("-")
|
||||
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
||||
.join(" ")
|
||||
const [_, name, type] = id.split("_")
|
||||
return (
|
||||
name
|
||||
.split("-")
|
||||
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
||||
.join(" ") + (type ? ` (${type})` : "")
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user