Clean up product typings (#7663)
There are a lot of issues in the admin after applying the correct typings, but fixing those should be done gradually, it's better to keep it out of this PR
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { ProductCollectionDTO } from "@medusajs/types"
|
||||
import { PlaceholderCell } from "../../common/placeholder-cell"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type CollectionCellProps = {
|
||||
collection?: ProductCollectionDTO | null
|
||||
collection?: HttpTypes.AdminCollection | null
|
||||
}
|
||||
|
||||
export const CollectionCell = ({ collection }: CollectionCellProps) => {
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { ProductDTO } from "@medusajs/types"
|
||||
import { Thumbnail } from "../../../../common/thumbnail"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductCellProps = {
|
||||
product: ProductDTO
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductCell = ({ product }: ProductCellProps) => {
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { ProductStatus } from "@medusajs/types"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { StatusCell } from "../../common/status-cell"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductStatusCellProps = {
|
||||
status: ProductStatus
|
||||
status: HttpTypes.AdminProductStatus
|
||||
}
|
||||
|
||||
export const ProductStatusCell = ({ status }: ProductStatusCellProps) => {
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { ProductVariantDTO } from "@medusajs/types"
|
||||
import { PlaceholderCell } from "../../common/placeholder-cell"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type VariantCellProps = {
|
||||
variants?: ProductVariantDTO[] | null
|
||||
variants?: HttpTypes.AdminProductVariant[] | null
|
||||
}
|
||||
|
||||
export const VariantCell = ({ variants }: VariantCellProps) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query"
|
||||
import { client } from "../../lib/client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { ProductTypeListRes, ProductTypeRes } from "../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const PRODUCT_TYPES_QUERY_KEY = "product_types" as const
|
||||
const productTypesQueryKeys = queryKeysFactory(PRODUCT_TYPES_QUERY_KEY)
|
||||
@@ -10,7 +10,12 @@ export const useProductType = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<ProductTypeRes, Error, ProductTypeRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
{ product_type: HttpTypes.AdminProductType },
|
||||
Error,
|
||||
{ product_type: HttpTypes.AdminProductType },
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
@@ -26,7 +31,12 @@ export const useProductType = (
|
||||
export const useProductTypes = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<ProductTypeListRes, Error, ProductTypeListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
{ product_types: HttpTypes.AdminProductType[] },
|
||||
Error,
|
||||
{ product_types: HttpTypes.AdminProductType[] },
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
|
||||
@@ -5,14 +5,9 @@ import {
|
||||
useQuery,
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
import { client, sdk } from "../../lib/client"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import {
|
||||
ProductDeleteRes,
|
||||
ProductListRes,
|
||||
ProductRes,
|
||||
} from "../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const PRODUCTS_QUERY_KEY = "products" as const
|
||||
@@ -29,8 +24,8 @@ export const useCreateProductOption = (
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) =>
|
||||
client.products.createOption(productId, payload),
|
||||
mutationFn: (payload: HttpTypes.AdminCreateProductOption) =>
|
||||
sdk.admin.product.createOption(productId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: optionsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -48,8 +43,8 @@ export const useUpdateProductOption = (
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) =>
|
||||
client.products.updateOption(productId, optionId, payload),
|
||||
mutationFn: (payload: HttpTypes.AdminUpdateProductOption) =>
|
||||
sdk.admin.product.updateOption(productId, optionId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: optionsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -71,7 +66,7 @@ export const useDeleteProductOption = (
|
||||
options?: UseMutationOptions<any, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.products.deleteOption(productId, optionId),
|
||||
mutationFn: () => sdk.admin.product.deleteOption(productId, optionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: optionsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -97,7 +92,8 @@ export const useProductVariant = (
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.products.retrieveVariant(productId, variantId, query),
|
||||
queryFn: () =>
|
||||
sdk.admin.product.retrieveVariant(productId, variantId, query),
|
||||
queryKey: variantsQueryKeys.detail(variantId),
|
||||
...options,
|
||||
})
|
||||
@@ -114,7 +110,7 @@ export const useProductVariants = (
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.products.listVariants(productId, query),
|
||||
queryFn: () => sdk.admin.product.listVariants(productId, query),
|
||||
queryKey: variantsQueryKeys.list({ productId, ...query }),
|
||||
...options,
|
||||
})
|
||||
@@ -127,8 +123,8 @@ export const useCreateProductVariant = (
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) =>
|
||||
client.products.createVariant(productId, payload),
|
||||
mutationFn: (payload: HttpTypes.AdminCreateProductVariant) =>
|
||||
sdk.admin.product.createVariant(productId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -146,8 +142,8 @@ export const useUpdateProductVariant = (
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) =>
|
||||
client.products.updateVariant(productId, variantId, payload),
|
||||
mutationFn: (payload: HttpTypes.AdminUpdateProductVariant) =>
|
||||
sdk.admin.product.updateVariant(productId, variantId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -168,8 +164,9 @@ export const useUpdateProductVariantsBatch = (
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) =>
|
||||
client.products.updateVariantsBatch(productId, payload),
|
||||
mutationFn: (
|
||||
payload: HttpTypes.AdminBatchProductVariantRequest["update"]
|
||||
) => sdk.admin.product.batchVariants(productId, { update: payload }),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -188,7 +185,7 @@ export const useDeleteVariant = (
|
||||
options?: UseMutationOptions<any, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.products.deleteVariant(productId, variantId),
|
||||
mutationFn: () => sdk.admin.product.deleteVariant(productId, variantId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -213,7 +210,7 @@ export const useProduct = (
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.products.retrieve(id, query),
|
||||
queryFn: () => sdk.admin.product.retrieve(id, query),
|
||||
queryKey: productsQueryKeys.detail(id),
|
||||
...options,
|
||||
})
|
||||
@@ -224,12 +221,17 @@ export const useProduct = (
|
||||
export const useProducts = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<ProductListRes, Error, ProductListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminProductListResponse,
|
||||
Error,
|
||||
HttpTypes.AdminProductListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.products.list(query),
|
||||
queryFn: () => sdk.admin.product.list(query),
|
||||
queryKey: productsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
@@ -245,7 +247,8 @@ export const useCreateProduct = (
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) => sdk.admin.product.create(payload),
|
||||
mutationFn: (payload: HttpTypes.AdminCreateProduct) =>
|
||||
sdk.admin.product.create(payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
@@ -256,10 +259,11 @@ export const useCreateProduct = (
|
||||
|
||||
export const useUpdateProduct = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<ProductRes, Error, any>
|
||||
options?: UseMutationOptions<HttpTypes.AdminProductResponse, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) => client.products.update(id, payload),
|
||||
mutationFn: (payload: HttpTypes.AdminUpdateProduct) =>
|
||||
sdk.admin.product.update(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) })
|
||||
@@ -272,10 +276,14 @@ export const useUpdateProduct = (
|
||||
|
||||
export const useDeleteProduct = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<ProductDeleteRes, Error, void>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminProductDeleteResponse,
|
||||
Error,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.products.delete(id),
|
||||
mutationFn: () => sdk.admin.product.delete(id),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) })
|
||||
|
||||
@@ -21,9 +21,9 @@ import {
|
||||
VariantCell,
|
||||
VariantHeader,
|
||||
} from "../../../components/table/table-cells/product/variant-cell"
|
||||
import { ExtendedProductDTO } from "../../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
export const useProductTableColumns = () => {
|
||||
return useMemo(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { AdminGetProductsParams } from "@medusajs/medusa"
|
||||
import { ProductStatus } from "@medusajs/types"
|
||||
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { useQueryParams } from "../../use-query-params"
|
||||
|
||||
type UseProductTableQueryProps = {
|
||||
@@ -46,7 +44,7 @@ export const useProductTableQuery = ({
|
||||
q,
|
||||
} = queryObject
|
||||
|
||||
const searchParams: AdminGetProductsParams = {
|
||||
const searchParams: HttpTypes.AdminProductParams = {
|
||||
limit: pageSize,
|
||||
offset: offset ? Number(offset) : 0,
|
||||
sales_channel_id: sales_channel_id?.split(","),
|
||||
@@ -56,9 +54,9 @@ export const useProductTableQuery = ({
|
||||
collection_id: collection_id?.split(","),
|
||||
is_giftcard: is_giftcard ? is_giftcard === "true" : undefined,
|
||||
order: order,
|
||||
tags: tags?.split(","),
|
||||
tags: tags ? { value: tags.split(",") } : undefined,
|
||||
type_id: type_id?.split(","),
|
||||
status: status?.split(",") as ProductStatus[],
|
||||
status: status?.split(",") as HttpTypes.AdminProductStatus[],
|
||||
q,
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { invites } from "./invites"
|
||||
import { payments } from "./payments"
|
||||
import { priceLists } from "./price-lists"
|
||||
import { productTypes } from "./product-types"
|
||||
import { products } from "./products"
|
||||
import { promotions } from "./promotions"
|
||||
import { reservations } from "./reservations"
|
||||
import { salesChannels } from "./sales-channels"
|
||||
@@ -42,7 +41,6 @@ export const client = {
|
||||
reservations: reservations,
|
||||
fulfillments: fulfillments,
|
||||
fulfillmentProviders: fulfillmentProviders,
|
||||
products: products,
|
||||
productTypes: productTypes,
|
||||
priceLists: priceLists,
|
||||
stockLocations: stockLocations,
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { ProductTypeListRes, ProductTypeRes } from "../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { getRequest } from "./common"
|
||||
|
||||
async function listProductTypes(query?: Record<string, any>) {
|
||||
return getRequest<ProductTypeListRes>(`/admin/product-types`, query)
|
||||
return getRequest<{ product_types: HttpTypes.AdminProductType[] }>(
|
||||
`/admin/product-types`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function retrieveProductType(id: string, query?: Record<string, any>) {
|
||||
return getRequest<ProductTypeRes>(`/admin/product-types/${id}`, query)
|
||||
return getRequest<{ product_type: HttpTypes.AdminProductType }>(
|
||||
`/admin/product-types/${id}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
export const productTypes = {
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
import { ProductDeleteRes, ProductListRes } from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
async function retrieveProduct(id: string, query?: Record<string, any>) {
|
||||
return getRequest<any>(`/admin/products/${id}`, query)
|
||||
}
|
||||
|
||||
async function createProduct(payload: any) {
|
||||
return postRequest<any>(`/admin/products`, payload)
|
||||
}
|
||||
|
||||
async function listProducts(query?: Record<string, any>) {
|
||||
return getRequest<ProductListRes>(`/admin/products`, query)
|
||||
}
|
||||
|
||||
async function updateProduct(id: string, payload: any) {
|
||||
return postRequest<any>(`/admin/products/${id}`, payload)
|
||||
}
|
||||
|
||||
async function deleteProduct(id: string) {
|
||||
return deleteRequest<ProductDeleteRes>(`/admin/products/${id}`)
|
||||
}
|
||||
|
||||
async function retrieveVariant(
|
||||
productId: string,
|
||||
variantId: string,
|
||||
query?: Record<string, any>
|
||||
) {
|
||||
return getRequest<any>(
|
||||
`/admin/products/${productId}/variants/${variantId}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function listVariants(productId: string, query?: Record<string, any>) {
|
||||
return getRequest<any>(`/admin/products/${productId}/variants`, query)
|
||||
}
|
||||
|
||||
async function createVariant(productId: string, payload: any) {
|
||||
return postRequest<any>(`/admin/products/${productId}/variants`, payload)
|
||||
}
|
||||
|
||||
async function updateVariant(
|
||||
productId: string,
|
||||
variantId: string,
|
||||
payload: any
|
||||
) {
|
||||
return postRequest<any>(
|
||||
`/admin/products/${productId}/variants/${variantId}`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function updateVariantsBatch(
|
||||
productId: string,
|
||||
payload: { add: any[]; update: any[]; remove: any[] }
|
||||
) {
|
||||
return postRequest<any>(
|
||||
`/admin/products/${productId}/variants/batch`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function deleteVariant(productId: string, variantId: string) {
|
||||
return deleteRequest<any>(
|
||||
`/admin/products/${productId}/variants/${variantId}`
|
||||
)
|
||||
}
|
||||
|
||||
async function createOption(productId: string, payload: any) {
|
||||
return postRequest<any>(`/admin/products/${productId}/options`, payload)
|
||||
}
|
||||
|
||||
async function updateOption(productId: string, optionId: string, payload: any) {
|
||||
return postRequest<any>(
|
||||
`/admin/products/${productId}/options/${optionId}`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function deleteOption(productId: string, optionId: string) {
|
||||
return deleteRequest<any>(`/admin/products/${productId}/options/${optionId}`)
|
||||
}
|
||||
|
||||
export const products = {
|
||||
retrieve: retrieveProduct,
|
||||
list: listProducts,
|
||||
create: createProduct,
|
||||
update: updateProduct,
|
||||
delete: deleteProduct,
|
||||
retrieveVariant,
|
||||
listVariants,
|
||||
createVariant,
|
||||
updateVariant,
|
||||
updateVariantsBatch,
|
||||
deleteVariant,
|
||||
createOption,
|
||||
updateOption,
|
||||
deleteOption,
|
||||
}
|
||||
@@ -63,7 +63,7 @@ export const RouteMap: RouteObject[] = [
|
||||
path: ":id",
|
||||
lazy: () => import("../../routes/products/product-detail"),
|
||||
handle: {
|
||||
crumb: (data: { product: HttpTypes.AdminProduct }) =>
|
||||
crumb: (data: HttpTypes.AdminProductResponse) =>
|
||||
data.product.title,
|
||||
},
|
||||
children: [
|
||||
|
||||
+1
-2
@@ -22,7 +22,6 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p
|
||||
import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters.tsx"
|
||||
import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query.tsx"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table.tsx"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses.ts"
|
||||
|
||||
type AddProductsToCollectionFormProps = {
|
||||
collection: HttpTypes.AdminCollection
|
||||
@@ -186,7 +185,7 @@ export const AddProductsToCollectionForm = ({
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
+2
-3
@@ -13,7 +13,6 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p
|
||||
import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters"
|
||||
import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
|
||||
type CollectionProductSectionProps = {
|
||||
collection: HttpTypes.AdminCollection
|
||||
@@ -139,7 +138,7 @@ const ProductActions = ({
|
||||
product,
|
||||
collectionId,
|
||||
}: {
|
||||
product: ExtendedProductDTO
|
||||
product: HttpTypes.AdminProduct
|
||||
collectionId: string
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
@@ -201,7 +200,7 @@ const ProductActions = ({
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const columns = useProductTableColumns()
|
||||
|
||||
+2
-2
@@ -4,16 +4,16 @@ import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import * as zod from "zod"
|
||||
|
||||
import { ProductCollectionDTO } from "@medusajs/types"
|
||||
import { Form } from "../../../../../components/common/form"
|
||||
import {
|
||||
RouteDrawer,
|
||||
useRouteModal,
|
||||
} from "../../../../../components/route-modal"
|
||||
import { useUpdateCollection } from "../../../../../hooks/api/collections"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type EditCollectionFormProps = {
|
||||
collection: ProductCollectionDTO
|
||||
collection: HttpTypes.AdminCollection
|
||||
}
|
||||
|
||||
const EditCollectionSchema = zod.object({
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
import { Container, Heading } from "@medusajs/ui"
|
||||
import { ProductVariantDTO } from "@medusajs/types"
|
||||
|
||||
import { ActionMenu } from "../../../../components/common/action-menu"
|
||||
import { InventoryItemRes } from "../../../../types/api-responses"
|
||||
import { PencilSquare } from "@medusajs/icons"
|
||||
import { SectionRow } from "../../../../components/common/section"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type InventoryItemGeneralSectionProps = {
|
||||
inventoryItem: InventoryItemRes["inventory_item"] & {
|
||||
variant: ProductVariantDTO | ProductVariantDTO[]
|
||||
variant: HttpTypes.AdminProductVariant | HttpTypes.AdminProductVariant[]
|
||||
}
|
||||
}
|
||||
export const InventoryItemGeneralSection = ({
|
||||
@@ -74,7 +74,7 @@ export const InventoryItemGeneralSection = ({
|
||||
)
|
||||
}
|
||||
|
||||
const getQuantityFormat = (quantity: number, locations: number) => {
|
||||
const getQuantityFormat = (quantity: number, locations?: number) => {
|
||||
return `${quantity ?? "-"}
|
||||
${quantity ? `across ${locations} locations` : ""}`
|
||||
${quantity ? `across ${locations ?? "-"} locations` : ""}`
|
||||
}
|
||||
|
||||
+42
-42
@@ -1,4 +1,4 @@
|
||||
import { CurrencyDTO, HttpTypes, ProductVariantDTO } from "@medusajs/types"
|
||||
import { CurrencyDTO, HttpTypes } from "@medusajs/types"
|
||||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import { UseFormReturn } from "react-hook-form"
|
||||
@@ -9,7 +9,6 @@ import { CurrencyCell } from "../../../../../components/grid/grid-cells/common/c
|
||||
import { DataGrid } from "../../../../../components/grid/data-grid"
|
||||
import { DataGridMeta } from "../../../../../components/grid/types"
|
||||
import { useCurrencies } from "../../../../../hooks/api/currencies"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
import { useRegions } from "../../../../../hooks/api/regions"
|
||||
import { useStore } from "../../../../../hooks/api/store"
|
||||
|
||||
@@ -95,7 +94,7 @@ export const CreateShippingOptionsPricesForm = ({
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<
|
||||
ExtendedProductDTO | ProductVariantDTO
|
||||
HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
>()
|
||||
|
||||
const useColumns = ({
|
||||
@@ -107,45 +106,46 @@ const useColumns = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const colDefs: ColumnDef<ExtendedProductDTO | ProductVariantDTO>[] =
|
||||
useMemo(() => {
|
||||
return [
|
||||
...currencies.map((currency) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: currency.code.toUpperCase(),
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currency}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`currency_prices.${currency.code}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
...regions.map((region) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: region.name,
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currencies.find(
|
||||
(c) => c.code === region.currency_code
|
||||
)}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`region_prices.${region.id}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
]
|
||||
}, [t, currencies, regions])
|
||||
const colDefs: ColumnDef<
|
||||
HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
>[] = useMemo(() => {
|
||||
return [
|
||||
...currencies.map((currency) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: currency.code.toUpperCase(),
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currency}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`currency_prices.${currency.code}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
...regions.map((region) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: region.name,
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currencies.find(
|
||||
(c) => c.code === region.currency_code
|
||||
)}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`region_prices.${region.id}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
]
|
||||
}, [t, currencies, regions])
|
||||
|
||||
return colDefs
|
||||
}
|
||||
|
||||
+42
-43
@@ -6,13 +6,12 @@ import * as zod from "zod"
|
||||
import {
|
||||
CurrencyDTO,
|
||||
PriceDTO,
|
||||
ProductVariantDTO,
|
||||
ShippingOptionDTO,
|
||||
HttpTypes,
|
||||
} from "@medusajs/types"
|
||||
import { Button, toast } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
||||
import { DataGrid } from "../../../../../components/grid/data-grid/index"
|
||||
import { CurrencyCell } from "../../../../../components/grid/grid-cells/common/currency-cell/index"
|
||||
@@ -25,7 +24,6 @@ import { useCurrencies } from "../../../../../hooks/api/currencies"
|
||||
import { useRegions } from "../../../../../hooks/api/regions"
|
||||
import { useUpdateShippingOptions } from "../../../../../hooks/api/shipping-options"
|
||||
import { useStore } from "../../../../../hooks/api/store"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
import { castNumber } from "../../../../../lib/cast-number.ts"
|
||||
|
||||
const getInitialCurrencyPrices = (prices: PriceDTO[]) => {
|
||||
@@ -254,7 +252,7 @@ export function EditShippingOptionsPricingForm({
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<
|
||||
ExtendedProductDTO | ProductVariantDTO
|
||||
HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
>()
|
||||
|
||||
const useColumns = ({
|
||||
@@ -266,45 +264,46 @@ const useColumns = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const colDefs: ColumnDef<ExtendedProductDTO | ProductVariantDTO>[] =
|
||||
useMemo(() => {
|
||||
return [
|
||||
...currencies.map((currency) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: currency.code.toUpperCase(),
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currency}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`currency_prices.${currency.code}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
...regions.map((region) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: region.name,
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currencies.find(
|
||||
(c) => c.code === region.currency_code
|
||||
)}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`region_prices.${region.id}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
]
|
||||
}, [t, currencies, regions])
|
||||
const colDefs: ColumnDef<
|
||||
HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
>[] = useMemo(() => {
|
||||
return [
|
||||
...currencies.map((currency) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: currency.code.toUpperCase(),
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currency}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`currency_prices.${currency.code}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
...regions.map((region) => {
|
||||
return columnHelper.display({
|
||||
header: t("fields.priceTemplate", {
|
||||
regionOrCountry: region.name,
|
||||
}),
|
||||
cell: ({ row, table }) => {
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currencies.find(
|
||||
(c) => c.code === region.currency_code
|
||||
)}
|
||||
meta={table.options.meta as DataGridMeta<any>}
|
||||
field={`region_prices.${region.id}`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
]
|
||||
}, [t, currencies, regions])
|
||||
|
||||
return colDefs
|
||||
}
|
||||
|
||||
+2
-7
@@ -1,10 +1,5 @@
|
||||
import { Buildings, XCircle } from "@medusajs/icons"
|
||||
import {
|
||||
AdminOrder,
|
||||
FulfillmentDTO,
|
||||
OrderLineItemDTO,
|
||||
ProductVariantDTO,
|
||||
} from "@medusajs/types"
|
||||
import { AdminOrder, FulfillmentDTO, OrderLineItemDTO } from "@medusajs/types"
|
||||
import {
|
||||
Container,
|
||||
Copy,
|
||||
@@ -49,7 +44,7 @@ const UnfulfilledItem = ({
|
||||
item,
|
||||
currencyCode,
|
||||
}: {
|
||||
item: OrderLineItemDTO & { variant: ProductVariantDTO }
|
||||
item: OrderLineItemDTO & { variant: HttpTypes.AdminProductVariant }
|
||||
currencyCode: string
|
||||
}) => {
|
||||
return (
|
||||
|
||||
+46
-46
@@ -1,4 +1,4 @@
|
||||
import { CurrencyDTO, ProductVariantDTO } from "@medusajs/types"
|
||||
import { CurrencyDTO, HttpTypes } from "@medusajs/types"
|
||||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -7,11 +7,10 @@ import { CurrencyCell } from "../../../../components/grid/grid-cells/common/curr
|
||||
import { ReadonlyCell } from "../../../../components/grid/grid-cells/common/readonly-cell"
|
||||
import { VoidCell } from "../../../../components/grid/grid-cells/common/void-cell"
|
||||
import { DataGridMeta } from "../../../../components/grid/types"
|
||||
import { ExtendedProductDTO } from "../../../../types/api-responses"
|
||||
import { isProductRow } from "../utils"
|
||||
|
||||
const columnHelper = createColumnHelper<
|
||||
ExtendedProductDTO | ProductVariantDTO
|
||||
HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
>()
|
||||
|
||||
export const usePriceListGridColumns = ({
|
||||
@@ -21,57 +20,58 @@ export const usePriceListGridColumns = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const colDefs: ColumnDef<ExtendedProductDTO | ProductVariantDTO>[] =
|
||||
useMemo(() => {
|
||||
return [
|
||||
columnHelper.display({
|
||||
id: t("fields.title"),
|
||||
header: t("fields.title"),
|
||||
cell: ({ row }) => {
|
||||
const colDefs: ColumnDef<
|
||||
HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
>[] = useMemo(() => {
|
||||
return [
|
||||
columnHelper.display({
|
||||
id: t("fields.title"),
|
||||
header: t("fields.title"),
|
||||
cell: ({ row }) => {
|
||||
const entity = row.original
|
||||
|
||||
if (isProductRow(entity)) {
|
||||
return (
|
||||
<VoidCell>
|
||||
<div className="flex h-full w-full items-center gap-x-2 overflow-hidden">
|
||||
<Thumbnail src={entity.thumbnail} />
|
||||
<span className="truncate">{entity.title}</span>
|
||||
</div>
|
||||
</VoidCell>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ReadonlyCell>
|
||||
<div className="flex h-full w-full items-center gap-x-2 overflow-hidden">
|
||||
<span className="truncate">{entity.title}</span>
|
||||
</div>
|
||||
</ReadonlyCell>
|
||||
)
|
||||
},
|
||||
}),
|
||||
...currencies.map((currency) => {
|
||||
return columnHelper.display({
|
||||
header: `Price ${currency.code.toUpperCase()}`,
|
||||
cell: ({ row, table }) => {
|
||||
const entity = row.original
|
||||
|
||||
if (isProductRow(entity)) {
|
||||
return (
|
||||
<VoidCell>
|
||||
<div className="flex h-full w-full items-center gap-x-2 overflow-hidden">
|
||||
<Thumbnail src={entity.thumbnail} />
|
||||
<span className="truncate">{entity.title}</span>
|
||||
</div>
|
||||
</VoidCell>
|
||||
)
|
||||
return <VoidCell />
|
||||
}
|
||||
|
||||
return (
|
||||
<ReadonlyCell>
|
||||
<div className="flex h-full w-full items-center gap-x-2 overflow-hidden">
|
||||
<span className="truncate">{entity.title}</span>
|
||||
</div>
|
||||
</ReadonlyCell>
|
||||
<CurrencyCell
|
||||
currency={currency}
|
||||
meta={table.options.meta as DataGridMeta}
|
||||
field={`products.${entity.product_id}.variants.${entity.id}.currency_prices.${currency.code}.amount`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
}),
|
||||
...currencies.map((currency) => {
|
||||
return columnHelper.display({
|
||||
header: `Price ${currency.code.toUpperCase()}`,
|
||||
cell: ({ row, table }) => {
|
||||
const entity = row.original
|
||||
|
||||
if (isProductRow(entity)) {
|
||||
return <VoidCell />
|
||||
}
|
||||
|
||||
return (
|
||||
<CurrencyCell
|
||||
currency={currency}
|
||||
meta={table.options.meta as DataGridMeta}
|
||||
field={`products.${entity.product_id}.variants.${entity.id}.currency_prices.${currency.code}.amount`}
|
||||
/>
|
||||
)
|
||||
},
|
||||
})
|
||||
}),
|
||||
]
|
||||
}, [t, currencies])
|
||||
})
|
||||
}),
|
||||
]
|
||||
}, [t, currencies])
|
||||
|
||||
return colDefs
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { PriceListDTO, ProductVariantDTO } from "@medusajs/types"
|
||||
import { PriceListDTO, HttpTypes } from "@medusajs/types"
|
||||
import { TFunction } from "i18next"
|
||||
import { ExtendedProductDTO } from "../../../types/api-responses"
|
||||
import { PriceListStatus } from "./constants"
|
||||
|
||||
const getValues = (priceList: PriceListDTO) => {
|
||||
@@ -49,7 +48,7 @@ export const getPriceListStatus = (
|
||||
}
|
||||
|
||||
export const isProductRow = (
|
||||
row: ExtendedProductDTO | ProductVariantDTO
|
||||
): row is ExtendedProductDTO => {
|
||||
row: HttpTypes.AdminProduct | HttpTypes.AdminProductVariant
|
||||
): row is HttpTypes.AdminProduct => {
|
||||
return "variants" in row
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,9 +13,9 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p
|
||||
import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters"
|
||||
import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
import { PricingProductsRecordType } from "../../../common/schemas"
|
||||
import { PricingCreateSchemaType } from "./schema"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type PricingProductsFormProps = {
|
||||
form: UseFormReturn<PricingCreateSchemaType>
|
||||
@@ -132,7 +132,7 @@ export const PricingProductsForm = ({ form }: PricingProductsFormProps) => {
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const base = useProductTableColumns()
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
import { PencilSquare, Plus, Trash } from "@medusajs/icons"
|
||||
import { PriceListDTO } from "@medusajs/types"
|
||||
import { PriceListDTO, HttpTypes } from "@medusajs/types"
|
||||
import { Checkbox, Container, Heading, usePrompt } from "@medusajs/ui"
|
||||
import { keepPreviousData } from "@tanstack/react-query"
|
||||
import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
|
||||
@@ -13,7 +13,6 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p
|
||||
import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters"
|
||||
import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
|
||||
type PricingProductSectionProps = {
|
||||
priceList: PriceListDTO
|
||||
@@ -145,7 +144,7 @@ export const PricingProductSection = ({
|
||||
)
|
||||
}
|
||||
|
||||
const ProductRowAction = ({ product }: { product: ExtendedProductDTO }) => {
|
||||
const ProductRowAction = ({ product }: { product: HttpTypes.AdminProduct }) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
// TODO: The endpoint to remove prices by product id is not implemented in v2.
|
||||
@@ -171,7 +170,7 @@ const ProductRowAction = ({ product }: { product: ExtendedProductDTO }) => {
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const base = useProductTableColumns()
|
||||
|
||||
+3
-3
@@ -2,6 +2,7 @@ import {
|
||||
CreatePriceListPriceDTO,
|
||||
PriceListDTO,
|
||||
UpdatePriceListPriceDTO,
|
||||
HttpTypes,
|
||||
} from "@medusajs/types"
|
||||
import { Button } from "@medusajs/ui"
|
||||
import { UseFormReturn, useForm, useWatch } from "react-hook-form"
|
||||
@@ -23,7 +24,6 @@ import {
|
||||
} from "../../../../../hooks/api/price-lists"
|
||||
import { useStore } from "../../../../../hooks/api/store"
|
||||
import { castNumber } from "../../../../../lib/cast-number"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
import { usePriceListGridColumns } from "../../../common/hooks/use-price-list-grid-columns"
|
||||
import {
|
||||
PricingProductsRecordSchema,
|
||||
@@ -33,7 +33,7 @@ import { isProductRow } from "../../../common/utils"
|
||||
|
||||
type PricingProductPricesFormProps = {
|
||||
priceList: PriceListDTO
|
||||
products: ExtendedProductDTO[]
|
||||
products: HttpTypes.AdminProduct[]
|
||||
}
|
||||
|
||||
const PricingProductPricesSchema = z.object({
|
||||
@@ -245,7 +245,7 @@ export const PricingProductPricesForm = ({
|
||||
}
|
||||
|
||||
function initDefaultValues(
|
||||
products: ExtendedProductDTO[],
|
||||
products: HttpTypes.AdminProduct[],
|
||||
existingProducts: any,
|
||||
form: UseFormReturn<z.infer<typeof PricingProductPricesSchema>>,
|
||||
record: VariantsPriceRecord
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CurrencyDTO, ProductVariantDTO } from "@medusajs/types"
|
||||
import { CurrencyDTO, HttpTypes } from "@medusajs/types"
|
||||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
import { UseFormReturn, useWatch } from "react-hook-form"
|
||||
@@ -48,7 +48,7 @@ export const VariantPricingForm = ({ form }: VariantPricingFormProps) => {
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ProductVariantDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProductVariant>()
|
||||
|
||||
export const useVariantPriceGridColumns = ({
|
||||
currencies = [],
|
||||
@@ -57,7 +57,7 @@ export const useVariantPriceGridColumns = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const colDefs: ColumnDef<ProductVariantDTO>[] = useMemo(() => {
|
||||
const colDefs: ColumnDef<HttpTypes.AdminProductVariant>[] = useMemo(() => {
|
||||
return [
|
||||
columnHelper.display({
|
||||
id: t("fields.title"),
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Button, Input } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -11,9 +10,10 @@ import {
|
||||
useRouteModal,
|
||||
} from "../../../../../components/route-modal"
|
||||
import { useUpdateProduct } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductAttributesFormProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
const dimension = zod
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Button, Input, toast } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -12,9 +11,10 @@ import {
|
||||
useRouteModal,
|
||||
} from "../../../../../components/route-modal"
|
||||
import { useCreateProductOption } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type EditProductOptionsFormProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
const CreateProductOptionSchema = z.object({
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Button, Heading, Input, Switch } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -17,9 +16,10 @@ import {
|
||||
import { useCreateProductVariant } from "../../../../../hooks/api/products"
|
||||
import { castNumber } from "../../../../../lib/cast-number"
|
||||
import { optionalInt } from "../../../../../lib/validation"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type CreateProductVariantFormProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
isStockAndInventoryEnabled?: boolean
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -3,7 +3,7 @@ import { Button, ProgressStatus, ProgressTabs, toast } from "@medusajs/ui"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import { useForm, useWatch } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { SalesChannelDTO } from "@medusajs/types"
|
||||
import { SalesChannelDTO, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
RouteFocusModal,
|
||||
useRouteModal,
|
||||
@@ -21,7 +21,6 @@ import { ProductCreateInventoryKitForm } from "../product-create-inventory-kit-f
|
||||
import { ProductCreateVariantsForm } from "../product-create-variants-form"
|
||||
import { isFetchError } from "../../../../../lib/is-fetch-error"
|
||||
import { sdk } from "../../../../../lib/client"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
enum Tab {
|
||||
DETAILS = "details",
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
import { ProductVariantDTO, RegionDTO } from "@medusajs/types"
|
||||
import { HttpTypes, RegionDTO } from "@medusajs/types"
|
||||
import { useMemo } from "react"
|
||||
import { UseFormReturn, useWatch } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -10,7 +10,6 @@ import { DataGridTextCell } from "../../../../../components/data-grid/data-grid-
|
||||
import { createDataGridHelper } from "../../../../../components/data-grid/utils"
|
||||
import { DataGridCurrencyCell } from "../../../../../components/data-grid/data-grid-cells/data-grid-currency-cell"
|
||||
import { DataGridBooleanCell } from "../../../../../components/data-grid/data-grid-cells/data-grid-boolean-cell"
|
||||
import { DataGridCountrySelectCell } from "../../../../../components/data-grid/data-grid-cells/data-grid-country-select-cell"
|
||||
import { useRegions } from "../../../../../hooks/api/regions"
|
||||
|
||||
type ProductCreateVariantsFormProps = {
|
||||
@@ -64,7 +63,7 @@ export const ProductCreateVariantsForm = ({
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createDataGridHelper<ProductVariantDTO>()
|
||||
const columnHelper = createDataGridHelper<HttpTypes.AdminProductVariant>()
|
||||
|
||||
const useColumns = ({
|
||||
options,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { CreateProductDTO } from "@medusajs/types"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { ProductCreateSchemaType } from "./types"
|
||||
import { castNumber } from "../../../lib/cast-number"
|
||||
|
||||
export const normalizeProductFormValues = (
|
||||
values: ProductCreateSchemaType & { status: CreateProductDTO["status"] }
|
||||
values: ProductCreateSchemaType & { status: HttpTypes.AdminProductStatus }
|
||||
) => {
|
||||
const thumbnail = values.media?.find((media) => media.isThumbnail)?.url
|
||||
const images = values.media
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
import { PencilSquare } from "@medusajs/icons"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Container, Heading, Text } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { SectionRow } from "../../../../../components/common/section"
|
||||
import { getFormattedCountry } from "../../../../../lib/addresses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductAttributeSectionProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductAttributeSection = ({
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Container, Heading, StatusBadge, usePrompt } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { SectionRow } from "../../../../../components/common/section"
|
||||
import { useDeleteProduct } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const productStatusColor = (status: string) => {
|
||||
switch (status) {
|
||||
@@ -23,7 +23,7 @@ const productStatusColor = (status: string) => {
|
||||
}
|
||||
|
||||
type ProductGeneralSectionProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductGeneralSection = ({
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { PencilSquare, ThumbnailBadge } from "@medusajs/icons"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
@@ -16,9 +15,10 @@ import { useTranslation } from "react-i18next"
|
||||
import { Link } from "react-router-dom"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { useUpdateProduct } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductMedisaSectionProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductMediaSection = ({ product }: ProductMedisaSectionProps) => {
|
||||
|
||||
+6
-6
@@ -1,17 +1,17 @@
|
||||
import { PencilSquare, Plus, Trash } from "@medusajs/icons"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Badge, Container, Heading, usePrompt } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { SectionRow } from "../../../../../components/common/section"
|
||||
import { useDeleteProductOption } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const OptionActions = ({
|
||||
product,
|
||||
option,
|
||||
}: {
|
||||
product: Product
|
||||
option: any
|
||||
product: HttpTypes.AdminProduct
|
||||
option: HttpTypes.AdminProductOption
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { mutateAsync } = useDeleteProductOption(product.id, option.id)
|
||||
@@ -61,7 +61,7 @@ const OptionActions = ({
|
||||
}
|
||||
|
||||
type ProductOptionSectionProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductOptionSection = ({
|
||||
@@ -88,12 +88,12 @@ export const ProductOptionSection = ({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{product.options.map((option) => {
|
||||
{product.options?.map((option) => {
|
||||
return (
|
||||
<SectionRow
|
||||
title={option.title}
|
||||
key={option.id}
|
||||
value={option.values.map((val) => {
|
||||
value={option.values?.map((val) => {
|
||||
return (
|
||||
<Badge
|
||||
key={val.value}
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
import { PencilSquare } from "@medusajs/icons"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Badge, Container, Heading } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Link } from "react-router-dom"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { SectionRow } from "../../../../../components/common/section"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductOrganizationSectionProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductOrganizationSection = ({
|
||||
@@ -37,7 +37,7 @@ export const ProductOrganizationSection = ({
|
||||
<SectionRow
|
||||
title={t("fields.tags")}
|
||||
value={
|
||||
product.tags.length > 0
|
||||
product.tags?.length
|
||||
? product.tags.map((tag) => (
|
||||
<Badge key={tag.id} className="w-fit" size="2xsmall" asChild>
|
||||
<Link to={`/products?tags=${tag.id}`}>{tag.value}</Link>
|
||||
@@ -75,7 +75,7 @@ export const ProductOrganizationSection = ({
|
||||
<SectionRow
|
||||
title={t("fields.categories")}
|
||||
value={
|
||||
product.categories?.length > 0
|
||||
product.categories?.length
|
||||
? product.categories.map((pcat) => (
|
||||
<Badge
|
||||
key={pcat.id}
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
import { Channels, PencilSquare } from "@medusajs/icons"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Container, Heading, Text, Tooltip } from "@medusajs/ui"
|
||||
import { Trans, useTranslation } from "react-i18next"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { useSalesChannels } from "../../../../../hooks/api/sales-channels"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductSalesChannelSectionProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
// TODO: The fetched sales channel doesn't contain all necessary info
|
||||
|
||||
+2
-2
@@ -1,7 +1,6 @@
|
||||
import { PencilSquare, Plus } from "@medusajs/icons"
|
||||
import { Container, Heading } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { ProductDTO } from "@medusajs/types"
|
||||
import { keepPreviousData } from "@tanstack/react-query"
|
||||
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
@@ -11,9 +10,10 @@ import { useProductVariantTableColumns } from "./use-variant-table-columns"
|
||||
import { useProductVariantTableFilters } from "./use-variant-table-filters"
|
||||
import { useProductVariantTableQuery } from "./use-variant-table-query"
|
||||
import { useProductVariants } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductVariantSectionProps = {
|
||||
product: ProductDTO
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
const PAGE_SIZE = 10
|
||||
|
||||
+10
-6
@@ -1,5 +1,4 @@
|
||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||
import { Product, ProductVariant } from "@medusajs/medusa"
|
||||
import { Badge, usePrompt } from "@medusajs/ui"
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
@@ -8,13 +7,14 @@ import { useTranslation } from "react-i18next"
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
|
||||
import { useDeleteVariant } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const VariantActions = ({
|
||||
variant,
|
||||
product,
|
||||
}: {
|
||||
variant: ProductVariant
|
||||
product: Product
|
||||
variant: HttpTypes.AdminProductVariant
|
||||
product: HttpTypes.AdminProduct
|
||||
}) => {
|
||||
const { mutateAsync } = useDeleteVariant(product.id, variant.id)
|
||||
const { t } = useTranslation()
|
||||
@@ -63,9 +63,11 @@ const VariantActions = ({
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ProductVariant>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProductVariant>()
|
||||
|
||||
export const useProductVariantTableColumns = (product?: Product) => {
|
||||
export const useProductVariantTableColumns = (
|
||||
product?: HttpTypes.AdminProduct
|
||||
) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const optionColumns = useMemo(() => {
|
||||
@@ -141,7 +143,9 @@ export const useProductVariantTableColumns = (product?: Product) => {
|
||||
columnHelper.display({
|
||||
id: "actions",
|
||||
cell: ({ row, table }) => {
|
||||
const { product } = table.options.meta as { product: Product }
|
||||
const { product } = table.options.meta as {
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
return <VariantActions variant={row.original} product={product} />
|
||||
},
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { AdminGetProductsVariantsParams } from "@medusajs/medusa"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { useQueryParams } from "../../../../../hooks/use-query-params"
|
||||
|
||||
export const useProductVariantTableQuery = ({
|
||||
@@ -31,7 +31,7 @@ export const useProductVariantTableQuery = ({
|
||||
order,
|
||||
} = queryObject
|
||||
|
||||
const searchParams: AdminGetProductsVariantsParams = {
|
||||
const searchParams: HttpTypes.AdminProductVariantParams = {
|
||||
limit: pageSize,
|
||||
offset: offset ? Number(offset) : 0,
|
||||
manage_inventory: manage_inventory
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
|
||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
import { PRODUCT_DETAIL_FIELDS } from "./constants"
|
||||
|
||||
const productDetailQuery = (id: string) => ({
|
||||
queryKey: productsQueryKeys.detail(id),
|
||||
queryFn: async () =>
|
||||
client.products.retrieve(id, { fields: PRODUCT_DETAIL_FIELDS }),
|
||||
sdk.admin.product.retrieve(id, { fields: PRODUCT_DETAIL_FIELDS }),
|
||||
})
|
||||
|
||||
export const productLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { ProductOption } from "@medusajs/medusa"
|
||||
import { Button, Input } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -12,9 +11,10 @@ import {
|
||||
useRouteModal,
|
||||
} from "../../../../../components/route-modal"
|
||||
import { useUpdateProductOption } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type EditProductOptionFormProps = {
|
||||
option: ProductOption
|
||||
option: HttpTypes.AdminProductOption
|
||||
}
|
||||
|
||||
const CreateProductOptionSchema = z.object({
|
||||
|
||||
+3
-3
@@ -1,5 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Product, ProductVariant } from "@medusajs/medusa"
|
||||
import { Button, Heading, Input, Switch } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -19,10 +18,11 @@ import {
|
||||
parseOptionalFormNumber,
|
||||
} from "../../../../../lib/form-helpers"
|
||||
import { optionalInt } from "../../../../../lib/validation"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductEditVariantFormProps = {
|
||||
product: Product
|
||||
variant: ProductVariant
|
||||
product: HttpTypes.AdminProduct
|
||||
variant: HttpTypes.AdminProductVariant
|
||||
}
|
||||
|
||||
const ProductEditVariantSchema = z.object({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
|
||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
|
||||
const queryKey = (id: string) => {
|
||||
@@ -9,7 +9,7 @@ const queryKey = (id: string) => {
|
||||
}
|
||||
|
||||
const queryFn = async (id: string) => {
|
||||
return await client.products.retrieve(id)
|
||||
return await sdk.admin.product.retrieve(id)
|
||||
}
|
||||
|
||||
const editProductVariantQuery = (id: string) => ({
|
||||
|
||||
+3
-3
@@ -1,4 +1,3 @@
|
||||
import { ProductVariant } from "@medusajs/medusa"
|
||||
import { Heading } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { json, useLoaderData, useParams } from "react-router-dom"
|
||||
@@ -6,6 +5,7 @@ import { RouteDrawer } from "../../../components/route-modal"
|
||||
import { useProduct } from "../../../hooks/api/products"
|
||||
import { ProductEditVariantForm } from "./components/product-edit-variant-form"
|
||||
import { editProductVariantLoader } from "./loader"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const ProductEditVariant = () => {
|
||||
const initialData = useLoaderData() as Awaited<
|
||||
@@ -20,7 +20,7 @@ export const ProductEditVariant = () => {
|
||||
})
|
||||
|
||||
const variant = product?.variants.find(
|
||||
(v: ProductVariant) => v.id === variant_id
|
||||
(v: HttpTypes.AdminProductVariant) => v.id === variant_id
|
||||
)
|
||||
|
||||
if (!isLoading && !variant) {
|
||||
@@ -44,7 +44,7 @@ export const ProductEditVariant = () => {
|
||||
{ready && (
|
||||
<ProductEditVariantForm
|
||||
product={product}
|
||||
variant={variant as unknown as ProductVariant}
|
||||
variant={variant as unknown as HttpTypes.AdminProductVariant}
|
||||
/>
|
||||
)}
|
||||
</RouteDrawer>
|
||||
|
||||
+3
-4
@@ -1,6 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { ProductStatus } from "@medusajs/types"
|
||||
import { Button, Input, Select, Text, Textarea } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -14,9 +12,10 @@ import {
|
||||
} from "../../../../../components/route-modal"
|
||||
import { useUpdateProduct } from "../../../../../hooks/api/products"
|
||||
import { parseOptionalFormData } from "../../../../../lib/form-helpers"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type EditProductFormProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
const EditProductSchema = zod.object({
|
||||
@@ -58,7 +57,7 @@ export const EditProductForm = ({ product }: EditProductFormProps) => {
|
||||
title,
|
||||
discountable,
|
||||
handle,
|
||||
status: status as ProductStatus,
|
||||
status: status as HttpTypes.AdminProductStatus,
|
||||
...nullableData,
|
||||
},
|
||||
{
|
||||
|
||||
+4
-4
@@ -16,8 +16,8 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p
|
||||
import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters"
|
||||
import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
import { productsLoader } from "../../loader"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
|
||||
@@ -43,7 +43,7 @@ export const ProductListTable = () => {
|
||||
const columns = useColumns()
|
||||
|
||||
const { table } = useDataTable({
|
||||
data: (products ?? []) as ExtendedProductDTO[],
|
||||
data: (products ?? []) as HttpTypes.AdminProduct[],
|
||||
columns,
|
||||
count,
|
||||
enablePagination: true,
|
||||
@@ -81,7 +81,7 @@ export const ProductListTable = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const ProductActions = ({ product }: { product: ExtendedProductDTO }) => {
|
||||
const ProductActions = ({ product }: { product: HttpTypes.AdminProduct }) => {
|
||||
const { t } = useTranslation()
|
||||
const prompt = usePrompt()
|
||||
const { mutateAsync } = useDeleteProduct(product.id)
|
||||
@@ -144,7 +144,7 @@ const ProductActions = ({ product }: { product: ExtendedProductDTO }) => {
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const base = useProductTableColumns()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { QueryClient } from "@tanstack/react-query"
|
||||
|
||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
import { ProductListRes } from "../../../types/api-responses"
|
||||
|
||||
const productsListQuery = () => ({
|
||||
queryKey: productsQueryKeys.list({ limit: 20, offset: 0 }),
|
||||
queryFn: async () => client.products.list({ limit: 20, offset: 0 }),
|
||||
queryFn: async () => sdk.admin.product.list({ limit: 20, offset: 0 }),
|
||||
})
|
||||
|
||||
export const productsLoader = (client: QueryClient) => {
|
||||
|
||||
+6
-3
@@ -5,7 +5,6 @@ import {
|
||||
TriangleLeftMini,
|
||||
TriangleRightMini,
|
||||
} from "@medusajs/icons"
|
||||
import { Image, Product } from "@medusajs/medusa"
|
||||
import { Button, IconButton, Text, Tooltip, clx, usePrompt } from "@medusajs/ui"
|
||||
import { useCallback, useEffect, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -13,9 +12,10 @@ import { Link, useLocation } from "react-router-dom"
|
||||
|
||||
import { RouteFocusModal } from "../../../../../components/route-modal"
|
||||
import { useUpdateProduct } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductMediaGalleryProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
export const ProductMediaGallery = ({ product }: ProductMediaGalleryProps) => {
|
||||
@@ -303,7 +303,10 @@ type Media = {
|
||||
isThumbnail: boolean
|
||||
}
|
||||
|
||||
const getMedia = (images: Image[] | null, thumbnail: string | null) => {
|
||||
const getMedia = (
|
||||
images: HttpTypes.AdminProductImage[] | null,
|
||||
thumbnail: string | null
|
||||
) => {
|
||||
const media: Media[] =
|
||||
images?.map((image) => ({
|
||||
id: image.id,
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Button, toast } from "@medusajs/ui"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -14,9 +13,10 @@ import { useUpdateProduct } from "../../../../../hooks/api/products"
|
||||
import { useComboboxData } from "../../../../../hooks/use-combobox-data"
|
||||
import { client, sdk } from "../../../../../lib/client"
|
||||
import { CategoryCombobox } from "../../../common/components/category-combobox"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type ProductOrganizationFormProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
const ProductOrganizationSchema = zod.object({
|
||||
|
||||
@@ -5,9 +5,9 @@ import { useTranslation } from "react-i18next"
|
||||
import * as zod from "zod"
|
||||
import { RouteFocusModal, useRouteModal } from "../../../components/route-modal"
|
||||
import { useUpdateProductVariantsBatch } from "../../../hooks/api/products"
|
||||
import { ExtendedProductDTO } from "../../../types/api-responses"
|
||||
import { VariantPricingForm } from "../common/variant-pricing-form"
|
||||
import { castNumber } from "../../../lib/cast-number"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const UpdateVariantPricesSchema = zod.object({
|
||||
variants: zod.array(
|
||||
@@ -23,7 +23,11 @@ export type UpdateVariantPricesSchemaType = zod.infer<
|
||||
typeof UpdateVariantPricesSchema
|
||||
>
|
||||
|
||||
export const PricingEdit = ({ product }: { product: ExtendedProductDTO }) => {
|
||||
export const PricingEdit = ({
|
||||
product,
|
||||
}: {
|
||||
product: HttpTypes.AdminProduct
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { handleSuccess } = useRouteModal()
|
||||
const form = useForm<UpdateVariantPricesSchemaType>({
|
||||
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
import { Product, SalesChannel } from "@medusajs/medusa"
|
||||
import { SalesChannel } from "@medusajs/medusa"
|
||||
import { Button, Checkbox } from "@medusajs/ui"
|
||||
import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
@@ -18,9 +18,10 @@ import { useSalesChannelTableQuery } from "../../../../../hooks/table/query/use-
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { useSalesChannels } from "../../../../../hooks/api/sales-channels"
|
||||
import { useUpdateProduct } from "../../../../../hooks/api/products"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type EditSalesChannelsFormProps = {
|
||||
product: Product
|
||||
product: HttpTypes.AdminProduct
|
||||
}
|
||||
|
||||
const EditSalesChannelsSchema = zod.object({
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import { useProductTableColumns } from "../../../../hooks/table/columns/use-prod
|
||||
import { useProductTableFilters } from "../../../../hooks/table/filters/use-product-table-filters"
|
||||
import { useProductTableQuery } from "../../../../hooks/table/query/use-product-table-query"
|
||||
import { useDataTable } from "../../../../hooks/use-data-table"
|
||||
import { ExtendedProductDTO } from "../../../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type AddProductsToSalesChannelFormProps = {
|
||||
salesChannel: SalesChannelDTO
|
||||
@@ -176,7 +176,7 @@ export const AddProductsToSalesChannelForm = ({
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const base = useProductTableColumns()
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p
|
||||
import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters"
|
||||
import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { ExtendedProductDTO } from "../../../../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const PAGE_SIZE = 10
|
||||
|
||||
@@ -154,7 +154,7 @@ export const SalesChannelProductSection = ({
|
||||
)
|
||||
}
|
||||
|
||||
const columnHelper = createColumnHelper<ExtendedProductDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
const useColumns = () => {
|
||||
const base = useProductTableColumns()
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
import { CustomerGroup, Product, ProductType } from "@medusajs/medusa"
|
||||
import { CustomerGroup } from "@medusajs/medusa"
|
||||
import { Button } from "@medusajs/ui"
|
||||
import { OnChangeFn, RowSelectionState } from "@tanstack/react-table"
|
||||
import { useState } from "react"
|
||||
@@ -25,7 +25,6 @@ import { useProductCollectionConditionsTableColumns } from "../../hooks/columns/
|
||||
import { useProductCollectionConditionsTableFilters } from "../../hooks/filters/use-product-collection-conditions-table-filters"
|
||||
import { useProductCollectionConditionsTableQuery } from "../../hooks/query/use-product-collection-conditions-table-query"
|
||||
|
||||
import { ProductCollectionDTO } from "@medusajs/types"
|
||||
import { keepPreviousData } from "@tanstack/react-query"
|
||||
import { useCollections } from "../../../../../hooks/api/collections"
|
||||
import { useCustomerGroups } from "../../../../../hooks/api/customer-groups"
|
||||
@@ -33,6 +32,7 @@ import { useProductTypes } from "../../../../../hooks/api/product-types"
|
||||
import { useProducts } from "../../../../../hooks/api/products"
|
||||
import { ConditionEntities } from "../../constants"
|
||||
import { ConditionsOption } from "../../types"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
@@ -102,7 +102,7 @@ const ProductConditionsTable = ({ selected = [], onSave }: ConditionsProps) => {
|
||||
|
||||
if (added.length) {
|
||||
const addedProducts = (products?.filter((p) => added.includes(p.id!)) ??
|
||||
[]) as Product[]
|
||||
[]) as HttpTypes.AdminProduct[]
|
||||
|
||||
if (addedProducts.length > 0) {
|
||||
const newConditions = addedProducts.map((p) => ({
|
||||
@@ -322,7 +322,7 @@ const ProductTypeConditionsTable = ({
|
||||
|
||||
if (added.length) {
|
||||
const addedTypes = (product_types?.filter((p) => added.includes(p.id!)) ??
|
||||
[]) as ProductType[]
|
||||
[]) as HttpTypes.AdminProductType[]
|
||||
|
||||
if (addedTypes.length > 0) {
|
||||
const newConditions = addedTypes.map((p) => ({
|
||||
@@ -431,7 +431,7 @@ const ProductCollectionConditionsTable = ({
|
||||
if (added.length) {
|
||||
const addedCollections = (collections?.filter((p) =>
|
||||
added.includes(p.id!)
|
||||
) ?? []) as ProductCollectionDTO[]
|
||||
) ?? []) as HttpTypes.AdminCollection[]
|
||||
|
||||
if (addedCollections.length > 0) {
|
||||
const newConditions = addedCollections.map((p) => ({
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { ProductCollectionDTO } from "@medusajs/types"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Checkbox } from "@medusajs/ui"
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
const columnHelper = createColumnHelper<ProductCollectionDTO>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminCollection>()
|
||||
|
||||
export const useProductCollectionConditionsTableColumns = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import { Checkbox } from "@medusajs/ui"
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
import { useProductTableColumns } from "../../../../../hooks/table/columns/use-product-table-columns"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const columnHelper = createColumnHelper<Product>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
|
||||
|
||||
export const useProductConditionsTableColumns = () => {
|
||||
const base = useProductTableColumns()
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { ProductType } from "@medusajs/medusa"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Checkbox } from "@medusajs/ui"
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
const columnHelper = createColumnHelper<ProductType>()
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminProductType>()
|
||||
|
||||
export const useProductTypeConditionsTableColumns = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
@@ -13,11 +13,6 @@ import {
|
||||
OrderDTO,
|
||||
PaymentProviderDTO,
|
||||
PriceListDTO,
|
||||
ProductCategoryDTO,
|
||||
ProductCollectionDTO,
|
||||
ProductDTO,
|
||||
ProductTypeDTO,
|
||||
ProductVariantDTO,
|
||||
PromotionDTO,
|
||||
PromotionRuleDTO,
|
||||
SalesChannelDTO,
|
||||
@@ -27,9 +22,9 @@ import {
|
||||
StockLocationDTO,
|
||||
StoreDTO,
|
||||
UserDTO,
|
||||
HttpTypes,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { ProductTagDTO } from "@medusajs/types/dist/product"
|
||||
import { WorkflowExecutionDTO } from "../routes/workflow-executions/types"
|
||||
|
||||
type ListRes = {
|
||||
@@ -105,29 +100,6 @@ export type InviteDeleteRes = DeleteRes
|
||||
export type OrderRes = { order: OrderDTO }
|
||||
export type OrderListRes = { orders: OrderDTO[] } & ListRes
|
||||
|
||||
// Products
|
||||
export type ExtendedProductDTO = ProductDTO & {
|
||||
variants: ProductVariantDTO[] | null
|
||||
sales_channels: SalesChannelDTO[] | null
|
||||
collections: ProductCollectionDTO[] | null
|
||||
categories: ProductCategoryDTO[] | null
|
||||
}
|
||||
export type ProductRes = { product: ExtendedProductDTO }
|
||||
export type ProductListRes = { products: ExtendedProductDTO[] } & ListRes
|
||||
export type ProductDeleteRes = DeleteRes
|
||||
|
||||
// Categories
|
||||
export type CategoryRes = { category: ProductCategoryDTO }
|
||||
export type CategoriesListRes = { categories: ProductCategoryDTO[] } & ListRes
|
||||
|
||||
// Tags
|
||||
export type TagRes = { tag: ProductTagDTO }
|
||||
export type TagsListRes = { tags: ProductTagDTO[] } & ListRes
|
||||
|
||||
// Product Types
|
||||
export type ProductTypeRes = { product_type: ProductTypeDTO }
|
||||
export type ProductTypeListRes = { product_types: ProductTypeDTO[] } & ListRes
|
||||
|
||||
// Payments
|
||||
|
||||
export type PaymentProvidersListRes = {
|
||||
|
||||
Reference in New Issue
Block a user