feat(sdk): Replace region calls with the SDK in admin, apply typings … (#7371)
This commit is contained in:
1 parent
521b4e7926
commit
025536e2a5
30 files changed
+315
-185
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
"@medusajs/js-sdk": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Replace region calls with the SDK in admin, apply typings to sdk
|
||||||
@@ -7,7 +7,7 @@ export const useEmailPassLogin = (
|
|||||||
options?: UseMutationOptions<void, Error, EmailPassReq>
|
options?: UseMutationOptions<void, Error, EmailPassReq>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => sdk.auth.login(payload),
|
mutationFn: (payload) => sdk.auth.login("admin", "emailpass", payload),
|
||||||
onSuccess: async (data, variables, context) => {
|
onSuccess: async (data, variables, context) => {
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,15 +5,10 @@ import {
|
|||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
import { client } from "../../lib/client"
|
import { sdk } from "../../lib/client"
|
||||||
import { queryClient } from "../../lib/medusa"
|
import { queryClient } from "../../lib/medusa"
|
||||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||||
import { CreateRegionReq, UpdateRegionReq } from "../../types/api-payloads"
|
import { DeleteResponse, HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||||
import {
|
|
||||||
RegionDeleteRes,
|
|
||||||
RegionListRes,
|
|
||||||
RegionRes,
|
|
||||||
} from "../../types/api-responses"
|
|
||||||
|
|
||||||
const REGIONS_QUERY_KEY = "regions" as const
|
const REGIONS_QUERY_KEY = "regions" as const
|
||||||
const regionsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
|
const regionsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
|
||||||
@@ -22,13 +17,18 @@ export const useRegion = (
|
|||||||
id: string,
|
id: string,
|
||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<RegionRes, Error, RegionRes, QueryKey>,
|
UseQueryOptions<
|
||||||
|
{ region: HttpTypes.AdminRegion },
|
||||||
|
Error,
|
||||||
|
{ region: HttpTypes.AdminRegion },
|
||||||
|
QueryKey
|
||||||
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: regionsQueryKeys.detail(id),
|
queryKey: regionsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.regions.retrieve(id, query),
|
queryFn: async () => sdk.admin.region.retrieve(id, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -38,12 +38,17 @@ export const useRegion = (
|
|||||||
export const useRegions = (
|
export const useRegions = (
|
||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<RegionListRes, Error, RegionListRes, QueryKey>,
|
UseQueryOptions<
|
||||||
|
PaginatedResponse<{ regions: HttpTypes.AdminRegion[] }>,
|
||||||
|
Error,
|
||||||
|
PaginatedResponse<{ regions: HttpTypes.AdminRegion[] }>,
|
||||||
|
QueryKey
|
||||||
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.regions.list(query),
|
queryFn: () => sdk.admin.region.list(query),
|
||||||
queryKey: regionsQueryKeys.list(query),
|
queryKey: regionsQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -52,10 +57,14 @@ export const useRegions = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useCreateRegion = (
|
export const useCreateRegion = (
|
||||||
options?: UseMutationOptions<RegionRes, Error, CreateRegionReq>
|
options?: UseMutationOptions<
|
||||||
|
{ region: HttpTypes.AdminRegion },
|
||||||
|
Error,
|
||||||
|
HttpTypes.AdminCreateRegion
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.regions.create(payload),
|
mutationFn: (payload) => sdk.admin.region.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() })
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
@@ -66,10 +75,14 @@ export const useCreateRegion = (
|
|||||||
|
|
||||||
export const useUpdateRegion = (
|
export const useUpdateRegion = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<RegionRes, Error, UpdateRegionReq>
|
options?: UseMutationOptions<
|
||||||
|
{ region: HttpTypes.AdminRegion },
|
||||||
|
Error,
|
||||||
|
HttpTypes.AdminUpdateRegion
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.regions.update(id, payload),
|
mutationFn: (payload) => sdk.admin.region.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.detail(id) })
|
||||||
@@ -82,10 +95,10 @@ export const useUpdateRegion = (
|
|||||||
|
|
||||||
export const useDeleteRegion = (
|
export const useDeleteRegion = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<RegionDeleteRes, Error, void>
|
options?: UseMutationOptions<DeleteResponse<"region">, Error, void>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.regions.delete(id),
|
mutationFn: () => sdk.admin.region.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: regionsQueryKeys.detail(id) })
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { createColumnHelper } from "@tanstack/react-table"
|
import { createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
import { RegionDTO } from "@medusajs/types"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CountriesCell,
|
CountriesCell,
|
||||||
@@ -14,8 +13,9 @@ import {
|
|||||||
RegionCell,
|
RegionCell,
|
||||||
RegionHeader,
|
RegionHeader,
|
||||||
} from "../../../components/table/table-cells/region/region-cell"
|
} from "../../../components/table/table-cells/region/region-cell"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<RegionDTO>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminRegion>()
|
||||||
|
|
||||||
export const useRegionTableColumns = () => {
|
export const useRegionTableColumns = () => {
|
||||||
return useMemo(
|
return useMemo(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AdminGetRegionsParams } from "@medusajs/medusa"
|
import { FindParams, HttpTypes } from "@medusajs/types"
|
||||||
import { useQueryParams } from "../../use-query-params"
|
import { useQueryParams } from "../../use-query-params"
|
||||||
|
|
||||||
type UseRegionTableQueryProps = {
|
type UseRegionTableQueryProps = {
|
||||||
@@ -17,7 +17,7 @@ export const useRegionTableQuery = ({
|
|||||||
|
|
||||||
const { offset, q, order, created_at, updated_at } = queryObject
|
const { offset, q, order, created_at, updated_at } = queryObject
|
||||||
|
|
||||||
const searchParams: AdminGetRegionsParams = {
|
const searchParams: FindParams & HttpTypes.AdminRegionFilters = {
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: offset ? Number(offset) : 0,
|
offset: offset ? Number(offset) : 0,
|
||||||
order,
|
order,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { priceLists } from "./price-lists"
|
|||||||
import { productTypes } from "./product-types"
|
import { productTypes } from "./product-types"
|
||||||
import { products } from "./products"
|
import { products } from "./products"
|
||||||
import { promotions } from "./promotions"
|
import { promotions } from "./promotions"
|
||||||
import { regions } from "./regions"
|
|
||||||
import { orders } from "./orders"
|
import { orders } from "./orders"
|
||||||
import { fulfillments } from "./fulfillments"
|
import { fulfillments } from "./fulfillments"
|
||||||
import { reservations } from "./reservations"
|
import { reservations } from "./reservations"
|
||||||
@@ -45,7 +44,6 @@ export const client = {
|
|||||||
tags: tags,
|
tags: tags,
|
||||||
users: users,
|
users: users,
|
||||||
orders: orders,
|
orders: orders,
|
||||||
regions: regions,
|
|
||||||
taxes: taxes,
|
taxes: taxes,
|
||||||
invites: invites,
|
invites: invites,
|
||||||
inventoryItems: inventoryItems,
|
inventoryItems: inventoryItems,
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import { CreateRegionDTO, UpdateRegionDTO } from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
RegionDeleteRes,
|
|
||||||
RegionListRes,
|
|
||||||
RegionRes,
|
|
||||||
} from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrieveRegion(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<RegionRes>(`/admin/regions/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listRegions(query?: Record<string, any>) {
|
|
||||||
return getRequest<RegionListRes>(`/admin/regions`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createRegion(payload: CreateRegionDTO) {
|
|
||||||
return postRequest<RegionRes>(`/admin/regions`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateRegion(id: string, payload: UpdateRegionDTO) {
|
|
||||||
return postRequest<RegionRes>(`/admin/regions/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteRegion(id: string) {
|
|
||||||
return deleteRequest<RegionDeleteRes>(`/admin/regions/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const regions = {
|
|
||||||
retrieve: retrieveRegion,
|
|
||||||
list: listRegions,
|
|
||||||
create: createRegion,
|
|
||||||
update: updateRegion,
|
|
||||||
delete: deleteRegion,
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { AdminCollectionsRes, AdminProductsRes } from "@medusajs/medusa"
|
||||||
AdminCollectionsRes,
|
|
||||||
AdminProductsRes,
|
|
||||||
AdminRegionsRes,
|
|
||||||
} from "@medusajs/medusa"
|
|
||||||
import {
|
import {
|
||||||
AdminApiKeyResponse,
|
AdminApiKeyResponse,
|
||||||
AdminCustomerGroupResponse,
|
AdminCustomerGroupResponse,
|
||||||
@@ -11,6 +7,7 @@ import {
|
|||||||
AdminTaxRegionResponse,
|
AdminTaxRegionResponse,
|
||||||
SalesChannelDTO,
|
SalesChannelDTO,
|
||||||
UserDTO,
|
UserDTO,
|
||||||
|
HttpTypes,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { Outlet, RouteObject } from "react-router-dom"
|
import { Outlet, RouteObject } from "react-router-dom"
|
||||||
|
|
||||||
@@ -593,7 +590,8 @@ export const RouteMap: RouteObject[] = [
|
|||||||
path: ":id",
|
path: ":id",
|
||||||
lazy: () => import("../../v2-routes/regions/region-detail"),
|
lazy: () => import("../../v2-routes/regions/region-detail"),
|
||||||
handle: {
|
handle: {
|
||||||
crumb: (data: AdminRegionsRes) => data.region.name,
|
crumb: (data: { region: HttpTypes.AdminRegion }) =>
|
||||||
|
data.region.name,
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
CreateProductCollectionDTO,
|
CreateProductCollectionDTO,
|
||||||
CreatePromotionDTO,
|
CreatePromotionDTO,
|
||||||
CreatePromotionRuleDTO,
|
CreatePromotionRuleDTO,
|
||||||
CreateRegionDTO,
|
|
||||||
CreateSalesChannelDTO,
|
CreateSalesChannelDTO,
|
||||||
CreateServiceZoneDTO,
|
CreateServiceZoneDTO,
|
||||||
CreateShippingOptionDTO,
|
CreateShippingOptionDTO,
|
||||||
@@ -26,7 +25,6 @@ import {
|
|||||||
UpdateProductCollectionDTO,
|
UpdateProductCollectionDTO,
|
||||||
UpdatePromotionDTO,
|
UpdatePromotionDTO,
|
||||||
UpdatePromotionRuleDTO,
|
UpdatePromotionRuleDTO,
|
||||||
UpdateRegionDTO,
|
|
||||||
UpdateSalesChannelDTO,
|
UpdateSalesChannelDTO,
|
||||||
UpdateServiceZoneDTO,
|
UpdateServiceZoneDTO,
|
||||||
UpdateShippingOptionDTO,
|
UpdateShippingOptionDTO,
|
||||||
@@ -38,10 +36,6 @@ import {
|
|||||||
// Auth
|
// Auth
|
||||||
export type EmailPassReq = { email: string; password: string }
|
export type EmailPassReq = { email: string; password: string }
|
||||||
|
|
||||||
// Regions
|
|
||||||
export type CreateRegionReq = CreateRegionDTO
|
|
||||||
export type UpdateRegionReq = UpdateRegionDTO
|
|
||||||
|
|
||||||
// Stores
|
// Stores
|
||||||
export type UpdateStoreReq = UpdateStoreDTO
|
export type UpdateStoreReq = UpdateStoreDTO
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
ProductTypeDTO,
|
ProductTypeDTO,
|
||||||
ProductVariantDTO,
|
ProductVariantDTO,
|
||||||
PromotionDTO,
|
PromotionDTO,
|
||||||
RegionDTO,
|
|
||||||
SalesChannelDTO,
|
SalesChannelDTO,
|
||||||
ShippingOptionDTO,
|
ShippingOptionDTO,
|
||||||
ShippingProfileDTO,
|
ShippingProfileDTO,
|
||||||
@@ -69,11 +68,6 @@ export type ExtendedStoreDTO = StoreDTO & {
|
|||||||
export type StoreRes = { store: ExtendedStoreDTO }
|
export type StoreRes = { store: ExtendedStoreDTO }
|
||||||
export type StoreListRes = { stores: ExtendedStoreDTO[] } & ListRes
|
export type StoreListRes = { stores: ExtendedStoreDTO[] } & ListRes
|
||||||
|
|
||||||
// Regions
|
|
||||||
export type RegionRes = { region: RegionDTO }
|
|
||||||
export type RegionListRes = { regions: RegionDTO[] } & ListRes
|
|
||||||
export type RegionDeleteRes = DeleteRes
|
|
||||||
|
|
||||||
// Fulfillments
|
// Fulfillments
|
||||||
export type FulfillmentRes = { fulfillment: FulfillmentDTO }
|
export type FulfillmentRes = { fulfillment: FulfillmentDTO }
|
||||||
export type FulfillmentListRes = { fulfillments: FulfillmentDTO[] } & ListRes
|
export type FulfillmentListRes = { fulfillments: FulfillmentDTO[] } & ListRes
|
||||||
|
|||||||
+6
-6
@@ -10,7 +10,6 @@ import { useTranslation } from "react-i18next"
|
|||||||
import * as zod from "zod"
|
import * as zod from "zod"
|
||||||
|
|
||||||
import { Button, Checkbox, toast } from "@medusajs/ui"
|
import { Button, Checkbox, toast } from "@medusajs/ui"
|
||||||
import { RegionCountryDTO, RegionDTO } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
RouteFocusModal,
|
RouteFocusModal,
|
||||||
useRouteModal,
|
useRouteModal,
|
||||||
@@ -22,9 +21,10 @@ import { useCountries } from "../../../common/hooks/use-countries"
|
|||||||
import { useCountryTableColumns } from "../../../common/hooks/use-country-table-columns"
|
import { useCountryTableColumns } from "../../../common/hooks/use-country-table-columns"
|
||||||
import { useCountryTableQuery } from "../../../common/hooks/use-country-table-query"
|
import { useCountryTableQuery } from "../../../common/hooks/use-country-table-query"
|
||||||
import { useUpdateRegion } from "../../../../../hooks/api/regions"
|
import { useUpdateRegion } from "../../../../../hooks/api/regions"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type AddCountriesFormProps = {
|
type AddCountriesFormProps = {
|
||||||
region: RegionDTO
|
region: HttpTypes.AdminRegion
|
||||||
}
|
}
|
||||||
|
|
||||||
const AddCountriesSchema = zod.object({
|
const AddCountriesSchema = zod.object({
|
||||||
@@ -71,7 +71,7 @@ export const AddCountriesForm = ({ region }: AddCountriesFormProps) => {
|
|||||||
iso_3: c.iso_3,
|
iso_3: c.iso_3,
|
||||||
num_code: c.num_code,
|
num_code: c.num_code,
|
||||||
region_id: null,
|
region_id: null,
|
||||||
region: {} as RegionDTO,
|
region: {} as HttpTypes.AdminRegion,
|
||||||
})),
|
})),
|
||||||
...searchParams,
|
...searchParams,
|
||||||
})
|
})
|
||||||
@@ -102,7 +102,7 @@ export const AddCountriesForm = ({ region }: AddCountriesFormProps) => {
|
|||||||
|
|
||||||
const handleSubmit = form.handleSubmit(async (values) => {
|
const handleSubmit = form.handleSubmit(async (values) => {
|
||||||
const payload = [
|
const payload = [
|
||||||
...region.countries.map((c) => c.iso_2),
|
...(region.countries?.map((c) => c.iso_2) ?? []),
|
||||||
...values.countries,
|
...values.countries,
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ export const AddCountriesForm = ({ region }: AddCountriesFormProps) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<RegionCountryDTO>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminRegionCountry>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const base = useCountryTableColumns()
|
const base = useCountryTableColumns()
|
||||||
@@ -203,5 +203,5 @@ const useColumns = () => {
|
|||||||
...base,
|
...base,
|
||||||
],
|
],
|
||||||
[base]
|
[base]
|
||||||
) as ColumnDef<RegionCountryDTO>[]
|
) as ColumnDef<HttpTypes.AdminRegionCountry>[]
|
||||||
}
|
}
|
||||||
+9
-7
@@ -1,6 +1,5 @@
|
|||||||
import { PlusMini, Trash } from "@medusajs/icons"
|
import { PlusMini, Trash } from "@medusajs/icons"
|
||||||
import { Checkbox, Container, Heading, toast, usePrompt } from "@medusajs/ui"
|
import { Checkbox, Container, Heading, toast, usePrompt } from "@medusajs/ui"
|
||||||
import { RegionCountryDTO, RegionDTO } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
RowSelectionState,
|
RowSelectionState,
|
||||||
@@ -15,9 +14,10 @@ import { useCountries } from "../../../common/hooks/use-countries"
|
|||||||
import { useCountryTableColumns } from "../../../common/hooks/use-country-table-columns"
|
import { useCountryTableColumns } from "../../../common/hooks/use-country-table-columns"
|
||||||
import { useCountryTableQuery } from "../../../common/hooks/use-country-table-query"
|
import { useCountryTableQuery } from "../../../common/hooks/use-country-table-query"
|
||||||
import { useUpdateRegion } from "../../../../../hooks/api/regions"
|
import { useUpdateRegion } from "../../../../../hooks/api/regions"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type RegionCountrySectionProps = {
|
type RegionCountrySectionProps = {
|
||||||
region: RegionDTO
|
region: HttpTypes.AdminRegion
|
||||||
}
|
}
|
||||||
|
|
||||||
const PREFIX = "c"
|
const PREFIX = "c"
|
||||||
@@ -143,8 +143,8 @@ const CountryActions = ({
|
|||||||
country,
|
country,
|
||||||
region,
|
region,
|
||||||
}: {
|
}: {
|
||||||
country: RegionCountryDTO
|
country: HttpTypes.AdminRegionCountry
|
||||||
region: RegionDTO
|
region: HttpTypes.AdminRegion
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const prompt = usePrompt()
|
const prompt = usePrompt()
|
||||||
@@ -204,7 +204,7 @@ const CountryActions = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<RegionCountryDTO>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminRegionCountry>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const base = useCountryTableColumns()
|
const base = useCountryTableColumns()
|
||||||
@@ -243,12 +243,14 @@ const useColumns = () => {
|
|||||||
columnHelper.display({
|
columnHelper.display({
|
||||||
id: "actions",
|
id: "actions",
|
||||||
cell: ({ row, table }) => {
|
cell: ({ row, table }) => {
|
||||||
const { region } = table.options.meta as { region: RegionDTO }
|
const { region } = table.options.meta as {
|
||||||
|
region: HttpTypes.AdminRegion
|
||||||
|
}
|
||||||
|
|
||||||
return <CountryActions country={row.original} region={region} />
|
return <CountryActions country={row.original} region={region} />
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
[base]
|
[base]
|
||||||
) as ColumnDef<RegionCountryDTO>[]
|
) as ColumnDef<HttpTypes.AdminRegionCountry>[]
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,5 +1,4 @@
|
|||||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||||
import { RegionDTO } from "@medusajs/types"
|
|
||||||
import { Badge, Container, Heading, Text, toast, usePrompt } from "@medusajs/ui"
|
import { Badge, Container, Heading, Text, toast, usePrompt } from "@medusajs/ui"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
|
||||||
@@ -9,9 +8,10 @@ import { ListSummary } from "../../../../../components/common/list-summary"
|
|||||||
import { useDeleteRegion } from "../../../../../hooks/api/regions.tsx"
|
import { useDeleteRegion } from "../../../../../hooks/api/regions.tsx"
|
||||||
import { currencies } from "../../../../../lib/currencies"
|
import { currencies } from "../../../../../lib/currencies"
|
||||||
import { formatProvider } from "../../../../../lib/format-provider"
|
import { formatProvider } from "../../../../../lib/format-provider"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type RegionGeneralSectionProps = {
|
type RegionGeneralSectionProps = {
|
||||||
region: RegionDTO
|
region: HttpTypes.AdminRegion
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RegionGeneralSection = ({ region }: RegionGeneralSectionProps) => {
|
export const RegionGeneralSection = ({ region }: RegionGeneralSectionProps) => {
|
||||||
@@ -54,7 +54,7 @@ export const RegionGeneralSection = ({ region }: RegionGeneralSectionProps) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const RegionActions = ({ region }: { region: RegionDTO }) => {
|
const RegionActions = ({ region }: { region: HttpTypes.AdminRegion }) => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { mutateAsync } = useDeleteRegion(region.id)
|
const { mutateAsync } = useDeleteRegion(region.id)
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { AdminRegionsRes } from "@medusajs/medusa"
|
|
||||||
import { Response } from "@medusajs/medusa-js"
|
|
||||||
import { adminRegionKeys } from "medusa-react"
|
import { adminRegionKeys } from "medusa-react"
|
||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
import { client } from "../../../lib/client"
|
|
||||||
import { queryClient } from "../../../lib/medusa"
|
import { queryClient } from "../../../lib/medusa"
|
||||||
|
import { sdk } from "../../../lib/client"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const regionQuery = (id: string) => ({
|
const regionQuery = (id: string) => ({
|
||||||
queryKey: adminRegionKeys.detail(id),
|
queryKey: adminRegionKeys.detail(id),
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
client.regions.retrieve(id, { fields: "*payment_providers" }),
|
sdk.admin.region.retrieve(id, { fields: "*payment_providers" }),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const regionLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const regionLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
@@ -16,7 +15,8 @@ export const regionLoader = async ({ params }: LoaderFunctionArgs) => {
|
|||||||
const query = regionQuery(id!)
|
const query = regionQuery(id!)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
queryClient.getQueryData<Response<AdminRegionsRes>>(query.queryKey) ??
|
queryClient.getQueryData<{ region: HttpTypes.AdminRegion }>(
|
||||||
(await queryClient.fetchQuery(query))
|
query.queryKey
|
||||||
|
) ?? (await queryClient.fetchQuery(query))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { PaymentProviderDTO, RegionDTO } from "@medusajs/types"
|
import { PaymentProviderDTO, HttpTypes } from "@medusajs/types"
|
||||||
import { Button, Input, Select, Text, toast } from "@medusajs/ui"
|
import { Button, Input, Select, Text, toast } from "@medusajs/ui"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
@@ -15,7 +15,7 @@ import { CurrencyInfo } from "../../../../../lib/currencies"
|
|||||||
import { formatProvider } from "../../../../../lib/format-provider"
|
import { formatProvider } from "../../../../../lib/format-provider"
|
||||||
|
|
||||||
type EditRegionFormProps = {
|
type EditRegionFormProps = {
|
||||||
region: RegionDTO
|
region: HttpTypes.AdminRegion
|
||||||
currencies: CurrencyInfo[]
|
currencies: CurrencyInfo[]
|
||||||
paymentProviders: PaymentProviderDTO[]
|
paymentProviders: PaymentProviderDTO[]
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,4 @@
|
|||||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||||
import { RegionDTO } from "@medusajs/types"
|
|
||||||
import { Button, Container, Heading, usePrompt, toast } from "@medusajs/ui"
|
import { Button, Container, Heading, usePrompt, toast } from "@medusajs/ui"
|
||||||
import { createColumnHelper } from "@tanstack/react-table"
|
import { createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
@@ -14,6 +13,7 @@ import { useRegionTableColumns } from "../../../../../hooks/table/columns/use-re
|
|||||||
import { useRegionTableFilters } from "../../../../../hooks/table/filters/use-region-table-filters"
|
import { useRegionTableFilters } from "../../../../../hooks/table/filters/use-region-table-filters"
|
||||||
import { useRegionTableQuery } from "../../../../../hooks/table/query/use-region-table-query"
|
import { useRegionTableQuery } from "../../../../../hooks/table/query/use-region-table-query"
|
||||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const PAGE_SIZE = 20
|
const PAGE_SIZE = 20
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export const RegionListTable = () => {
|
|||||||
const columns = useColumns()
|
const columns = useColumns()
|
||||||
|
|
||||||
const { table } = useDataTable({
|
const { table } = useDataTable({
|
||||||
data: (regions ?? []) as RegionDTO[],
|
data: (regions ?? []) as HttpTypes.AdminRegion[],
|
||||||
columns,
|
columns,
|
||||||
count,
|
count,
|
||||||
enablePagination: true,
|
enablePagination: true,
|
||||||
@@ -81,7 +81,7 @@ export const RegionListTable = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const RegionActions = ({ region }: { region: RegionDTO }) => {
|
const RegionActions = ({ region }: { region: HttpTypes.AdminRegion }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const prompt = usePrompt()
|
const prompt = usePrompt()
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ const RegionActions = ({ region }: { region: RegionDTO }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<RegionDTO>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminRegion>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const base = useRegionTableColumns()
|
const base = useRegionTableColumns()
|
||||||
|
|||||||
+5
-8
@@ -17,7 +17,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
toast,
|
toast,
|
||||||
} from "@medusajs/ui"
|
} from "@medusajs/ui"
|
||||||
import { RegionCountryDTO, RegionDTO, ServiceZoneDTO } from "@medusajs/types"
|
import { ServiceZoneDTO, HttpTypes } from "@medusajs/types"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { XMarkMini } from "@medusajs/icons"
|
import { XMarkMini } from "@medusajs/icons"
|
||||||
|
|
||||||
@@ -26,10 +26,7 @@ import {
|
|||||||
useRouteModal,
|
useRouteModal,
|
||||||
} from "../../../../../components/route-modal"
|
} from "../../../../../components/route-modal"
|
||||||
import { SplitView } from "../../../../../components/layout/split-view"
|
import { SplitView } from "../../../../../components/layout/split-view"
|
||||||
import {
|
import { useUpdateServiceZone } from "../../../../../hooks/api/stock-locations"
|
||||||
useCreateServiceZone,
|
|
||||||
useUpdateServiceZone,
|
|
||||||
} from "../../../../../hooks/api/stock-locations"
|
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { useCountryTableQuery } from "../../../../regions/common/hooks/use-country-table-query"
|
import { useCountryTableQuery } from "../../../../regions/common/hooks/use-country-table-query"
|
||||||
import { useCountries } from "../../../../regions/common/hooks/use-countries"
|
import { useCountries } from "../../../../regions/common/hooks/use-countries"
|
||||||
@@ -130,7 +127,7 @@ export function EditServiceZoneAreasForm({
|
|||||||
iso_3: c.iso_3,
|
iso_3: c.iso_3,
|
||||||
num_code: c.num_code,
|
num_code: c.num_code,
|
||||||
region_id: null,
|
region_id: null,
|
||||||
region: {} as RegionDTO,
|
region: {} as HttpTypes.AdminRegion,
|
||||||
})),
|
})),
|
||||||
...searchParams,
|
...searchParams,
|
||||||
})
|
})
|
||||||
@@ -299,7 +296,7 @@ export function EditServiceZoneAreasForm({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<RegionCountryDTO>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminRegionCountry>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const base = useCountryTableColumns()
|
const base = useCountryTableColumns()
|
||||||
@@ -340,5 +337,5 @@ const useColumns = () => {
|
|||||||
...base,
|
...base,
|
||||||
],
|
],
|
||||||
[base]
|
[base]
|
||||||
) as ColumnDef<RegionCountryDTO>[]
|
) as ColumnDef<HttpTypes.AdminRegionCountry>[]
|
||||||
}
|
}
|
||||||
+4
-4
@@ -18,7 +18,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
toast,
|
toast,
|
||||||
} from "@medusajs/ui"
|
} from "@medusajs/ui"
|
||||||
import { FulfillmentSetDTO, RegionCountryDTO, RegionDTO } from "@medusajs/types"
|
import { FulfillmentSetDTO, HttpTypes } from "@medusajs/types"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { XMarkMini } from "@medusajs/icons"
|
import { XMarkMini } from "@medusajs/icons"
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ export function CreateServiceZoneForm({
|
|||||||
iso_3: c.iso_3,
|
iso_3: c.iso_3,
|
||||||
num_code: c.num_code,
|
num_code: c.num_code,
|
||||||
region_id: null,
|
region_id: null,
|
||||||
region: {} as RegionDTO,
|
region: {} as HttpTypes.AdminRegion,
|
||||||
})),
|
})),
|
||||||
...searchParams,
|
...searchParams,
|
||||||
})
|
})
|
||||||
@@ -322,7 +322,7 @@ export function CreateServiceZoneForm({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<RegionCountryDTO>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminRegionCountry>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const base = useCountryTableColumns()
|
const base = useCountryTableColumns()
|
||||||
@@ -363,5 +363,5 @@ const useColumns = () => {
|
|||||||
...base,
|
...base,
|
||||||
],
|
],
|
||||||
[base]
|
[base]
|
||||||
) as ColumnDef<RegionCountryDTO>[]
|
) as ColumnDef<HttpTypes.AdminRegionCountry>[]
|
||||||
}
|
}
|
||||||
+2
-3
@@ -1,5 +1,4 @@
|
|||||||
import { PropsWithChildren } from "react"
|
import { CurrencyDTO, HttpTypes, ProductVariantDTO } from "@medusajs/types"
|
||||||
import { CurrencyDTO, ProductVariantDTO, RegionDTO } from "@medusajs/types"
|
|
||||||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { UseFormReturn } from "react-hook-form"
|
import { UseFormReturn } from "react-hook-form"
|
||||||
@@ -104,7 +103,7 @@ const useColumns = ({
|
|||||||
regions = [],
|
regions = [],
|
||||||
}: {
|
}: {
|
||||||
currencies?: CurrencyDTO[]
|
currencies?: CurrencyDTO[]
|
||||||
regions?: RegionDTO[]
|
regions?: HttpTypes.AdminRegion[]
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,6 @@ import {
|
|||||||
CurrencyDTO,
|
CurrencyDTO,
|
||||||
PriceDTO,
|
PriceDTO,
|
||||||
ProductVariantDTO,
|
ProductVariantDTO,
|
||||||
RegionDTO,
|
|
||||||
ShippingOptionDTO,
|
ShippingOptionDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
@@ -30,6 +29,7 @@ import { CurrencyCell } from "../../../../../components/grid/grid-cells/common/c
|
|||||||
import { DataGridMeta } from "../../../../../components/grid/types"
|
import { DataGridMeta } from "../../../../../components/grid/types"
|
||||||
import { DataGrid } from "../../../../../components/grid/data-grid"
|
import { DataGrid } from "../../../../../components/grid/data-grid"
|
||||||
import { useUpdateShippingOptions } from "../../../../../hooks/api/shipping-options.ts"
|
import { useUpdateShippingOptions } from "../../../../../hooks/api/shipping-options.ts"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const getInitialCurrencyPrices = (prices: PriceDTO[]) => {
|
const getInitialCurrencyPrices = (prices: PriceDTO[]) => {
|
||||||
const ret: Record<string, number> = {}
|
const ret: Record<string, number> = {}
|
||||||
@@ -271,7 +271,7 @@ const useColumns = ({
|
|||||||
regions = [],
|
regions = [],
|
||||||
}: {
|
}: {
|
||||||
currencies?: CurrencyDTO[]
|
currencies?: CurrencyDTO[]
|
||||||
regions?: RegionDTO[]
|
regions?: HttpTypes.AdminRegion[]
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,83 @@
|
|||||||
|
import {
|
||||||
|
DeleteResponse,
|
||||||
|
FindParams,
|
||||||
|
HttpTypes,
|
||||||
|
PaginatedResponse,
|
||||||
|
SelectParams,
|
||||||
|
} from "@medusajs/types"
|
||||||
import { Client } from "../client"
|
import { Client } from "../client"
|
||||||
|
import { ClientHeaders } from "../types"
|
||||||
|
|
||||||
export class Admin {
|
export class Admin {
|
||||||
private client: Client
|
private client: Client
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
this.client = client
|
this.client = client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public region = {
|
||||||
|
create: async (
|
||||||
|
body: HttpTypes.AdminCreateRegion,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{ region: HttpTypes.AdminRegion }>(
|
||||||
|
`/admin/regions`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
update: async (
|
||||||
|
id: string,
|
||||||
|
body: HttpTypes.AdminUpdateRegion,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{ region: HttpTypes.AdminRegion }>(
|
||||||
|
`/admin/regions/${id}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
list: async (
|
||||||
|
queryParams?: FindParams & HttpTypes.AdminRegionFilters,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<
|
||||||
|
PaginatedResponse<{ regions: HttpTypes.AdminRegion[] }>
|
||||||
|
>(`/admin/regions`, {
|
||||||
|
query: queryParams,
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
retrieve: async (
|
||||||
|
id: string,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{ region: HttpTypes.AdminRegion }>(
|
||||||
|
`/admin/regions/${id}`,
|
||||||
|
{
|
||||||
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
delete: async (id: string, headers?: ClientHeaders) => {
|
||||||
|
return this.client.fetch<DeleteResponse<"region">>(
|
||||||
|
`/admin/regions/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,13 @@ export class Auth {
|
|||||||
this.config = config
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
login = async (payload: { email: string; password: string }) => {
|
login = async (
|
||||||
// TODO: It is a bit strange to eg. require to pass `scope` in `login`, it might be better for us to have auth methods in both `admin` and `store` classes instead?
|
scope: "admin" | "store",
|
||||||
|
method: "emailpass",
|
||||||
|
payload: { email: string; password: string }
|
||||||
|
) => {
|
||||||
const { token } = await this.client.fetch<{ token: string }>(
|
const { token } = await this.client.fetch<{ token: string }>(
|
||||||
"/auth/admin/emailpass",
|
`/auth/${scope}/${method}`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: payload,
|
body: payload,
|
||||||
@@ -32,9 +35,11 @@ export class Auth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logout = async () => {
|
logout = async () => {
|
||||||
await this.client.fetch("/auth/session", {
|
if (this.config?.auth?.type === "session") {
|
||||||
method: "DELETE",
|
await this.client.fetch("/auth/session", {
|
||||||
})
|
method: "DELETE",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.client.clearToken()
|
this.client.clearToken()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { StoreRegion } from "@medusajs/types"
|
import {
|
||||||
|
FindParams,
|
||||||
|
HttpTypes,
|
||||||
|
PaginatedResponse,
|
||||||
|
SelectParams,
|
||||||
|
} from "@medusajs/types"
|
||||||
import { Client } from "../client"
|
import { Client } from "../client"
|
||||||
import { ClientHeaders } from "../types"
|
import { ClientHeaders } from "../types"
|
||||||
|
|
||||||
@@ -11,153 +16,188 @@ export class Store {
|
|||||||
|
|
||||||
public region = {
|
public region = {
|
||||||
list: async (
|
list: async (
|
||||||
queryParams?: Record<string, any>,
|
query?: FindParams & HttpTypes.StoreRegionFilters,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/regions`, {
|
return this.client.fetch<
|
||||||
query: queryParams,
|
PaginatedResponse<{ regions: HttpTypes.StoreRegion[] }>
|
||||||
|
>(`/store/regions`, {
|
||||||
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
queryParams?: Record<string, any>,
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<StoreRegion>(`/store/regions/${id}`, {
|
return this.client.fetch<{ region: HttpTypes.StoreRegion }>(
|
||||||
query: queryParams,
|
`/store/regions/${id}`,
|
||||||
headers,
|
{
|
||||||
})
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
public collection = {
|
public collection = {
|
||||||
list: async (
|
list: async (
|
||||||
queryParams?: Record<string, any>,
|
query?: FindParams & HttpTypes.StoreCollectionFilters,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/collections`, {
|
return this.client.fetch<
|
||||||
query: queryParams,
|
PaginatedResponse<{ collections: HttpTypes.StoreCollection }>
|
||||||
|
>(`/store/collections`, {
|
||||||
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
queryParams?: Record<string, any>,
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/collections/${id}`, {
|
return this.client.fetch<{ collection: HttpTypes.StoreCollection }>(
|
||||||
query: queryParams,
|
`/store/collections/${id}`,
|
||||||
headers,
|
{
|
||||||
})
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
public category = {
|
public category = {
|
||||||
list: async (
|
list: async (
|
||||||
queryParams?: Record<string, any>,
|
query?: FindParams & HttpTypes.StoreProductCategoryFilters,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/product-categories`, {
|
return this.client.fetch<
|
||||||
query: queryParams,
|
PaginatedResponse<{ categories: HttpTypes.StoreProductCategory }>
|
||||||
|
>(`/store/product-categories`, {
|
||||||
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
queryParams?: Record<string, any>,
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/product-categories/${id}`, {
|
return this.client.fetch<{ category: HttpTypes.StoreProductCategory }>(
|
||||||
query: queryParams,
|
`/store/product-categories/${id}`,
|
||||||
headers,
|
{
|
||||||
})
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
public product = {
|
public product = {
|
||||||
list: async (
|
list: async (
|
||||||
queryParams?: Record<string, any>,
|
query?: FindParams & HttpTypes.StoreProductFilters,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/products`, {
|
return this.client.fetch<
|
||||||
query: queryParams,
|
PaginatedResponse<{ products: HttpTypes.StoreProduct }>
|
||||||
|
>(`/store/products`, {
|
||||||
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
queryParams?: Record<string, any>,
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/products/${id}`, {
|
return this.client.fetch<{ product: HttpTypes.StoreProduct }>(
|
||||||
query: queryParams,
|
`/store/products/${id}`,
|
||||||
headers,
|
{
|
||||||
})
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
public order = {
|
public order = {
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
queryParams?: Record<string, any>,
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/orders/${id}`, {
|
return this.client.fetch<any>(`/store/orders/${id}`, {
|
||||||
query: queryParams,
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
public cart = {
|
public cart = {
|
||||||
create: async (body: any, headers?: ClientHeaders) => {
|
create: async (
|
||||||
|
body: any,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
return this.client.fetch<any>(`/store/carts`, {
|
return this.client.fetch<any>(`/store/carts`, {
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body,
|
body,
|
||||||
|
query,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
update: async (id: string, body: any, headers?: ClientHeaders) => {
|
update: async (
|
||||||
|
id: string,
|
||||||
|
body: any,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
return this.client.fetch<any>(`/store/carts/${id}`, {
|
return this.client.fetch<any>(`/store/carts/${id}`, {
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body,
|
body,
|
||||||
|
query,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
queryParams?: Record<string, any>,
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/carts/${id}`, {
|
return this.client.fetch<any>(`/store/carts/${id}`, {
|
||||||
query: queryParams,
|
|
||||||
headers,
|
headers,
|
||||||
|
query,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
createLineItem: async (
|
createLineItem: async (
|
||||||
cartId: string,
|
cartId: string,
|
||||||
body: any,
|
body: any,
|
||||||
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/carts/${cartId}/line-items`, {
|
return this.client.fetch<any>(`/store/carts/${cartId}/line-items`, {
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body,
|
body,
|
||||||
|
query,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
updateLineItem: async (
|
updateLineItem: async (
|
||||||
cartId: string,
|
cartId: string,
|
||||||
lineItemId: string,
|
lineItemId: string,
|
||||||
body: any,
|
body: any,
|
||||||
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(
|
return this.client.fetch<any>(
|
||||||
`/store/carts/${cartId}/line-items/${lineItemId}`,
|
`/store/carts/${cartId}/line-items/${lineItemId}`,
|
||||||
{
|
{
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body,
|
body,
|
||||||
|
query,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -169,37 +209,44 @@ export class Store {
|
|||||||
return this.client.fetch<any>(
|
return this.client.fetch<any>(
|
||||||
`/store/carts/${cartId}/line-items/${lineItemId}`,
|
`/store/carts/${cartId}/line-items/${lineItemId}`,
|
||||||
{
|
{
|
||||||
headers,
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
addShippingMethod: async (
|
addShippingMethod: async (
|
||||||
cartId: string,
|
cartId: string,
|
||||||
body: any,
|
body: any,
|
||||||
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/carts/${cartId}/shipping-methods`, {
|
return this.client.fetch<any>(`/store/carts/${cartId}/shipping-methods`, {
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body,
|
body,
|
||||||
|
query,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
complete: async (cartId: string, headers?: ClientHeaders) => {
|
complete: async (
|
||||||
|
cartId: string,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
return this.client.fetch<any>(`/store/carts/${cartId}/complete`, {
|
return this.client.fetch<any>(`/store/carts/${cartId}/complete`, {
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
public fulfillment = {
|
public fulfillment = {
|
||||||
listCartOptions: async (
|
listCartOptions: async (
|
||||||
queryParams?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/shipping-options`, {
|
return this.client.fetch<any>(`/store/shipping-options`, {
|
||||||
query: queryParams,
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -207,11 +254,11 @@ export class Store {
|
|||||||
|
|
||||||
public payment = {
|
public payment = {
|
||||||
listPaymentProviders: async (
|
listPaymentProviders: async (
|
||||||
queryParams?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
return this.client.fetch<any>(`/store/payment-providers`, {
|
return this.client.fetch<any>(`/store/payment-providers`, {
|
||||||
query: queryParams,
|
query,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -219,6 +266,7 @@ export class Store {
|
|||||||
initiatePaymentSession: async (
|
initiatePaymentSession: async (
|
||||||
cart: any,
|
cart: any,
|
||||||
body: Record<string, any>,
|
body: Record<string, any>,
|
||||||
|
query?: SelectParams,
|
||||||
headers?: ClientHeaders
|
headers?: ClientHeaders
|
||||||
) => {
|
) => {
|
||||||
let paymentCollectionId = (cart as any).payment_collection?.id
|
let paymentCollectionId = (cart as any).payment_collection?.id
|
||||||
@@ -231,8 +279,8 @@ export class Store {
|
|||||||
}
|
}
|
||||||
paymentCollectionId = (
|
paymentCollectionId = (
|
||||||
await this.client.fetch<any>(`/store/payment-collections`, {
|
await this.client.fetch<any>(`/store/payment-collections`, {
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body: collectionBody,
|
body: collectionBody,
|
||||||
})
|
})
|
||||||
).payment_collection.id
|
).payment_collection.id
|
||||||
@@ -241,9 +289,10 @@ export class Store {
|
|||||||
return this.client.fetch<any>(
|
return this.client.fetch<any>(
|
||||||
`/store/payment-collections/${paymentCollectionId}/payment-sessions`,
|
`/store/payment-collections/${paymentCollectionId}/payment-sessions`,
|
||||||
{
|
{
|
||||||
headers,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers,
|
||||||
body,
|
body,
|
||||||
|
query,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,5 +14,6 @@ export * from "./product-category"
|
|||||||
export * from "./reservation"
|
export * from "./reservation"
|
||||||
export * from "./region"
|
export * from "./region"
|
||||||
export * from "./product"
|
export * from "./product"
|
||||||
|
export * from "./payment"
|
||||||
export * from "./collection"
|
export * from "./collection"
|
||||||
export * from "./common"
|
export * from "./common"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { BasePaymentProvider } from "./common"
|
||||||
|
|
||||||
|
export interface AdminPaymentProvider extends BasePaymentProvider {
|
||||||
|
is_enabled: boolean
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export interface BasePaymentProvider {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./admin"
|
||||||
|
export * from "./store"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BasePaymentProvider } from "./common"
|
||||||
|
|
||||||
|
export interface StorePaymentProvider extends BasePaymentProvider {}
|
||||||
@@ -9,3 +9,21 @@ export interface AdminRegion extends BaseRegion {}
|
|||||||
export interface AdminRegionCountry extends BaseRegionCountry {}
|
export interface AdminRegionCountry extends BaseRegionCountry {}
|
||||||
export interface AdminRegionFilters extends BaseRegionFilters {}
|
export interface AdminRegionFilters extends BaseRegionFilters {}
|
||||||
export interface AdminRegionCountryFilters extends BaseRegionCountryFilters {}
|
export interface AdminRegionCountryFilters extends BaseRegionCountryFilters {}
|
||||||
|
|
||||||
|
export interface AdminCreateRegion {
|
||||||
|
name: string
|
||||||
|
currency_code: string
|
||||||
|
countries?: string[]
|
||||||
|
automatic_taxes?: boolean
|
||||||
|
payment_providers?: string[]
|
||||||
|
metadata?: Record<string, any>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminUpdateRegion {
|
||||||
|
name?: string
|
||||||
|
currency_code?: string
|
||||||
|
countries?: string[]
|
||||||
|
automatic_taxes?: boolean
|
||||||
|
payment_providers?: string[]
|
||||||
|
metadata?: Record<string, any>
|
||||||
|
}
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||||
|
import { AdminPaymentProvider } from "../payment"
|
||||||
|
|
||||||
export interface BaseRegion {
|
export interface BaseRegion {
|
||||||
id?: string
|
id: string
|
||||||
name?: string
|
name: string
|
||||||
currency_code?: string
|
currency_code: string
|
||||||
automatic_taxes?: boolean
|
automatic_taxes?: boolean
|
||||||
countries?: BaseRegionCountry[]
|
countries?: BaseRegionCountry[]
|
||||||
|
payment_providers?: AdminPaymentProvider[]
|
||||||
metadata?: Record<string, any> | null
|
metadata?: Record<string, any> | null
|
||||||
created_at?: string
|
created_at?: string
|
||||||
updated_at?: string
|
updated_at?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseRegionCountry {
|
export interface BaseRegionCountry {
|
||||||
id?: string
|
id: string
|
||||||
iso_2?: string
|
iso_2?: string
|
||||||
iso_3?: string
|
iso_3?: string
|
||||||
num_code?: number
|
num_code?: number
|
||||||
|
|||||||
Reference in new issue
Block a user