chore: Remove @medusajs/medusa usage + local types from dashboard (#8883)

Closes CC-403
This commit is contained in:
Oli Juhl authored and GitHub committed 2024-08-30 15:37:44 +00:00
1 parent 3da01035f3
commit 4350fe5368
62 files changed
+296 -618

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
"name": "@medusajs/dashboard", "name": "@medusajs/dashboard",
"version": "0.0.1", "version": "0.0.1",
"scripts": { "scripts": {
"generate:static": "node ./scripts/generate-countries.js && prettier --write ./src/lib/countries.ts && node ./scripts/generate-currencies.js && prettier --write ./src/lib/currencies.ts", "generate:static": "node ./scripts/generate-currencies.js && prettier --write ./src/lib/currencies.ts",
"dev": "vite", "dev": "vite",
"build": "tsup && node ./scripts/generate-types.js", "build": "tsup && node ./scripts/generate-types.js",
"build:preview": "vite build", "build:preview": "vite build",
@@ -1,16 +1,16 @@
import { Address, Cart, Order } from "@medusajs/medusa"
import { Avatar, Copy, Text } from "@medusajs/ui" import { Avatar, Copy, Text } from "@medusajs/ui"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { Link } from "react-router-dom" import { Link } from "react-router-dom"
import { HttpTypes } from "@medusajs/types"
import { getFormattedAddress, isSameAddress } from "../../../lib/addresses" import { getFormattedAddress, isSameAddress } from "../../../lib/addresses"
const ID = ({ data }: { data: Cart | Order }) => { const ID = ({ data }: { data: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
const id = data.customer_id const id = data.customer_id
const name = getCartOrOrderCustomer(data) const name = getOrderCustomer(data)
const email = data.email const email = data.email
const fallback = (name || email).charAt(0).toUpperCase() const fallback = (name || email || "").charAt(0).toUpperCase()
return ( return (
<div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4"> <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
@@ -36,7 +36,7 @@ const ID = ({ data }: { data: Cart | Order }) => {
) )
} }
const Company = ({ data }: { data: Order | Cart }) => { const Company = ({ data }: { data: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
const company = const company =
data.shipping_address?.company || data.billing_address?.company data.shipping_address?.company || data.billing_address?.company
@@ -57,11 +57,11 @@ const Company = ({ data }: { data: Order | Cart }) => {
) )
} }
const Contact = ({ data }: { data: Cart | Order }) => { const Contact = ({ data }: { data: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
const phone = data.shipping_address?.phone || data.billing_address?.phone const phone = data.shipping_address?.phone || data.billing_address?.phone
const email = data.email const email = data.email || ""
return ( return (
<div className="text-ui-fg-subtle grid grid-cols-2 items-start px-6 py-4"> <div className="text-ui-fg-subtle grid grid-cols-2 items-start px-6 py-4">
@@ -106,7 +106,9 @@ const AddressPrint = ({
address, address,
type, type,
}: { }: {
address: Address | null address:
| HttpTypes.AdminOrder["shipping_address"]
| HttpTypes.AdminOrder["billing_address"]
type: "shipping" | "billing" type: "shipping" | "billing"
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@@ -146,7 +148,7 @@ const AddressPrint = ({
) )
} }
const Addresses = ({ data }: { data: Cart | Order }) => { const Addresses = ({ data }: { data: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
@@ -183,7 +185,7 @@ export const CustomerInfo = Object.assign(
} }
) )
const getCartOrOrderCustomer = (obj: Cart | Order) => { const getOrderCustomer = (obj: HttpTypes.AdminOrder) => {
const { first_name: sFirstName, last_name: sLastName } = const { first_name: sFirstName, last_name: sLastName } =
obj.shipping_address || {} obj.shipping_address || {}
const { first_name: bFirstName, last_name: bLastName } = const { first_name: bFirstName, last_name: bLastName } =
@@ -1,4 +1,3 @@
import { Country } from "@medusajs/medusa"
import { Heading, Input, Select, clx } from "@medusajs/ui" import { Heading, Input, Select, clx } from "@medusajs/ui"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { z } from "zod" import { z } from "zod"
@@ -7,12 +6,13 @@ import { Control } from "react-hook-form"
import { AddressSchema } from "../../../lib/schemas" import { AddressSchema } from "../../../lib/schemas"
import { Form } from "../../common/form" import { Form } from "../../common/form"
import { CountrySelect } from "../../inputs/country-select" import { CountrySelect } from "../../inputs/country-select"
import { HttpTypes } from "@medusajs/types"
type AddressFieldValues = z.infer<typeof AddressSchema> type AddressFieldValues = z.infer<typeof AddressSchema>
type AddressFormProps = { type AddressFormProps = {
control: Control<AddressFieldValues> control: Control<AddressFieldValues>
countries?: Country[] countries?: HttpTypes.AdminRegionCountry[]
layout: "grid" | "stack" layout: "grid" | "stack"
} }
@@ -1,4 +1,3 @@
import { Customer, DraftOrder, Order } from "@medusajs/medusa"
import { Select, Text, clx } from "@medusajs/ui" import { Select, Text, clx } from "@medusajs/ui"
import { useInfiniteQuery } from "@tanstack/react-query" import { useInfiniteQuery } from "@tanstack/react-query"
import { format } from "date-fns" import { format } from "date-fns"
@@ -19,6 +18,7 @@ import { TransferOwnershipSchema } from "../../../lib/schemas"
import { Form } from "../../common/form" import { Form } from "../../common/form"
import { Skeleton } from "../../common/skeleton" import { Skeleton } from "../../common/skeleton"
import { Combobox } from "../../inputs/combobox" import { Combobox } from "../../inputs/combobox"
import { HttpTypes } from "@medusajs/types"
type TransferOwnerShipFieldValues = z.infer<typeof TransferOwnershipSchema> type TransferOwnerShipFieldValues = z.infer<typeof TransferOwnershipSchema>
@@ -26,14 +26,16 @@ type TransferOwnerShipFormProps = {
/** /**
* The Order or DraftOrder to transfer ownership of. * The Order or DraftOrder to transfer ownership of.
*/ */
order: Order | DraftOrder order: HttpTypes.AdminOrder
/** /**
* React Hook Form control object. * React Hook Form control object.
*/ */
control: Control<TransferOwnerShipFieldValues> control: Control<TransferOwnerShipFieldValues>
} }
const isOrder = (order: Order | DraftOrder): order is Order => { const isOrder = (
order: HttpTypes.AdminOrder
): order is HttpTypes.AdminOrder => {
return "customer" in order return "customer" in order
} }
@@ -90,7 +92,7 @@ export const TransferOwnerShipForm = ({
}, },
}) })
const createLabel = (customer?: Customer) => { const createLabel = (customer?: HttpTypes.AdminCustomer) => {
if (!customer) { if (!customer) {
return "" return ""
} }
@@ -187,7 +189,7 @@ export const TransferOwnerShipForm = ({
) )
} }
const OrderDetailsTable = ({ order }: { order: Order }) => { const OrderDetailsTable = ({ order }: { order: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { label: fulfillmentLabel } = getOrderFulfillmentStatus( const { label: fulfillmentLabel } = getOrderFulfillmentStatus(
@@ -208,7 +210,8 @@ const OrderDetailsTable = ({ order }: { order: Order }) => {
) )
} }
const DraftOrderDetailsTable = ({ draft }: { draft: DraftOrder }) => { // TODO: Create type for Draft Order when we have it
const DraftOrderDetailsTable = ({ draft }: { draft: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
@@ -219,10 +222,12 @@ const DraftOrderDetailsTable = ({ draft }: { draft: DraftOrder }) => {
label={t("fields.status")} label={t("fields.status")}
value={t(`draftOrders.status.${draft.status}`)} value={t(`draftOrders.status.${draft.status}`)}
/> />
<TotalRow
{/* TODO: This will likely change. We don't use carts for draft orders any longer. */}
{/* <TotalRow
total={draft.cart.total || 0} total={draft.cart.total || 0}
currencyCode={draft.cart.region.currency_code} currencyCode={draft.cart.region.currency_code}
/> /> */}
</Table> </Table>
) )
} }
@@ -1,9 +1,13 @@
import { Country } from "@medusajs/medusa"
import { Tooltip } from "@medusajs/ui" import { Tooltip } from "@medusajs/ui"
import ReactCountryFlag from "react-country-flag" import ReactCountryFlag from "react-country-flag"
import { PlaceholderCell } from "../../common/placeholder-cell" import { PlaceholderCell } from "../../common/placeholder-cell"
import { HttpTypes } from "@medusajs/types"
export const CountryCell = ({ country }: { country?: Country | null }) => { export const CountryCell = ({
country,
}: {
country?: HttpTypes.AdminRegionCountry | null
}) => {
if (!country) { if (!country) {
return <PlaceholderCell /> return <PlaceholderCell />
} }
@@ -13,7 +17,7 @@ export const CountryCell = ({ country }: { country?: Country | null }) => {
<Tooltip content={country.display_name}> <Tooltip content={country.display_name}>
<div className="flex size-4 items-center justify-center overflow-hidden rounded-sm"> <div className="flex size-4 items-center justify-center overflow-hidden rounded-sm">
<ReactCountryFlag <ReactCountryFlag
countryCode={country.iso_2.toUpperCase()} countryCode={country.iso_2!.toUpperCase()}
svg svg
style={{ style={{
width: "16px", width: "16px",
@@ -1,7 +1,11 @@
import { Customer } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
export const CustomerCell = ({ customer }: { customer: Customer | null }) => { export const CustomerCell = ({
customer,
}: {
customer: HttpTypes.AdminCustomer | null
}) => {
if (!customer) { if (!customer) {
return <span className="text-ui-fg-muted">-</span> return <span className="text-ui-fg-muted">-</span>
} }
@@ -1,10 +1,10 @@
import { SalesChannel } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
export const SalesChannelCell = ({ export const SalesChannelCell = ({
channel, channel,
}: { }: {
channel: SalesChannel | null channel: HttpTypes.AdminSalesChannel | null
}) => { }) => {
if (!channel) { if (!channel) {
return <span className="text-ui-fg-muted">-</span> return <span className="text-ui-fg-muted">-</span>
@@ -1,10 +1,10 @@
import { FulfillmentProvider } from "@medusajs/medusa"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { formatProvider } from "../../../../../lib/format-provider" import { formatProvider } from "../../../../../lib/format-provider"
import { PlaceholderCell } from "../../common/placeholder-cell" import { PlaceholderCell } from "../../common/placeholder-cell"
import { HttpTypes } from "@medusajs/types"
type FulfillmentProvidersCellProps = { type FulfillmentProvidersCellProps = {
fulfillmentProviders?: FulfillmentProvider[] | null fulfillmentProviders?: HttpTypes.AdminFulfillmentProvider[] | null
} }
export const FulfillmentProvidersCell = ({ export const FulfillmentProvidersCell = ({
@@ -1 +0,0 @@
export * from "./subtotal-requirement-cell"
@@ -1,43 +0,0 @@
import { ShippingOption } from "@medusajs/medusa"
import { useTranslation } from "react-i18next"
import { MoneyAmountCell } from "../../common/money-amount-cell"
import { PlaceholderCell } from "../../common/placeholder-cell"
type SubtotalType = "min" | "max"
type SubtotalRequirementCellProps = {
type: SubtotalType
shippingOption: ShippingOption
}
export const SubtotalRequirementCell = (
props: SubtotalRequirementCellProps
) => {
const requirement = props.shippingOption.requirements?.find(
(r) => r.type === `${props.type}_subtotal`
)
if (!requirement) {
return <PlaceholderCell />
}
return (
<MoneyAmountCell
currencyCode={props.shippingOption.region!.currency_code}
amount={requirement.amount}
/>
)
}
export const SubtotalRequirementHeader = ({ type }: { type: SubtotalType }) => {
const { t } = useTranslation()
const header =
type === "min" ? t("fields.minSubtotal") : t("fields.maxSubtotal")
return (
<div className="flex size-full items-center overflow-hidden">
<span className="truncate">{header}</span>
</div>
)
}
@@ -1,11 +1,14 @@
import { UseMutationOptions, useMutation } from "@tanstack/react-query" import { UseMutationOptions, useMutation } from "@tanstack/react-query"
import { FetchError } from "@medusajs/js-sdk" import { FetchError } from "@medusajs/js-sdk"
import { sdk } from "../../lib/client" import { sdk } from "../../lib/client"
import { EmailPassReq } from "../../types/api-payloads" import { HttpTypes } from "@medusajs/types"
export const useSignInWithEmailPassword = ( export const useSignInWithEmailPassword = (
options?: UseMutationOptions<string, FetchError, EmailPassReq> options?: UseMutationOptions<
string,
FetchError,
HttpTypes.AdminSignUpWithEmailPassword
>
) => { ) => {
return useMutation({ return useMutation({
mutationFn: (payload) => sdk.auth.login("user", "emailpass", payload), mutationFn: (payload) => sdk.auth.login("user", "emailpass", payload),
@@ -17,7 +20,11 @@ export const useSignInWithEmailPassword = (
} }
export const useSignUpWithEmailPass = ( export const useSignUpWithEmailPass = (
options?: UseMutationOptions<string, FetchError, EmailPassReq> options?: UseMutationOptions<
string,
FetchError,
HttpTypes.AdminSignInWithEmailPassword
>
) => { ) => {
return useMutation({ return useMutation({
mutationFn: (payload) => sdk.auth.register("user", "emailpass", payload), mutationFn: (payload) => sdk.auth.register("user", "emailpass", payload),
@@ -9,5 +9,5 @@ export * from "./use-product-type-table-columns"
export * from "./use-region-table-columns" export * from "./use-region-table-columns"
export * from "./use-return-reason-table-columns" export * from "./use-return-reason-table-columns"
export * from "./use-sales-channel-table-columns" export * from "./use-sales-channel-table-columns"
export * from "./use-shipping-option-table-columns"
export * from "./use-tax-rates-table-columns" export * from "./use-tax-rates-table-columns"
@@ -1,4 +1,3 @@
import { Order } from "@medusajs/medusa"
import { import {
ColumnDef, ColumnDef,
ColumnDefBase, ColumnDefBase,
@@ -34,9 +33,10 @@ import {
TotalCell, TotalCell,
TotalHeader, TotalHeader,
} from "../../../components/table/table-cells/order/total-cell" } from "../../../components/table/table-cells/order/total-cell"
import { HttpTypes } from "@medusajs/types"
// We have to use any here, as the type of Order is so complex that it lags the TS server // We have to use any here, as the type of Order is so complex that it lags the TS server
const columnHelper = createColumnHelper<Order>() const columnHelper = createColumnHelper<HttpTypes.AdminOrder>()
type UseOrderTableColumnsProps = { type UseOrderTableColumnsProps = {
exclude?: string[] exclude?: string[]
@@ -52,7 +52,7 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => {
cell: ({ getValue }) => { cell: ({ getValue }) => {
const id = getValue() const id = getValue()
return <DisplayIdCell displayId={id} /> return <DisplayIdCell displayId={id!} />
}, },
}), }),
columnHelper.accessor("created_at", { columnHelper.accessor("created_at", {
@@ -118,17 +118,19 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => {
const isAccessorColumnDef = ( const isAccessorColumnDef = (
c: any c: any
): c is ColumnDef<Order> & { accessorKey: string } => { ): c is ColumnDef<HttpTypes.AdminOrder> & { accessorKey: string } => {
return c.accessorKey !== undefined return c.accessorKey !== undefined
} }
const isDisplayColumnDef = ( const isDisplayColumnDef = (
c: any c: any
): c is ColumnDef<Order> & { id: string } => { ): c is ColumnDef<HttpTypes.AdminOrder> & { id: string } => {
return c.id !== undefined return c.id !== undefined
} }
const shouldExclude = <TDef extends ColumnDefBase<Order, any>>(c: TDef) => { const shouldExclude = <TDef extends ColumnDefBase<HttpTypes.AdminOrder, any>>(
c: TDef
) => {
if (isAccessorColumnDef(c)) { if (isAccessorColumnDef(c)) {
return exclude.includes(c.accessorKey) return exclude.includes(c.accessorKey)
} else if (isDisplayColumnDef(c)) { } else if (isDisplayColumnDef(c)) {
@@ -138,5 +140,7 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => {
return false return false
} }
return columns.filter((c) => !shouldExclude(c)) as ColumnDef<Order>[] return columns.filter(
(c) => !shouldExclude(c)
) as ColumnDef<HttpTypes.AdminOrder>[]
} }
@@ -1,107 +0,0 @@
import { ShippingOption } from "@medusajs/medusa"
import { PricedShippingOption } from "@medusajs/medusa/dist/types/pricing"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"
import {
AdminOnlyCell,
AdminOnlyHeader,
} from "../../../components/table/table-cells/shipping-option/admin-only-cell"
import {
IsReturnCell,
IsReturnHeader,
} from "../../../components/table/table-cells/shipping-option/is-return-cell"
import {
PriceTypeCell,
PriceTypeHeader,
} from "../../../components/table/table-cells/shipping-option/price-type-cell"
import {
ShippingOptionCell,
ShippingOptionHeader,
} from "../../../components/table/table-cells/shipping-option/shipping-option-cell"
import {
ShippingPriceCell,
ShippingPriceHeader,
} from "../../../components/table/table-cells/shipping-option/shipping-price-cell/shipping-price-cell"
import {
SubtotalRequirementCell,
SubtotalRequirementHeader,
} from "../../../components/table/table-cells/shipping-option/subtotal-requirement-cell"
const columnHelper = createColumnHelper<PricedShippingOption>()
export const useShippingOptionTableColumns = () => {
return useMemo(
() => [
columnHelper.accessor("name", {
header: () => <ShippingOptionHeader />,
cell: ({ getValue }) => <ShippingOptionCell name={getValue()} />,
}),
columnHelper.accessor("is_return", {
header: () => <IsReturnHeader />,
cell: (cell) => {
const value = cell.getValue()
return <IsReturnCell isReturn={value} />
},
}),
columnHelper.accessor("price_type", {
header: () => <PriceTypeHeader />,
cell: ({ getValue }) => {
const type = getValue()
return <PriceTypeCell priceType={type} />
},
}),
columnHelper.accessor("price_incl_tax", {
header: () => <ShippingPriceHeader />,
cell: ({ getValue, row }) => {
const isCalculated = row.original.price_type === "calculated"
const amount = getValue()
const currencyCode = row.original.region!.currency_code
return (
<ShippingPriceCell
isCalculated={isCalculated}
currencyCode={currencyCode}
price={amount}
/>
)
},
}),
columnHelper.display({
id: "min_amount",
header: () => <SubtotalRequirementHeader type="min" />,
cell: ({ row }) => {
return (
<SubtotalRequirementCell
type="min"
shippingOption={row.original as unknown as ShippingOption}
/>
)
},
}),
columnHelper.display({
id: "max_amount",
header: () => <SubtotalRequirementHeader type="max" />,
cell: ({ row }) => {
return (
<SubtotalRequirementCell
type="max"
shippingOption={row.original as unknown as ShippingOption}
/>
)
},
}),
columnHelper.accessor("admin_only", {
header: () => <AdminOnlyHeader />,
cell: (cell) => {
const value = cell.getValue() || false
return <AdminOnlyCell adminOnly={value} />
},
}),
],
[]
)
}
@@ -1,4 +1,4 @@
import { AdminGetPromotionsParams } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params" import { useQueryParams } from "../../use-query-params"
type UsePromotionTableQueryProps = { type UsePromotionTableQueryProps = {
@@ -17,7 +17,7 @@ export const usePromotionTableQuery = ({
const { offset, q, created_at, updated_at } = queryObject const { offset, q, created_at, updated_at } = queryObject
const searchParams: AdminGetPromotionsParams = { const searchParams: HttpTypes.AdminGetPromotionsParams = {
limit: pageSize, limit: pageSize,
created_at: created_at ? JSON.parse(created_at) : undefined, created_at: created_at ? JSON.parse(created_at) : undefined,
updated_at: updated_at ? JSON.parse(updated_at) : undefined, updated_at: updated_at ? JSON.parse(updated_at) : undefined,
@@ -1,5 +1,4 @@
import { AdminGetCustomerGroupsParams } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params" import { useQueryParams } from "../../use-query-params"
type UseCustomerGroupTableQueryProps = { type UseCustomerGroupTableQueryProps = {
@@ -18,7 +17,7 @@ export const useCustomerGroupTableQuery = ({
const { offset, created_at, updated_at, q, order } = queryObject const { offset, created_at, updated_at, q, order } = queryObject
const searchParams: AdminGetCustomerGroupsParams = { const searchParams: HttpTypes.AdminGetCustomerGroupsParams = {
limit: pageSize, limit: pageSize,
offset: offset ? Number(offset) : 0, offset: offset ? Number(offset) : 0,
order, order,
@@ -1,4 +1,4 @@
import { AdminGetCustomersParams } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params" import { useQueryParams } from "../../use-query-params"
type UseCustomerTableQueryProps = { type UseCustomerTableQueryProps = {
@@ -26,7 +26,7 @@ export const useCustomerTableQuery = ({
const { offset, groups, created_at, updated_at, has_account, q, order } = const { offset, groups, created_at, updated_at, has_account, q, order } =
queryObject queryObject
const searchParams: AdminGetCustomersParams = { const searchParams: HttpTypes.AdminCustomerFilters = {
limit: pageSize, limit: pageSize,
offset: offset ? Number(offset) : 0, offset: offset ? Number(offset) : 0,
groups: groups?.split(","), groups: groups?.split(","),
@@ -1,4 +1,4 @@
import { AdminGetOrdersParams } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params" import { useQueryParams } from "../../use-query-params"
type UseOrderTableQueryProps = { type UseOrderTableQueryProps = {
@@ -37,7 +37,7 @@ export const useOrderTableQuery = ({
order, order,
} = queryObject } = queryObject
const searchParams: AdminGetOrdersParams = { const searchParams: HttpTypes.AdminOrderFilters = {
limit: pageSize, limit: pageSize,
offset: offset ? Number(offset) : 0, offset: offset ? Number(offset) : 0,
sales_channel_id: sales_channel_id?.split(","), sales_channel_id: sales_channel_id?.split(","),
@@ -1,4 +1,4 @@
import { AdminGetShippingOptionsParams } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params" import { useQueryParams } from "../../use-query-params"
type UseShippingOptionTableQueryProps = { type UseShippingOptionTableQueryProps = {
@@ -29,10 +29,11 @@ export const useShippingOptionTableQuery = ({
const { offset, order, q, admin_only, is_return, created_at, updated_at } = const { offset, order, q, admin_only, is_return, created_at, updated_at } =
queryObject queryObject
const searchParams: AdminGetShippingOptionsParams = { const searchParams: HttpTypes.AdminShippingOptionListParams = {
limit: pageSize, limit: pageSize,
offset: offset ? Number(offset) : 0, offset: offset ? Number(offset) : 0,
region_id: regionId, // TODO: We don't allow region_id in the API yet
// region_id: regionId,
is_return: is_return ? is_return === "true" : undefined, is_return: is_return ? is_return === "true" : undefined,
admin_only: admin_only ? admin_only === "true" : undefined, admin_only: admin_only ? admin_only === "true" : undefined,
q, q,
@@ -1,4 +1,4 @@
import { AdminGetTaxRatesParams } from "@medusajs/medusa" import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params" import { useQueryParams } from "../../use-query-params"
type UseTaxRateTableQueryProps = { type UseTaxRateTableQueryProps = {
@@ -17,7 +17,7 @@ export const useTaxRateTableQuery = ({
const { offset, q, order, created_at, updated_at } = queryObject const { offset, q, order, created_at, updated_at } = queryObject
const searchParams: AdminGetTaxRatesParams = { const searchParams: HttpTypes.AdminTaxRateListParams = {
limit: pageSize, limit: pageSize,
offset: offset ? Number(offset) : 0, offset: offset ? Number(offset) : 0,
order, order,
@@ -1,8 +1,11 @@
import { AddressDTO } from "@medusajs/types" import { HttpTypes } from "@medusajs/types"
import { countries, getCountryByIso2 } from "./data/countries" import { countries, getCountryByIso2 } from "./data/countries"
export const isSameAddress = (a: AddressDTO | null, b: AddressDTO | null) => { export const isSameAddress = (
a?: HttpTypes.AdminOrderAddress | null,
b?: HttpTypes.AdminOrderAddress | null
) => {
if (!a || !b) { if (!a || !b) {
return false return false
} }
@@ -22,7 +25,7 @@ export const isSameAddress = (a: AddressDTO | null, b: AddressDTO | null) => {
export const getFormattedAddress = ({ export const getFormattedAddress = ({
address, address,
}: { }: {
address?: Partial<AddressDTO> | null address?: HttpTypes.AdminOrderAddress | null
}) => { }) => {
if (!address) { if (!address) {
return [] return []
@@ -70,7 +73,7 @@ export const getFormattedAddress = ({
} }
if (country) { if (country) {
formattedAddress.push(country.display_name) formattedAddress.push(country.display_name!)
} else if (country_code) { } else if (country_code) {
const country = getCountryByIso2(country_code) const country = getCountryByIso2(country_code)
@@ -9,7 +9,6 @@ import { ProtectedRoute } from "../../components/authentication/protected-route"
import { MainLayout } from "../../components/layout/main-layout" import { MainLayout } from "../../components/layout/main-layout"
import { SettingsLayout } from "../../components/layout/settings-layout" import { SettingsLayout } from "../../components/layout/settings-layout"
import { ErrorBoundary } from "../../components/utilities/error-boundary" import { ErrorBoundary } from "../../components/utilities/error-boundary"
import { PriceListRes } from "../../types/api-responses"
import { getCountryByIso2 } from "../../lib/data/countries" import { getCountryByIso2 } from "../../lib/data/countries"
import { import {
@@ -415,7 +414,8 @@ export const RouteMap: RouteObject[] = [
lazy: () => lazy: () =>
import("../../routes/price-lists/price-list-detail"), import("../../routes/price-lists/price-list-detail"),
handle: { handle: {
crumb: (data: PriceListRes) => data.price_list.title, crumb: (data: HttpTypes.AdminPriceListResponse) =>
data.price_list.title,
}, },
children: [ children: [
{ {
@@ -1,5 +1,4 @@
import { ArrowPath } from "@medusajs/icons" import { ArrowPath } from "@medusajs/icons"
import { Customer, Order } from "@medusajs/medusa"
import { Button, Container, Heading } from "@medusajs/ui" import { Button, Container, Heading } from "@medusajs/ui"
import { keepPreviousData } from "@tanstack/react-query" import { keepPreviousData } from "@tanstack/react-query"
import { createColumnHelper } from "@tanstack/react-table" import { createColumnHelper } from "@tanstack/react-table"
@@ -12,9 +11,10 @@ import { useOrderTableColumns } from "../../../../../hooks/table/columns/use-ord
import { useOrderTableFilters } from "../../../../../hooks/table/filters/use-order-table-filters" import { useOrderTableFilters } from "../../../../../hooks/table/filters/use-order-table-filters"
import { useOrderTableQuery } from "../../../../../hooks/table/query/use-order-table-query" import { useOrderTableQuery } from "../../../../../hooks/table/query/use-order-table-query"
import { useDataTable } from "../../../../../hooks/use-data-table" import { useDataTable } from "../../../../../hooks/use-data-table"
import { HttpTypes } from "@medusajs/types"
type CustomerGeneralSectionProps = { type CustomerGeneralSectionProps = {
customer: Customer customer: HttpTypes.AdminCustomer
} }
const PAGE_SIZE = 10 const PAGE_SIZE = 10
@@ -83,7 +83,7 @@ export const CustomerOrderSection = ({
) )
} }
const CustomerOrderActions = ({ order }: { order: Order }) => { const CustomerOrderActions = ({ order }: { order: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
@@ -103,7 +103,7 @@ const CustomerOrderActions = ({ order }: { order: Order }) => {
) )
} }
const columnHelper = createColumnHelper<Order>() const columnHelper = createColumnHelper<HttpTypes.AdminOrder>()
const useColumns = () => { const useColumns = () => {
const base = useOrderTableColumns({ exclude: ["customer"] }) const base = useOrderTableColumns({ exclude: ["customer"] })
@@ -1,18 +1,15 @@
import { zodResolver } from "@hookform/resolvers/zod" import { zodResolver } from "@hookform/resolvers/zod"
import { Order } from "@medusajs/medusa"
import { Button } from "@medusajs/ui" import { Button } 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"
import { z } from "zod" import { z } from "zod"
import { TransferOwnerShipForm } from "../../../../../components/forms/transfer-ownership-form" import { TransferOwnerShipForm } from "../../../../../components/forms/transfer-ownership-form"
import { import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
RouteDrawer,
useRouteModal,
} from "../../../../../components/modals"
import { TransferOwnershipSchema } from "../../../../../lib/schemas" import { TransferOwnershipSchema } from "../../../../../lib/schemas"
import { HttpTypes } from "@medusajs/types"
type TransferCustomerOrderOwnershipFormProps = { type TransferCustomerOrderOwnershipFormProps = {
order: Order order: HttpTypes.AdminOrder
} }
export const TransferCustomerOrderOwnershipForm = ({ export const TransferCustomerOrderOwnershipForm = ({
@@ -23,7 +20,7 @@ export const TransferCustomerOrderOwnershipForm = ({
const form = useForm<z.infer<typeof TransferOwnershipSchema>>({ const form = useForm<z.infer<typeof TransferOwnershipSchema>>({
defaultValues: { defaultValues: {
current_owner_id: order.customer_id, current_owner_id: order.customer_id ?? undefined,
new_owner_id: "", new_owner_id: "",
}, },
resolver: zodResolver(TransferOwnershipSchema), resolver: zodResolver(TransferOwnershipSchema),
@@ -1,12 +1,11 @@
import { Button, Container, Heading } from "@medusajs/ui" import { Button, Container, Heading } from "@medusajs/ui"
import { InventoryItemRes } from "../../../../types/api-responses"
import { ItemLocationListTable } from "./location-levels-table/location-list-table" import { ItemLocationListTable } from "./location-levels-table/location-list-table"
import { Link } from "react-router-dom" import { Link } from "react-router-dom"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { HttpTypes } from "@medusajs/types"
type InventoryItemLocationLevelsSectionProps = { type InventoryItemLocationLevelsSectionProps = {
inventoryItem: InventoryItemRes["inventory_item"] inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"]
} }
export const InventoryItemLocationLevelsSection = ({ export const InventoryItemLocationLevelsSection = ({
inventoryItem, inventoryItem,
@@ -1,12 +1,11 @@
import { Button, Container, Heading } from "@medusajs/ui" import { Button, Container, Heading } from "@medusajs/ui"
import { InventoryItemRes } from "../../../../types/api-responses"
import { Link } from "react-router-dom" import { Link } from "react-router-dom"
import { ReservationItemTable } from "./reservations-table/reservation-list-table" import { ReservationItemTable } from "./reservations-table/reservation-list-table"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { HttpTypes } from "@medusajs/types"
type InventoryItemLocationLevelsSectionProps = { type InventoryItemLocationLevelsSectionProps = {
inventoryItem: InventoryItemRes["inventory_item"] inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"]
} }
export const InventoryItemReservationsSection = ({ export const InventoryItemReservationsSection = ({
inventoryItem, inventoryItem,
@@ -1,7 +1,7 @@
import { PencilSquare, Trash } from "@medusajs/icons" import { PencilSquare, Trash } from "@medusajs/icons"
import { toast, usePrompt } from "@medusajs/ui" import { toast, usePrompt } from "@medusajs/ui"
import { InventoryTypes } from "@medusajs/types" import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { ActionMenu } from "../../../../../components/common/action-menu" import { ActionMenu } from "../../../../../components/common/action-menu"
import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" import { useDeleteReservationItem } from "../../../../../hooks/api/reservations"
@@ -9,7 +9,7 @@ import { useDeleteReservationItem } from "../../../../../hooks/api/reservations"
export const ReservationActions = ({ export const ReservationActions = ({
reservation, reservation,
}: { }: {
reservation: InventoryTypes.ReservationItemDTO reservation: HttpTypes.AdminReservation
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const prompt = usePrompt() const prompt = usePrompt()
@@ -1,10 +1,13 @@
import { useMemo } from "react" import { useMemo } from "react"
import { InventoryTypes } from "@medusajs/types" import { HttpTypes } from "@medusajs/types"
import { DataTable } from "../../../../../components/table/data-table" import { DataTable } from "../../../../../components/table/data-table"
import { useDataTable } from "../../../../../hooks/use-data-table" import { useDataTable } from "../../../../../hooks/use-data-table"
import { useReservationItems } from "../../../../../hooks/api/reservations" import { useReservationItems } from "../../../../../hooks/api/reservations"
import { useReservationTableColumn } from "./use-reservation-list-table-columns" import {
ExtendedReservationItem,
useReservationTableColumn,
} from "./use-reservation-list-table-columns"
import { useReservationsTableQuery } from "./use-reservation-list-table-query" import { useReservationsTableQuery } from "./use-reservation-list-table-query"
import { useStockLocations } from "../../../../../hooks/api" import { useStockLocations } from "../../../../../hooks/api"
@@ -13,7 +16,7 @@ const PAGE_SIZE = 20
export const ReservationItemTable = ({ export const ReservationItemTable = ({
inventoryItem, inventoryItem,
}: { }: {
inventoryItem: InventoryTypes.InventoryItemDTO inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"]
}) => { }) => {
const { searchParams, raw } = useReservationsTableQuery({ const { searchParams, raw } = useReservationsTableQuery({
pageSize: PAGE_SIZE, pageSize: PAGE_SIZE,
@@ -29,7 +32,7 @@ export const ReservationItemTable = ({
id: (reservations || []).map((r) => r.location_id), id: (reservations || []).map((r) => r.location_id),
}) })
const data = useMemo(() => { const data = useMemo<ExtendedReservationItem[]>(() => {
const locationMap = new Map((stock_locations || []).map((l) => [l.id, l])) const locationMap = new Map((stock_locations || []).map((l) => [l.id, l]))
return (reservations || []).map((r) => ({ return (reservations || []).map((r) => ({
@@ -45,7 +48,7 @@ export const ReservationItemTable = ({
columns, columns,
count, count,
enablePagination: true, enablePagination: true,
getRowId: (row: InventoryTypes.ReservationItemDTO) => row.id, getRowId: (row: ExtendedReservationItem) => row.id,
pageSize: PAGE_SIZE, pageSize: PAGE_SIZE,
}) })
@@ -1,19 +1,17 @@
import { InventoryTypes, StockLocationDTO } from "@medusajs/types" import { HttpTypes } from "@medusajs/types"
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell" import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
import { ReservationActions } from "./reservation-actions" import { ReservationActions } from "./reservation-actions"
import { createColumnHelper } from "@tanstack/react-table" import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react" import { useMemo } from "react"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { DateCell } from "../../../../../components/table/table-cells/common/date-cell"
import { CreatedAtCell } from "../../../../../components/table/table-cells/common/created-at-cell" import { CreatedAtCell } from "../../../../../components/table/table-cells/common/created-at-cell"
/** /**
* Adds missing properties to the InventoryItemDTO type. * Adds missing properties to the InventoryItemDTO type.
*/ */
interface ExtendedReservationItem extends InventoryTypes.ReservationItemDTO { export interface ExtendedReservationItem extends HttpTypes.AdminReservation {
line_item: { order_id: string } line_item?: { order_id: string }
location: StockLocationDTO location?: HttpTypes.AdminStockLocation
} }
const columnHelper = createColumnHelper<ExtendedReservationItem>() const columnHelper = createColumnHelper<ExtendedReservationItem>()
@@ -2,8 +2,6 @@ import { Trash } from "@medusajs/icons"
import { useMemo } from "react" import { useMemo } from "react"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import * as zod from "zod" import * as zod from "zod"
import { LineItem } from "@medusajs/medusa"
import { Input, Text } from "@medusajs/ui" import { Input, Text } from "@medusajs/ui"
import { UseFormReturn } from "react-hook-form" import { UseFormReturn } from "react-hook-form"
@@ -14,9 +12,10 @@ import { MoneyAmountCell } from "../../../../../components/table/table-cells/com
import { useProductVariant } from "../../../../../hooks/api/products.tsx" import { useProductVariant } from "../../../../../hooks/api/products.tsx"
import { getFulfillableQuantity } from "../../../../../lib/order-item.ts" import { getFulfillableQuantity } from "../../../../../lib/order-item.ts"
import { CreateFulfillmentSchema } from "./constants.ts" import { CreateFulfillmentSchema } from "./constants.ts"
import { HttpTypes } from "@medusajs/types"
type OrderEditItemProps = { type OrderEditItemProps = {
item: LineItem item: HttpTypes.AdminOrderLineItem
currencyCode: string currencyCode: string
locationId?: string locationId?: string
onItemRemove: (itemId: string) => void onItemRemove: (itemId: string) => void
@@ -33,8 +32,8 @@ export function OrderCreateFulfillmentItem({
const { t } = useTranslation() const { t } = useTranslation()
const { variant } = useProductVariant( const { variant } = useProductVariant(
item.variant.product_id, item.variant!.product_id!,
item.variant_id, item.variant_id!,
{ {
fields: "*inventory,*inventory.location_levels", fields: "*inventory,*inventory.location_levels",
} }
@@ -79,10 +78,10 @@ export function OrderCreateFulfillmentItem({
<Text className="txt-small" as="span" weight="plus"> <Text className="txt-small" as="span" weight="plus">
{item.title} {item.title}
</Text> </Text>
{item.variant.sku && <span>({item.variant.sku})</span>} {item.variant?.sku && <span>({item.variant.sku})</span>}
</div> </div>
<Text as="div" className="text-ui-fg-subtle txt-small"> <Text as="div" className="text-ui-fg-subtle txt-small">
{item.variant.title} {item.variant?.title ?? ""}
</Text> </Text>
</div> </div>
</div> </div>
@@ -1,13 +1,12 @@
import { Order } from "@medusajs/medusa"
import { Container, Heading } from "@medusajs/ui" import { Container, Heading } from "@medusajs/ui"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { ArrowPath, CurrencyDollar, Envelope, FlyingBox } from "@medusajs/icons" import { ArrowPath, CurrencyDollar, Envelope, FlyingBox } from "@medusajs/icons"
import { ActionMenu } from "../../../../../components/common/action-menu" import { ActionMenu } from "../../../../../components/common/action-menu"
import { CustomerInfo } from "../../../../../components/common/customer-info" import { CustomerInfo } from "../../../../../components/common/customer-info"
import { HttpTypes } from "@medusajs/types"
type OrderCustomerSectionProps = { type OrderCustomerSectionProps = {
order: Order order: HttpTypes.AdminOrder
} }
export const OrderCustomerSection = ({ order }: OrderCustomerSectionProps) => { export const OrderCustomerSection = ({ order }: OrderCustomerSectionProps) => {
@@ -1,5 +1,4 @@
import { XCircle } from "@medusajs/icons" import { XCircle } from "@medusajs/icons"
import { Order } from "@medusajs/medusa"
import { import {
Container, Container,
Copy, Copy,
@@ -16,9 +15,10 @@ import {
getOrderFulfillmentStatus, getOrderFulfillmentStatus,
getOrderPaymentStatus, getOrderPaymentStatus,
} from "../../../../../lib/order-helpers" } from "../../../../../lib/order-helpers"
import { HttpTypes } from "@medusajs/types"
type OrderGeneralSectionProps = { type OrderGeneralSectionProps = {
order: Order order: HttpTypes.AdminOrder
} }
export const OrderGeneralSection = ({ order }: OrderGeneralSectionProps) => { export const OrderGeneralSection = ({ order }: OrderGeneralSectionProps) => {
@@ -82,7 +82,7 @@ export const OrderGeneralSection = ({ order }: OrderGeneralSectionProps) => {
) )
} }
const FulfillmentBadge = ({ order }: { order: Order }) => { const FulfillmentBadge = ({ order }: { order: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { label, color } = getOrderFulfillmentStatus( const { label, color } = getOrderFulfillmentStatus(
@@ -97,7 +97,7 @@ const FulfillmentBadge = ({ order }: { order: Order }) => {
) )
} }
const PaymentBadge = ({ order }: { order: Order }) => { const PaymentBadge = ({ order }: { order: HttpTypes.AdminOrder }) => {
const { t } = useTranslation() const { t } = useTranslation()
/** /**
@@ -1,8 +1,4 @@
import { ArrowDownRightMini, DocumentText, XCircle } from "@medusajs/icons" import { ArrowDownRightMini, DocumentText, XCircle } from "@medusajs/icons"
import {
Payment as MedusaPayment,
Refund as MedusaRefund,
} from "@medusajs/medusa"
import { AdminPaymentCollection, HttpTypes } from "@medusajs/types" import { AdminPaymentCollection, HttpTypes } from "@medusajs/types"
import { import {
Badge, Badge,
@@ -44,7 +40,7 @@ export const OrderPaymentSection = ({ order }: OrderPaymentSectionProps) => {
const refunds = payments const refunds = payments
.map((payment) => payment?.refunds) .map((payment) => payment?.refunds)
.flat(1) .flat(1)
.filter(Boolean) .filter(Boolean) as HttpTypes.AdminRefund[]
return ( return (
<Container className="divide-y divide-dashed p-0"> <Container className="divide-y divide-dashed p-0">
@@ -122,7 +118,7 @@ const Refund = ({
<div className="flex items-center justify-end">{RefundReasonBadge}</div> <div className="flex items-center justify-end">{RefundReasonBadge}</div>
<div className="flex items-center justify-end"> <div className="flex items-center justify-end">
<Text size="small" leading="compact"> <Text size="small" leading="compact">
- {getLocaleAmount(refund.amount, currencyCode)} - {getLocaleAmount(refund.amount as number, currencyCode)}
</Text> </Text>
</div> </div>
</div> </div>
@@ -136,8 +132,8 @@ const Payment = ({
currencyCode, currencyCode,
}: { }: {
order: HttpTypes.AdminOrder order: HttpTypes.AdminOrder
payment: MedusaPayment payment: HttpTypes.AdminPayment
refunds: MedusaRefund[] refunds: HttpTypes.AdminRefund[]
currencyCode: string currencyCode: string
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@@ -148,7 +144,7 @@ const Payment = ({
const res = await prompt({ const res = await prompt({
title: t("orders.payment.capture"), title: t("orders.payment.capture"),
description: t("orders.payment.capturePayment", { description: t("orders.payment.capturePayment", {
amount: formatCurrency(payment.amount, currencyCode), amount: formatCurrency(payment.amount as number, currencyCode),
}), }),
confirmText: t("actions.confirm"), confirmText: t("actions.confirm"),
cancelText: t("actions.cancel"), cancelText: t("actions.cancel"),
@@ -160,12 +156,12 @@ const Payment = ({
} }
await mutateAsync( await mutateAsync(
{ amount: payment.amount }, { amount: payment.amount as number },
{ {
onSuccess: () => { onSuccess: () => {
toast.success( toast.success(
t("orders.payment.capturePaymentSuccess", { t("orders.payment.capturePaymentSuccess", {
amount: formatCurrency(payment.amount, currencyCode), amount: formatCurrency(payment.amount as number, currencyCode),
}) })
) )
}, },
@@ -197,7 +193,10 @@ const Payment = ({
{cleanId} {cleanId}
</Text> </Text>
<Text size="small" leading="compact"> <Text size="small" leading="compact">
{format(new Date(payment.created_at), "dd MMM, yyyy, HH:mm:ss")} {format(
new Date(payment.created_at as string),
"dd MMM, yyyy, HH:mm:ss"
)}
</Text> </Text>
</div> </div>
<div className="flex items-center justify-end"> <div className="flex items-center justify-end">
@@ -212,7 +211,7 @@ const Payment = ({
</div> </div>
<div className="flex items-center justify-end"> <div className="flex items-center justify-end">
<Text size="small" leading="compact"> <Text size="small" leading="compact">
{getLocaleAmount(payment.amount, payment.currency_code)} {getLocaleAmount(payment.amount as number, payment.currency_code)}
</Text> </Text>
</div> </div>
<ActionMenu <ActionMenu
@@ -260,8 +259,8 @@ const PaymentBreakdown = ({
currencyCode, currencyCode,
}: { }: {
order: HttpTypes.AdminOrder order: HttpTypes.AdminOrder
payments: MedusaPayment[] payments: HttpTypes.AdminPayment[]
refunds: MedusaRefund[] refunds: HttpTypes.AdminRefund[]
currencyCode: string currencyCode: string
}) => { }) => {
/** /**
@@ -271,7 +270,10 @@ const PaymentBreakdown = ({
const entries = [...orderRefunds, ...payments] const entries = [...orderRefunds, ...payments]
.sort((a, b) => { .sort((a, b) => {
return new Date(a.created_at).getTime() - new Date(b.created_at).getTime() return (
new Date(a.created_at as string).getTime() -
new Date(b.created_at as string).getTime()
)
}) })
.map((entry) => { .map((entry) => {
return { return {
@@ -279,8 +281,8 @@ const PaymentBreakdown = ({
type: entry.id.startsWith("pay_") ? "payment" : "refund", type: entry.id.startsWith("pay_") ? "payment" : "refund",
} }
}) as ( }) as (
| { type: "payment"; event: MedusaPayment } | { type: "payment"; event: HttpTypes.AdminPayment }
| { type: "refund"; event: MedusaRefund } | { type: "refund"; event: HttpTypes.AdminRefund }
)[] )[]
return ( return (
@@ -1,9 +1,9 @@
import { LoaderFunctionArgs } from "react-router-dom" import { LoaderFunctionArgs } from "react-router-dom"
import { HttpTypes } from "@medusajs/types"
import { ordersQueryKeys } from "../../../hooks/api/orders" import { ordersQueryKeys } from "../../../hooks/api/orders"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { OrderRes } from "../../../types/api-responses"
import { DEFAULT_FIELDS } from "./constants" import { DEFAULT_FIELDS } from "./constants"
const orderDetailQuery = (id: string) => ({ const orderDetailQuery = (id: string) => ({
@@ -19,7 +19,7 @@ export const orderLoader = async ({ params }: LoaderFunctionArgs) => {
const query = orderDetailQuery(id!) const query = orderDetailQuery(id!)
return ( return (
queryClient.getQueryData<OrderRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminOrderResponse>(query.queryKey) ??
(await queryClient.fetchQuery(query)) (await queryClient.fetchQuery(query))
) )
} }
@@ -1,8 +1,8 @@
import { HttpTypes } from "@medusajs/types"
import { LoaderFunctionArgs } from "react-router-dom" import { LoaderFunctionArgs } from "react-router-dom"
import { priceListsQueryKeys } from "../../../hooks/api/price-lists" import { priceListsQueryKeys } from "../../../hooks/api/price-lists"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { PriceListRes } from "../../../types/api-responses"
const pricingDetailQuery = (id: string) => ({ const pricingDetailQuery = (id: string) => ({
queryKey: priceListsQueryKeys.detail(id), queryKey: priceListsQueryKeys.detail(id),
@@ -14,7 +14,8 @@ export const pricingLoader = async ({ params }: LoaderFunctionArgs) => {
const query = pricingDetailQuery(id!) const query = pricingDetailQuery(id!)
return ( return (
queryClient.getQueryData<PriceListRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminPriceListResponse>(
(await queryClient.fetchQuery(query)) query.queryKey
) ?? (await queryClient.fetchQuery(query))
) )
} }
@@ -1,9 +1,9 @@
import { QueryClient } from "@tanstack/react-query" import { QueryClient } from "@tanstack/react-query"
import { HttpTypes } from "@medusajs/types"
import { productsQueryKeys } from "../../../hooks/api/products" import { productsQueryKeys } from "../../../hooks/api/products"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { ProductListRes } from "../../../types/api-responses"
const productsListQuery = () => ({ const productsListQuery = () => ({
queryKey: productsQueryKeys.list({ limit: 20, offset: 0 }), queryKey: productsQueryKeys.list({ limit: 20, offset: 0 }),
@@ -15,8 +15,9 @@ export const productsLoader = (client: QueryClient) => {
const query = productsListQuery() const query = productsListQuery()
return ( return (
queryClient.getQueryData<ProductListRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminProductListResponse>(
(await client.fetchQuery(query)) query.queryKey
) ?? (await client.fetchQuery(query))
) )
} }
} }
@@ -1,4 +1,3 @@
import { SalesChannel } from "@medusajs/medusa"
import { Button, Checkbox } from "@medusajs/ui" import { Button, Checkbox } from "@medusajs/ui"
import { RowSelectionState, createColumnHelper } from "@tanstack/react-table" import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
import { useEffect, useMemo, useState } from "react" import { useEffect, useMemo, useState } from "react"
@@ -153,7 +152,8 @@ export const EditSalesChannelsForm = ({
) )
} }
const columnHelper = createColumnHelper<SalesChannel>() const columnHelper =
createColumnHelper<HttpTypes.AdminSalesChannelResponse["sales_channel"]>()
const useColumns = () => { const useColumns = () => {
const columns = useSalesChannelTableColumns() const columns = useSalesChannelTableColumns()
@@ -1,8 +1,8 @@
import { HttpTypes } from "@medusajs/types"
import { LoaderFunctionArgs } from "react-router-dom" import { LoaderFunctionArgs } from "react-router-dom"
import { promotionsQueryKeys } from "../../../hooks/api/promotions" import { promotionsQueryKeys } from "../../../hooks/api/promotions"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { PromotionRes } from "../../../types/api-responses"
const promotionDetailQuery = (id: string) => ({ const promotionDetailQuery = (id: string) => ({
queryKey: promotionsQueryKeys.detail(id), queryKey: promotionsQueryKeys.detail(id),
@@ -14,7 +14,8 @@ export const promotionLoader = async ({ params }: LoaderFunctionArgs) => {
const query = promotionDetailQuery(id!) const query = promotionDetailQuery(id!)
return ( return (
queryClient.getQueryData<PromotionRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminPromotionResponse>(
(await queryClient.fetchQuery(query)) query.queryKey
) ?? (await queryClient.fetchQuery(query))
) )
} }
@@ -1,8 +1,8 @@
import { HttpTypes } from "@medusajs/types"
import { QueryClient } from "@tanstack/react-query" import { QueryClient } from "@tanstack/react-query"
import { promotionsQueryKeys } from "../../../hooks/api/promotions" import { promotionsQueryKeys } from "../../../hooks/api/promotions"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { PromotionListRes } from "../../../types/api-responses"
const params = { const params = {
limit: 20, limit: 20,
@@ -19,8 +19,9 @@ export const promotionsLoader = (client: QueryClient) => {
const query = promotionsListQuery() const query = promotionsListQuery()
return ( return (
queryClient.getQueryData<PromotionListRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminPromotionListResponse>(
(await client.fetchQuery(query)) query.queryKey
) ?? (await client.fetchQuery(query))
) )
} }
} }
@@ -7,7 +7,7 @@ import {
} from "../../../../../components/modals" } from "../../../../../components/modals"
import { zodResolver } from "@hookform/resolvers/zod" import { zodResolver } from "@hookform/resolvers/zod"
import { InventoryTypes } from "@medusajs/types" import { HttpTypes } from "@medusajs/types"
import React from "react" import React from "react"
import { useForm } from "react-hook-form" import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
@@ -16,7 +16,6 @@ import { Combobox } from "../../../../../components/inputs/combobox"
import { useInventoryItems } from "../../../../../hooks/api/inventory" import { useInventoryItems } from "../../../../../hooks/api/inventory"
import { useCreateReservationItem } from "../../../../../hooks/api/reservations" import { useCreateReservationItem } from "../../../../../hooks/api/reservations"
import { useStockLocations } from "../../../../../hooks/api/stock-locations" import { useStockLocations } from "../../../../../hooks/api/stock-locations"
import { InventoryItemRes } from "../../../../../types/api-responses"
export const CreateReservationSchema = zod.object({ export const CreateReservationSchema = zod.object({
inventory_item_id: zod.string().min(1), inventory_item_id: zod.string().min(1),
@@ -68,7 +67,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
const inventoryItemId = form.watch("inventory_item_id") const inventoryItemId = form.watch("inventory_item_id")
const selectedInventoryItem = inventory_items?.find( const selectedInventoryItem = inventory_items?.find(
(it) => it.id === inventoryItemId (it) => it.id === inventoryItemId
) as InventoryItemRes["inventory_item"] | undefined ) as HttpTypes.AdminInventoryItemResponse["inventory_item"] | undefined
const locationId = form.watch("location_id") const locationId = form.watch("location_id")
const selectedLocationLevel = selectedInventoryItem?.location_levels?.find( const selectedLocationLevel = selectedInventoryItem?.location_levels?.find(
@@ -81,7 +80,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
{ {
id: id:
selectedInventoryItem?.location_levels?.map( selectedInventoryItem?.location_levels?.map(
(level: InventoryTypes.InventoryLevelDTO) => level.location_id (level: HttpTypes.AdminInventoryLevel) => level.location_id
) ?? [], ) ?? [],
}, },
{ {
@@ -200,7 +199,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
<AttributeGridRow <AttributeGridRow
title={t("inventory.available")} title={t("inventory.available")}
value={ value={
selectedLocationLevel selectedLocationLevel?.available_quantity
? selectedLocationLevel.available_quantity - (quantity || 0) ? selectedLocationLevel.available_quantity - (quantity || 0)
: "-" : "-"
} }
@@ -222,7 +221,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
)} )}
min={1} min={1}
max={ max={
selectedLocationLevel selectedLocationLevel?.available_quantity
? selectedLocationLevel.available_quantity ? selectedLocationLevel.available_quantity
: 0 : 0
} }
@@ -1,6 +1,5 @@
import * as zod from "zod" import * as zod from "zod"
import { HttpTypes } from "@medusajs/types"
import { InventoryTypes, StockLocationDTO } from "@medusajs/types"
import { Button, Input, Select, Text, Textarea, toast } from "@medusajs/ui" import { Button, Input, Select, Text, Textarea, toast } from "@medusajs/ui"
import { RouteDrawer, useRouteModal } from "../../../../../../components/modals" import { RouteDrawer, useRouteModal } from "../../../../../../components/modals"
@@ -10,12 +9,11 @@ import { useTranslation } from "react-i18next"
import { z } from "zod" import { z } from "zod"
import { Form } from "../../../../../../components/common/form" import { Form } from "../../../../../../components/common/form"
import { useUpdateReservationItem } from "../../../../../../hooks/api/reservations" import { useUpdateReservationItem } from "../../../../../../hooks/api/reservations"
import { InventoryItemRes } from "../../../../../../types/api-responses"
type EditReservationFormProps = { type EditReservationFormProps = {
reservation: InventoryTypes.ReservationItemDTO reservation: HttpTypes.AdminReservationResponse["reservation"]
locations: StockLocationDTO[] locations: HttpTypes.AdminStockLocation[]
item: InventoryItemRes["inventory_item"] item: HttpTypes.AdminInventoryItemResponse["inventory_item"]
} }
const EditReservationSchema = z.object({ const EditReservationSchema = z.object({
@@ -43,7 +41,9 @@ const AttributeGridRow = ({
) )
} }
const getDefaultValues = (reservation: InventoryTypes.ReservationItemDTO) => { const getDefaultValues = (
reservation: HttpTypes.AdminReservationResponse["reservation"]
) => {
return { return {
quantity: reservation.quantity, quantity: reservation.quantity,
location_id: reservation.location_id, location_id: reservation.location_id,
@@ -82,8 +82,7 @@ export const EditReservationForm = ({
const locationId = form.watch("location_id") const locationId = form.watch("location_id")
const level = item.location_levels!.find( const level = item.location_levels!.find(
(level: InventoryTypes.InventoryLevelDTO) => (level: HttpTypes.AdminInventoryLevel) => level.location_id === locationId
level.location_id === locationId
) )
return ( return (
@@ -139,7 +138,7 @@ export const EditReservationForm = ({
title={t("inventory.available")} title={t("inventory.available")}
value={ value={
level!.stocked_quantity - level!.stocked_quantity -
(level.reserved_quantity - reservation.quantity) - (level!.reserved_quantity - reservation.quantity) -
reservedQuantity reservedQuantity
} }
/> />
@@ -157,7 +156,10 @@ export const EditReservationForm = ({
<Input <Input
type="number" type="number"
min={0} min={0}
max={level!.available_quantity + reservation.quantity} max={
(level!.available_quantity || 0) +
(reservation.quantity || 0)
}
value={value || ""} value={value || ""}
onChange={(e) => { onChange={(e) => {
const value = e.target.value const value = e.target.value
@@ -1,10 +1,10 @@
import { PencilSquare, Trash } from "@medusajs/icons" import { PencilSquare, Trash } from "@medusajs/icons"
import { ActionMenu } from "../../../../../components/common/action-menu" import { ActionMenu } from "../../../../../components/common/action-menu"
import { ExtendedReservationItem } from "@medusajs/medusa"
import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" import { useDeleteReservationItem } from "../../../../../hooks/api/reservations"
import { usePrompt } from "@medusajs/ui" import { usePrompt } from "@medusajs/ui"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { ExtendedReservationItem } from "../../../../inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns"
export const ReservationActions = ({ export const ReservationActions = ({
reservation, reservation,
@@ -1,4 +1,3 @@
import { ExtendedReservationItem } from "@medusajs/medusa"
import { createColumnHelper } from "@tanstack/react-table" import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react" import { useMemo } from "react"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
@@ -6,6 +5,7 @@ import { LinkButton } from "../../../../../components/common/link-button"
import { DateCell } from "../../../../../components/table/table-cells/common/date-cell" import { DateCell } from "../../../../../components/table/table-cells/common/date-cell"
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell" import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
import { ReservationActions } from "./reservation-actions" import { ReservationActions } from "./reservation-actions"
import { ExtendedReservationItem } from "../../../../inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns"
const columnHelper = createColumnHelper<ExtendedReservationItem>() const columnHelper = createColumnHelper<ExtendedReservationItem>()
@@ -1,9 +1,9 @@
import { LoaderFunctionArgs } from "react-router-dom" import { LoaderFunctionArgs } from "react-router-dom"
import { HttpTypes } from "@medusajs/types"
import { productsQueryKeys } from "../../../hooks/api/products" import { productsQueryKeys } from "../../../hooks/api/products"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { UserRes } from "../../../types/api-responses"
const userDetailQuery = (id: string) => ({ const userDetailQuery = (id: string) => ({
queryKey: productsQueryKeys.detail(id), queryKey: productsQueryKeys.detail(id),
@@ -15,7 +15,7 @@ export const userLoader = async ({ params }: LoaderFunctionArgs) => {
const query = userDetailQuery(id!) const query = userDetailQuery(id!)
return ( return (
queryClient.getQueryData<UserRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminUserResponse>(query.queryKey) ??
(await queryClient.fetchQuery(query)) (await queryClient.fetchQuery(query))
) )
} }
@@ -1,9 +1,9 @@
import { LoaderFunctionArgs } from "react-router-dom" import { LoaderFunctionArgs } from "react-router-dom"
import { HttpTypes } from "@medusajs/types"
import { workflowExecutionsQueryKeys } from "../../../hooks/api/workflow-executions" import { workflowExecutionsQueryKeys } from "../../../hooks/api/workflow-executions"
import { sdk } from "../../../lib/client" import { sdk } from "../../../lib/client"
import { queryClient } from "../../../lib/query-client" import { queryClient } from "../../../lib/query-client"
import { WorkflowExecutionRes } from "../../../types/api-responses"
const executionDetailQuery = (id: string) => ({ const executionDetailQuery = (id: string) => ({
queryKey: workflowExecutionsQueryKeys.detail(id), queryKey: workflowExecutionsQueryKeys.detail(id),
@@ -15,7 +15,8 @@ export const executionLoader = async ({ params }: LoaderFunctionArgs) => {
const query = executionDetailQuery(id!) const query = executionDetailQuery(id!)
return ( return (
queryClient.getQueryData<WorkflowExecutionRes>(query.queryKey) ?? queryClient.getQueryData<HttpTypes.AdminWorkflowExecutionResponse>(
(await queryClient.fetchQuery(query)) query.queryKey
) ?? (await queryClient.fetchQuery(query))
) )
} }
@@ -1,118 +0,0 @@
/**
* Temporary types for API payloads until we export them from `@medusajs/types`
*/
import {
CreateApiKeyDTO,
CreateCampaignDTO,
CreateFulfillmentSetDTO,
CreateInviteDTO,
CreatePriceListDTO,
CreatePromotionDTO,
CreatePromotionRuleDTO,
CreateSalesChannelDTO,
CreateServiceZoneDTO,
CreateShippingOptionDTO,
CreateShippingProfileDTO,
CreateStockLocationInput,
InventoryTypes,
UpdateApiKeyDTO,
UpdateCampaignDTO,
UpdatePriceListDTO,
UpdatePromotionDTO,
UpdatePromotionRuleDTO,
UpdateSalesChannelDTO,
UpdateServiceZoneDTO,
UpdateShippingOptionDTO,
UpdateStockLocationInput,
UpdateStoreDTO,
UpdateUserDTO,
} from "@medusajs/types"
// Auth
export type EmailPassReq = { email: string; password: string }
// Stores
export type UpdateStoreReq = UpdateStoreDTO
// API Keys
export type CreateApiKeyReq = CreateApiKeyDTO
export type UpdateApiKeyReq = UpdateApiKeyDTO
// Sales Channels
export type CreateSalesChannelReq = CreateSalesChannelDTO
export type UpdateSalesChannelReq = UpdateSalesChannelDTO
export type AddProductsSalesChannelReq = { product_ids: string[] }
export type RemoveProductsSalesChannelReq = { product_ids: string[] }
// Users
export type UpdateUserReq = Omit<UpdateUserDTO, "id">
// Invites
export type CreateInviteReq = CreateInviteDTO
// Stock Locations
export type CreateStockLocationReq = CreateStockLocationInput
export type UpdateStockLocationReq = UpdateStockLocationInput
export type UpdateStockLocationSalesChannelsReq = {
add?: string[]
remove?: string[]
}
export type CreateFulfillmentSetReq = CreateFulfillmentSetDTO
export type CreateServiceZoneReq = CreateServiceZoneDTO
export type UpdateServiceZoneReq =
| UpdateServiceZoneDTO
// Shipping Options
| { region_id: string; amount: number }
export type CreateShippingOptionReq = CreateShippingOptionDTO & {
/**
* The shipping option pricing
*/
prices: (
| { currency_code: string; amount: number }
| { region_id: string; amount: number }
)[]
}
export type UpdateShippingOptionReq = UpdateShippingOptionDTO & {
/**
* The shipping option pricing
*/
prices: (
| { currency_code: string; amount: number; id?: string }
| { region_id: string; amount: number; id?: string }
)[]
}
// Shipping Profile
export type CreateShippingProfileReq = CreateShippingProfileDTO
// Price Lists
export type CreatePriceListReq = CreatePriceListDTO
export type UpdatePriceListReq = Omit<UpdatePriceListDTO, "id">
export type AddPriceListPricesReq = {
prices: {
currency_code: string
amount: number
variant_id: string
}[]
}
export type DeletePriceListPricesReq = { ids: string[] }
// Promotion
export type CreatePromotionReq = CreatePromotionDTO
export type UpdatePromotionReq = Omit<UpdatePromotionDTO, "id">
export type BatchAddPromotionRulesReq = { rules: CreatePromotionRuleDTO[] }
export type BatchRemovePromotionRulesReq = { rule_ids: string[] }
export type BatchUpdatePromotionRulesReq = { rules: UpdatePromotionRuleDTO[] }
// Campaign
export type CreateCampaignReq = CreateCampaignDTO
export type UpdateCampaignReq = UpdateCampaignDTO
// Reservations
export type UpdateReservationReq = Omit<
InventoryTypes.UpdateReservationItemInput,
"id"
>
export type CreateReservationReq = InventoryTypes.CreateReservationItemInput
@@ -1,168 +0,0 @@
/**
* Temporary types for API responses until we export them from `@medusajs/types`
*/
import {
CampaignDTO,
CurrencyDTO,
CustomerGroupDTO,
FulfillmentDTO,
FulfillmentProviderDTO,
InventoryTypes,
InviteDTO,
OrderDTO,
PaymentProviderDTO,
PriceListDTO,
PromotionDTO,
PromotionRuleDTO,
SalesChannelDTO,
ShippingOptionDTO,
ShippingProfileDTO,
StockLocationAddressDTO,
StockLocationDTO,
StoreDTO,
UserDTO,
} from "@medusajs/types"
import { WorkflowExecutionDTO } from "../routes/workflow-executions/types"
type ListRes = {
count: number
offset: number
limit: number
}
type DeleteRes = {
id: string
object: string
deleted: true
}
// Auth
export type EmailPassRes = { token: string }
// Promotions
export type PromotionRes = { promotion: PromotionDTO }
export type PromotionListRes = { promotions: PromotionDTO[] } & ListRes
export type PromotionRuleAttributesListRes = { attributes: Record<any, any>[] }
export type PromotionRuleOperatorsListRes = { operators: Record<any, any>[] }
export type PromotionRuleValuesListRes = { values: Record<any, any>[] }
export type PromotionRulesListRes = { rules: PromotionRuleDTO[] }
export type PromotionDeleteRes = DeleteRes
// Users
export type UserRes = { user: UserDTO }
export type UserListRes = { users: UserDTO[] } & ListRes
export type UserDeleteRes = DeleteRes
// Stores
export type ExtendedStoreDTO = StoreDTO
export type StoreRes = { store: ExtendedStoreDTO }
export type StoreListRes = { stores: ExtendedStoreDTO[] } & ListRes
// Fulfillments
export type FulfillmentRes = { fulfillment: FulfillmentDTO }
export type FulfillmentListRes = { fulfillments: FulfillmentDTO[] } & ListRes
export type FulfillmentDeleteRes = DeleteRes
// Reservations
export type ReservationRes = { reservation: InventoryTypes.ReservationItemDTO }
export type ReservationListRes = {
reservations: InventoryTypes.ReservationItemDTO[]
} & ListRes
export type ReservationDeleteRes = DeleteRes
// Campaigns
export type CampaignRes = { campaign: CampaignDTO }
export type CampaignListRes = { campaigns: CampaignDTO[] } & ListRes
export type CampaignDeleteRes = DeleteRes
// API Keys
export type ApiKeyDeleteRes = DeleteRes
// Sales Channels
export type SalesChannelDeleteRes = DeleteRes
// Currencies
export type CurrencyRes = { currency: CurrencyDTO }
export type CurrencyListRes = { currencies: CurrencyDTO[] } & ListRes
// Invites
export type InviteRes = { invite: InviteDTO }
export type InviteListRes = { invites: InviteDTO[] } & ListRes
export type InviteDeleteRes = DeleteRes
// Orders
export type OrderRes = { order: OrderDTO }
export type OrderListRes = { orders: OrderDTO[] } & ListRes
// Payments
export type PaymentProvidersListRes = {
payment_providers: PaymentProviderDTO[]
}
// Stock Locations
export type ExtendedStockLocationDTO = StockLocationDTO & {
address: StockLocationAddressDTO | null
sales_channels: SalesChannelDTO[] | null
}
export type StockLocationRes = { stock_location: ExtendedStockLocationDTO }
export type StockLocationListRes = {
stock_locations: ExtendedStockLocationDTO[]
} & ListRes
export type StockLocationDeleteRes = DeleteRes
export type FulfillmentSetDeleteRes = DeleteRes
export type ServiceZoneDeleteRes = DeleteRes
// Fulfillment providers
export type FulfillmentProvidersListRes = {
fulfillment_providers: FulfillmentProviderDTO
} & ListRes
// Shipping options
export type ShippingOptionRes = { shipping_option: ShippingOptionDTO }
export type ShippingOptionDeleteRes = DeleteRes
export type ShippingOptionListRes = {
shipping_options: ShippingOptionDTO[]
} & ListRes
// Shipping profile
export type ShippingProfileRes = { shipping_profile: ShippingProfileDTO }
export type ShippingProfileListRes = {
shipping_profiles: ShippingProfileDTO[]
} & ListRes
export type ShippingProfileDeleteRes = DeleteRes
// Workflow Executions
export type WorkflowExecutionRes = { workflow_execution: WorkflowExecutionDTO }
export type WorkflowExecutionListRes = {
workflow_executions: WorkflowExecutionDTO[]
} & ListRes
// Taxes
export type TaxRegionDeleteRes = DeleteRes
export type TaxRateDeleteRes = DeleteRes
// Reservations
export type ReservationItemDeleteRes = DeleteRes
export type ReservationItemListRes = {
reservations: InventoryTypes.ReservationItemDTO[]
} & ListRes
export type ReservationItemRes = {
reservation: InventoryTypes.ReservationItemDTO
}
// Price Lists
export type PriceListRes = { price_list: PriceListDTO }
export type PriceListListRes = { price_lists: PriceListDTO[] } & ListRes
export type PriceListDeleteRes = DeleteRes
// Customer Groups
export type CustomerGroupRes = { customer_group: CustomerGroupDTO }
export type CustomerGroupListRes = {
customer_groups: CustomerGroupDTO[]
} & ListRes
export type CustomerGroupDeleteRes = DeleteRes
+3 -2
View File
@@ -1,3 +1,4 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client" import { Client } from "../client"
import { Config } from "../types" import { Config } from "../types"
@@ -13,7 +14,7 @@ export class Auth {
register = async ( register = async (
actor: "customer" | "user", actor: "customer" | "user",
method: "emailpass", method: "emailpass",
payload: { email: string; password: string } payload: HttpTypes.AdminSignUpWithEmailPassword
) => { ) => {
const { token } = await this.client.fetch<{ token: string }>( const { token } = await this.client.fetch<{ token: string }>(
`/auth/${actor}/${method}/register`, `/auth/${actor}/${method}/register`,
@@ -31,7 +32,7 @@ export class Auth {
login = async ( login = async (
actor: "customer" | "user", actor: "customer" | "user",
method: "emailpass", method: "emailpass",
payload: { email: string; password: string } payload: HttpTypes.AdminSignInWithEmailPassword
) => { ) => {
const { token } = await this.client.fetch<{ token: string }>( const { token } = await this.client.fetch<{ token: string }>(
`/auth/${actor}/${method}`, `/auth/${actor}/${method}`,
@@ -0,0 +1,17 @@
export interface BaseAddress {
id: string
customer_id?: string
first_name?: string
last_name?: string
phone?: string
company?: string
address_1?: string
address_2?: string
city?: string
country_code?: string
province?: string
postal_code?: string
metadata: Record<string, unknown> | null
created_at: Date | string
updated_at: Date | string
}
@@ -0,0 +1 @@
export * from "./entities"
@@ -0,0 +1 @@
export * from "./payloads"
@@ -0,0 +1,7 @@
export interface AdminSignUpWithEmailPassword {
email: string
password: string
}
export interface AdminSignInWithEmailPassword
extends AdminSignUpWithEmailPassword {}
@@ -1,5 +1,5 @@
import { OperatorMap } from "../../../dal" import { BaseFilterable, OperatorMap } from "../../../dal"
import { SelectParams } from "../../common" import { FindParams, SelectParams } from "../../common"
export interface AdminCustomerInGroupFilters { export interface AdminCustomerInGroupFilters {
id?: string | string[] id?: string | string[]
@@ -15,7 +15,9 @@ export interface AdminCustomerInGroupFilters {
deleted_at?: OperatorMap<string> deleted_at?: OperatorMap<string>
} }
export interface AdminGetCustomerGroupsParams { export interface AdminGetCustomerGroupsParams
extends FindParams,
BaseFilterable<AdminGetCustomerGroupsParams> {
limit?: number limit?: number
offset?: number offset?: number
q?: string q?: string
@@ -1,4 +1,5 @@
import { BaseFilterable, OperatorMap } from "../../dal" import { BaseFilterable, OperatorMap } from "../../dal"
import { FindParams } from "../common"
export interface BaseCustomerGroup { export interface BaseCustomerGroup {
id: string id: string
@@ -56,7 +57,8 @@ export interface CustomerGroupInCustomerFilters {
} }
export interface BaseCustomerFilters export interface BaseCustomerFilters
extends BaseFilterable<BaseCustomerFilters> { extends FindParams,
BaseFilterable<BaseCustomerFilters> {
q?: string q?: string
id?: string[] | string | OperatorMap<string | string[]> id?: string[] | string | OperatorMap<string | string[]>
email?: string[] | string | OperatorMap<string> email?: string[] | string | OperatorMap<string>
+2
View File
@@ -1,4 +1,6 @@
export * from "./address"
export * from "./api-key" export * from "./api-key"
export * from "./auth"
export * from "./campaign" export * from "./campaign"
export * from "./cart" export * from "./cart"
export * from "./claim" export * from "./claim"
@@ -14,4 +14,24 @@ export interface AdminInventoryItem {
description?: string | null description?: string | null
thumbnail?: string | null thumbnail?: string | null
metadata?: Record<string, unknown> | null metadata?: Record<string, unknown> | null
location_levels?: AdminInventoryLevel[]
}
export interface AdminInventoryLevel {
id: string
created_at: Date
updated_at: Date
deleted_at: Date | null
inventory_item_id: string
location_id: string
stocked_quantity: number
raw_stocked_quantity: Record<string, unknown>
reserved_quantity: number
raw_reserved_quantity: Record<string, unknown>
incoming_quantity: number
raw_incoming_quantity: Record<string, unknown>
metadata: Record<string, unknown> | null
inventory_item?: AdminInventoryItem
available_quantity: number | null
} }
@@ -1,4 +1,8 @@
import { AdminCustomer } from "../../customer"
import { AdminPaymentCollection } from "../../payment/admin" import { AdminPaymentCollection } from "../../payment/admin"
import { AdminProductVariant } from "../../product"
import { AdminRegionCountry } from "../../region"
import { AdminSalesChannel } from "../../sales-channel"
import { import {
BaseOrder, BaseOrder,
BaseOrderAddress, BaseOrderAddress,
@@ -12,15 +16,26 @@ import {
export interface AdminOrder extends BaseOrder { export interface AdminOrder extends BaseOrder {
payment_collections: AdminPaymentCollection[] payment_collections: AdminPaymentCollection[]
fulfillments?: BaseOrderFulfillment[] fulfillments?: BaseOrderFulfillment[]
sales_channel?: AdminSalesChannel
customer?: AdminCustomer
shipping_address?: AdminOrderAddress | null
billing_address?: AdminOrderAddress | null
} }
export interface AdminOrderLineItem extends BaseOrderLineItem {} export interface AdminOrderLineItem extends BaseOrderLineItem {
variant?: AdminProductVariant
}
export interface AdminOrderFulfillment extends BaseOrderFulfillment {} export interface AdminOrderFulfillment extends BaseOrderFulfillment {}
export interface AdminOrderLineItem extends BaseOrderLineItem {} export interface AdminOrderLineItem extends BaseOrderLineItem {}
export interface AdminOrderAddress extends BaseOrderAddress {}
export interface AdminOrderAddress extends BaseOrderAddress {
country?: AdminRegionCountry
}
export interface AdminOrderShippingMethod extends BaseOrderShippingMethod {} export interface AdminOrderShippingMethod extends BaseOrderShippingMethod {}
export interface AdminOrderPreview export interface AdminOrderPreview
extends Omit<AdminOrder, "items" | "shipping_methods"> { extends Omit<AdminOrder, "items" | "shipping_methods"> {
return_requested_total: number return_requested_total: number
@@ -1,7 +1,15 @@
import { BaseFilterable } from "../../../dal"; import { OperatorMap } from "../../../dal"
import { FindParams } from "../../common"; import { FindParams } from "../../common"
import { BaseOrderFilters } from "../common"
export interface AdminOrderFilters extends FindParams, BaseFilterable<AdminOrderFilters> { export interface AdminOrderFilters extends FindParams, BaseOrderFilters {
id?: string[] | string id?: string[] | string
name?: string[] | string name?: string[] | string
} sales_channel_id?: string[]
fulfillment_status?: string[]
payment_status?: string[]
region_id?: string[]
q?: string
created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
}
+7 -4
View File
@@ -1,6 +1,7 @@
import { BaseFilterable, OperatorMap } from "../../dal" import { BaseFilterable, OperatorMap } from "../../dal"
import { BigNumberValue } from "../../totals" import { BigNumberValue } from "../../totals"
import { BaseClaim } from "../claim/common" import { BaseClaim } from "../claim/common"
import { FindParams } from "../common"
import { BasePaymentCollection } from "../payment/common" import { BasePaymentCollection } from "../payment/common"
import { BaseProduct, BaseProductVariant } from "../product/common" import { BaseProduct, BaseProductVariant } from "../product/common"
@@ -264,9 +265,9 @@ export interface BaseOrder {
sales_channel_id: string | null sales_channel_id: string | null
email: string | null email: string | null
currency_code: string currency_code: string
display_id?: string display_id?: number
shipping_address?: BaseOrderAddress shipping_address?: BaseOrderAddress | null
billing_address?: BaseOrderAddress billing_address?: BaseOrderAddress | null
items: BaseOrderLineItem[] | null items: BaseOrderLineItem[] | null
shipping_methods: BaseOrderShippingMethod[] | null shipping_methods: BaseOrderShippingMethod[] | null
payment_collections?: BasePaymentCollection[] payment_collections?: BasePaymentCollection[]
@@ -302,7 +303,9 @@ export interface BaseOrder {
original_shipping_tax_total: number original_shipping_tax_total: number
} }
export interface BaseOrderFilters extends BaseFilterable<BaseOrderFilters> { export interface BaseOrderFilters
extends FindParams,
BaseFilterable<BaseOrderFilters> {
id?: string[] | string | OperatorMap<string | string[]> id?: string[] | string | OperatorMap<string | string[]>
status?: string[] | string | OperatorMap<string | string[]> status?: string[] | string | OperatorMap<string | string[]>
} }
@@ -2,7 +2,7 @@ export interface AdminReservation {
id: string id: string
line_item_id: string | null line_item_id: string | null
location_id: string location_id: string
quantity: string quantity: number
external_id: string | null external_id: string | null
description: string | null description: string | null
inventory_item_id: string inventory_item_id: string
@@ -6,6 +6,8 @@ export interface AdminShippingOptionListParams extends FindParams {
q?: string q?: string
service_zone_id?: string | string[] service_zone_id?: string | string[]
stock_location_id?: string | string[] stock_location_id?: string | string[]
is_return?: boolean
admin_only?: boolean
shipping_profile_id?: string | string[] shipping_profile_id?: string | string[]
provider_id?: string | string[] provider_id?: string | string[]
shipping_option_type_id?: string | string[] shipping_option_type_id?: string | string[]
@@ -3,6 +3,7 @@ import {
ShippingOptionPriceType as ShippingOptionPriceTypeEnum, ShippingOptionPriceType as ShippingOptionPriceTypeEnum,
} from "@medusajs/utils" } from "@medusajs/utils"
import { z } from "zod" import { z } from "zod"
import { booleanString } from "../../utils/common-validators"
import { import {
createFindParams, createFindParams,
createOperatorMap, createOperatorMap,
@@ -28,6 +29,8 @@ export const AdminGetShippingOptionsParams = createFindParams({
shipping_profile_id: z.union([z.string(), z.array(z.string())]).optional(), shipping_profile_id: z.union([z.string(), z.array(z.string())]).optional(),
provider_id: z.union([z.string(), z.array(z.string())]).optional(), provider_id: z.union([z.string(), z.array(z.string())]).optional(),
stock_location_id: z.union([z.string(), z.array(z.string())]).optional(), stock_location_id: z.union([z.string(), z.array(z.string())]).optional(),
is_return: booleanString().optional(),
admin_only: booleanString().optional(),
shipping_option_type_id: z shipping_option_type_id: z
.union([z.string(), z.array(z.string())]) .union([z.string(), z.array(z.string())])
.optional(), .optional(),