From 4350fe5368c78af2d9e2216bb35d0d86ab4b7ba4 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:37:44 +0200 Subject: [PATCH] chore: Remove `@medusajs/medusa` usage + local types from dashboard (#8883) Closes CC-403 --- packages/admin-next/dashboard/package.json | 2 +- .../common/customer-info/customer-info.tsx | 22 +-- .../forms/address-form/address-form.tsx | 4 +- .../transfer-ownership-form.tsx | 21 ++- .../order/country-cell/country-cell.tsx | 10 +- .../order/customer-cell/customer-cell.tsx | 8 +- .../sales-channel-cell/sales-channel-cell.tsx | 4 +- .../fulfillment-providers-cell.tsx | 4 +- .../subtotal-requirement-cell/index.ts | 1 - .../subtotal-requirement-cell.tsx | 43 ----- .../dashboard/src/hooks/api/auth.tsx | 15 +- .../src/hooks/table/columns/index.ts | 2 +- .../table/columns/use-order-table-columns.tsx | 18 +- .../use-shipping-option-table-columns.tsx | 107 ----------- .../query-v2/use-promotion-table-query.tsx | 4 +- .../query/use-customer-group-table-query.tsx | 5 +- .../table/query/use-customer-table-query.tsx | 4 +- .../table/query/use-order-table-query.tsx | 4 +- .../query/use-shipping-option-table-query.tsx | 7 +- .../table/query/use-tax-rate-table-query.tsx | 4 +- .../admin-next/dashboard/src/lib/addresses.ts | 11 +- .../providers/router-provider/route-map.tsx | 4 +- .../customer-order-section.tsx | 8 +- ...transfer-customer-order-ownership-form.tsx | 11 +- .../inventory-item-location-levels.tsx | 5 +- .../inventory-item-reservations.tsx | 5 +- .../reservation-actions.tsx | 4 +- .../reservation-list-table.tsx | 13 +- .../use-reservation-list-table-columns.tsx | 10 +- .../order-create-fulfillment-item.tsx | 13 +- .../order-customer-section.tsx | 5 +- .../order-general-section.tsx | 8 +- .../order-payment-section.tsx | 38 ++-- .../src/routes/orders/order-detail/loader.ts | 4 +- .../price-lists/price-list-detail/loader.ts | 7 +- .../routes/products/product-list/loader.ts | 7 +- .../edit-sales-channels-form.tsx | 4 +- .../promotions/promotion-detail/loader.ts | 7 +- .../promotions/promotion-list/loader.ts | 7 +- .../reservation-create-from.tsx | 11 +- .../components/edit-reservation-form.tsx | 24 +-- .../reservation-actions.tsx | 2 +- .../use-reservation-table-columns.tsx | 2 +- .../src/routes/users/user-detail/loader.ts | 4 +- .../workflow-execution-detail/loader.ts | 7 +- .../dashboard/src/types/api-payloads.ts | 118 ------------ .../dashboard/src/types/api-responses.ts | 168 ------------------ packages/core/js-sdk/src/auth/index.ts | 5 +- .../core/types/src/http/address/entities.ts | 17 ++ packages/core/types/src/http/address/index.ts | 1 + packages/core/types/src/http/auth/index.ts | 1 + packages/core/types/src/http/auth/payloads.ts | 7 + .../src/http/customer-group/admin/queries.ts | 8 +- .../core/types/src/http/customer/common.ts | 4 +- packages/core/types/src/http/index.ts | 2 + .../src/http/inventory/admin/entities.ts | 20 +++ .../types/src/http/order/admin/entities.ts | 19 +- .../types/src/http/order/admin/queries.ts | 16 +- packages/core/types/src/http/order/common.ts | 11 +- .../src/http/reservation/admin/entities.ts | 2 +- .../src/http/shipping-option/admin/queries.ts | 2 + .../api/admin/shipping-options/validators.ts | 3 + 62 files changed, 296 insertions(+), 618 deletions(-) delete mode 100644 packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/index.ts delete mode 100644 packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/subtotal-requirement-cell.tsx delete mode 100644 packages/admin-next/dashboard/src/hooks/table/columns/use-shipping-option-table-columns.tsx delete mode 100644 packages/admin-next/dashboard/src/types/api-payloads.ts delete mode 100644 packages/admin-next/dashboard/src/types/api-responses.ts create mode 100644 packages/core/types/src/http/address/entities.ts create mode 100644 packages/core/types/src/http/address/index.ts create mode 100644 packages/core/types/src/http/auth/index.ts create mode 100644 packages/core/types/src/http/auth/payloads.ts diff --git a/packages/admin-next/dashboard/package.json b/packages/admin-next/dashboard/package.json index 994abb09c5..9dfc0ac39f 100644 --- a/packages/admin-next/dashboard/package.json +++ b/packages/admin-next/dashboard/package.json @@ -2,7 +2,7 @@ "name": "@medusajs/dashboard", "version": "0.0.1", "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", "build": "tsup && node ./scripts/generate-types.js", "build:preview": "vite build", diff --git a/packages/admin-next/dashboard/src/components/common/customer-info/customer-info.tsx b/packages/admin-next/dashboard/src/components/common/customer-info/customer-info.tsx index d51be3704a..33596131b4 100644 --- a/packages/admin-next/dashboard/src/components/common/customer-info/customer-info.tsx +++ b/packages/admin-next/dashboard/src/components/common/customer-info/customer-info.tsx @@ -1,16 +1,16 @@ -import { Address, Cart, Order } from "@medusajs/medusa" import { Avatar, Copy, Text } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { Link } from "react-router-dom" +import { HttpTypes } from "@medusajs/types" import { getFormattedAddress, isSameAddress } from "../../../lib/addresses" -const ID = ({ data }: { data: Cart | Order }) => { +const ID = ({ data }: { data: HttpTypes.AdminOrder }) => { const { t } = useTranslation() const id = data.customer_id - const name = getCartOrOrderCustomer(data) + const name = getOrderCustomer(data) const email = data.email - const fallback = (name || email).charAt(0).toUpperCase() + const fallback = (name || email || "").charAt(0).toUpperCase() return (
@@ -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 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 phone = data.shipping_address?.phone || data.billing_address?.phone - const email = data.email + const email = data.email || "" return (
@@ -106,7 +106,9 @@ const AddressPrint = ({ address, type, }: { - address: Address | null + address: + | HttpTypes.AdminOrder["shipping_address"] + | HttpTypes.AdminOrder["billing_address"] type: "shipping" | "billing" }) => { const { t } = useTranslation() @@ -146,7 +148,7 @@ const AddressPrint = ({ ) } -const Addresses = ({ data }: { data: Cart | Order }) => { +const Addresses = ({ data }: { data: HttpTypes.AdminOrder }) => { const { t } = useTranslation() 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 } = obj.shipping_address || {} const { first_name: bFirstName, last_name: bLastName } = diff --git a/packages/admin-next/dashboard/src/components/forms/address-form/address-form.tsx b/packages/admin-next/dashboard/src/components/forms/address-form/address-form.tsx index eb73da67e6..5485882289 100644 --- a/packages/admin-next/dashboard/src/components/forms/address-form/address-form.tsx +++ b/packages/admin-next/dashboard/src/components/forms/address-form/address-form.tsx @@ -1,4 +1,3 @@ -import { Country } from "@medusajs/medusa" import { Heading, Input, Select, clx } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { z } from "zod" @@ -7,12 +6,13 @@ import { Control } from "react-hook-form" import { AddressSchema } from "../../../lib/schemas" import { Form } from "../../common/form" import { CountrySelect } from "../../inputs/country-select" +import { HttpTypes } from "@medusajs/types" type AddressFieldValues = z.infer type AddressFormProps = { control: Control - countries?: Country[] + countries?: HttpTypes.AdminRegionCountry[] layout: "grid" | "stack" } diff --git a/packages/admin-next/dashboard/src/components/forms/transfer-ownership-form/transfer-ownership-form.tsx b/packages/admin-next/dashboard/src/components/forms/transfer-ownership-form/transfer-ownership-form.tsx index da2a5aba4b..7c76549c0a 100644 --- a/packages/admin-next/dashboard/src/components/forms/transfer-ownership-form/transfer-ownership-form.tsx +++ b/packages/admin-next/dashboard/src/components/forms/transfer-ownership-form/transfer-ownership-form.tsx @@ -1,4 +1,3 @@ -import { Customer, DraftOrder, Order } from "@medusajs/medusa" import { Select, Text, clx } from "@medusajs/ui" import { useInfiniteQuery } from "@tanstack/react-query" import { format } from "date-fns" @@ -19,6 +18,7 @@ import { TransferOwnershipSchema } from "../../../lib/schemas" import { Form } from "../../common/form" import { Skeleton } from "../../common/skeleton" import { Combobox } from "../../inputs/combobox" +import { HttpTypes } from "@medusajs/types" type TransferOwnerShipFieldValues = z.infer @@ -26,14 +26,16 @@ type TransferOwnerShipFormProps = { /** * The Order or DraftOrder to transfer ownership of. */ - order: Order | DraftOrder + order: HttpTypes.AdminOrder /** * React Hook Form control object. */ control: Control } -const isOrder = (order: Order | DraftOrder): order is Order => { +const isOrder = ( + order: HttpTypes.AdminOrder +): order is HttpTypes.AdminOrder => { return "customer" in order } @@ -90,7 +92,7 @@ export const TransferOwnerShipForm = ({ }, }) - const createLabel = (customer?: Customer) => { + const createLabel = (customer?: HttpTypes.AdminCustomer) => { if (!customer) { return "" } @@ -187,7 +189,7 @@ export const TransferOwnerShipForm = ({ ) } -const OrderDetailsTable = ({ order }: { order: Order }) => { +const OrderDetailsTable = ({ order }: { order: HttpTypes.AdminOrder }) => { const { t } = useTranslation() 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() return ( @@ -219,10 +222,12 @@ const DraftOrderDetailsTable = ({ draft }: { draft: DraftOrder }) => { label={t("fields.status")} value={t(`draftOrders.status.${draft.status}`)} /> - + /> */} ) } diff --git a/packages/admin-next/dashboard/src/components/table/table-cells/order/country-cell/country-cell.tsx b/packages/admin-next/dashboard/src/components/table/table-cells/order/country-cell/country-cell.tsx index 33114a4793..e25d14f456 100644 --- a/packages/admin-next/dashboard/src/components/table/table-cells/order/country-cell/country-cell.tsx +++ b/packages/admin-next/dashboard/src/components/table/table-cells/order/country-cell/country-cell.tsx @@ -1,9 +1,13 @@ -import { Country } from "@medusajs/medusa" import { Tooltip } from "@medusajs/ui" import ReactCountryFlag from "react-country-flag" 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) { return } @@ -13,7 +17,7 @@ export const CountryCell = ({ country }: { country?: Country | null }) => {
{ +export const CustomerCell = ({ + customer, +}: { + customer: HttpTypes.AdminCustomer | null +}) => { if (!customer) { return - } diff --git a/packages/admin-next/dashboard/src/components/table/table-cells/order/sales-channel-cell/sales-channel-cell.tsx b/packages/admin-next/dashboard/src/components/table/table-cells/order/sales-channel-cell/sales-channel-cell.tsx index 17e249d041..c451cb12b2 100644 --- a/packages/admin-next/dashboard/src/components/table/table-cells/order/sales-channel-cell/sales-channel-cell.tsx +++ b/packages/admin-next/dashboard/src/components/table/table-cells/order/sales-channel-cell/sales-channel-cell.tsx @@ -1,10 +1,10 @@ -import { SalesChannel } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useTranslation } from "react-i18next" export const SalesChannelCell = ({ channel, }: { - channel: SalesChannel | null + channel: HttpTypes.AdminSalesChannel | null }) => { if (!channel) { return - diff --git a/packages/admin-next/dashboard/src/components/table/table-cells/region/fulfillment-providers-cell/fulfillment-providers-cell.tsx b/packages/admin-next/dashboard/src/components/table/table-cells/region/fulfillment-providers-cell/fulfillment-providers-cell.tsx index 6f95a396e5..8ac650ac62 100644 --- a/packages/admin-next/dashboard/src/components/table/table-cells/region/fulfillment-providers-cell/fulfillment-providers-cell.tsx +++ b/packages/admin-next/dashboard/src/components/table/table-cells/region/fulfillment-providers-cell/fulfillment-providers-cell.tsx @@ -1,10 +1,10 @@ -import { FulfillmentProvider } from "@medusajs/medusa" import { useTranslation } from "react-i18next" import { formatProvider } from "../../../../../lib/format-provider" import { PlaceholderCell } from "../../common/placeholder-cell" +import { HttpTypes } from "@medusajs/types" type FulfillmentProvidersCellProps = { - fulfillmentProviders?: FulfillmentProvider[] | null + fulfillmentProviders?: HttpTypes.AdminFulfillmentProvider[] | null } export const FulfillmentProvidersCell = ({ diff --git a/packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/index.ts b/packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/index.ts deleted file mode 100644 index 8ee08b37d7..0000000000 --- a/packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./subtotal-requirement-cell" diff --git a/packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/subtotal-requirement-cell.tsx b/packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/subtotal-requirement-cell.tsx deleted file mode 100644 index d9a5733bfa..0000000000 --- a/packages/admin-next/dashboard/src/components/table/table-cells/shipping-option/subtotal-requirement-cell/subtotal-requirement-cell.tsx +++ /dev/null @@ -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 - } - - return ( - - ) -} - -export const SubtotalRequirementHeader = ({ type }: { type: SubtotalType }) => { - const { t } = useTranslation() - - const header = - type === "min" ? t("fields.minSubtotal") : t("fields.maxSubtotal") - - return ( -
- {header} -
- ) -} diff --git a/packages/admin-next/dashboard/src/hooks/api/auth.tsx b/packages/admin-next/dashboard/src/hooks/api/auth.tsx index b994c32f72..7bbcba2d1c 100644 --- a/packages/admin-next/dashboard/src/hooks/api/auth.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/auth.tsx @@ -1,11 +1,14 @@ import { UseMutationOptions, useMutation } from "@tanstack/react-query" import { FetchError } from "@medusajs/js-sdk" - import { sdk } from "../../lib/client" -import { EmailPassReq } from "../../types/api-payloads" +import { HttpTypes } from "@medusajs/types" export const useSignInWithEmailPassword = ( - options?: UseMutationOptions + options?: UseMutationOptions< + string, + FetchError, + HttpTypes.AdminSignUpWithEmailPassword + > ) => { return useMutation({ mutationFn: (payload) => sdk.auth.login("user", "emailpass", payload), @@ -17,7 +20,11 @@ export const useSignInWithEmailPassword = ( } export const useSignUpWithEmailPass = ( - options?: UseMutationOptions + options?: UseMutationOptions< + string, + FetchError, + HttpTypes.AdminSignInWithEmailPassword + > ) => { return useMutation({ mutationFn: (payload) => sdk.auth.register("user", "emailpass", payload), diff --git a/packages/admin-next/dashboard/src/hooks/table/columns/index.ts b/packages/admin-next/dashboard/src/hooks/table/columns/index.ts index 869b6e3850..5e367512d1 100644 --- a/packages/admin-next/dashboard/src/hooks/table/columns/index.ts +++ b/packages/admin-next/dashboard/src/hooks/table/columns/index.ts @@ -9,5 +9,5 @@ export * from "./use-product-type-table-columns" export * from "./use-region-table-columns" export * from "./use-return-reason-table-columns" export * from "./use-sales-channel-table-columns" -export * from "./use-shipping-option-table-columns" export * from "./use-tax-rates-table-columns" + diff --git a/packages/admin-next/dashboard/src/hooks/table/columns/use-order-table-columns.tsx b/packages/admin-next/dashboard/src/hooks/table/columns/use-order-table-columns.tsx index 50ca39028f..e28ced6cab 100644 --- a/packages/admin-next/dashboard/src/hooks/table/columns/use-order-table-columns.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/columns/use-order-table-columns.tsx @@ -1,4 +1,3 @@ -import { Order } from "@medusajs/medusa" import { ColumnDef, ColumnDefBase, @@ -34,9 +33,10 @@ import { TotalCell, TotalHeader, } 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 -const columnHelper = createColumnHelper() +const columnHelper = createColumnHelper() type UseOrderTableColumnsProps = { exclude?: string[] @@ -52,7 +52,7 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => { cell: ({ getValue }) => { const id = getValue() - return + return }, }), columnHelper.accessor("created_at", { @@ -118,17 +118,19 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => { const isAccessorColumnDef = ( c: any - ): c is ColumnDef & { accessorKey: string } => { + ): c is ColumnDef & { accessorKey: string } => { return c.accessorKey !== undefined } const isDisplayColumnDef = ( c: any - ): c is ColumnDef & { id: string } => { + ): c is ColumnDef & { id: string } => { return c.id !== undefined } - const shouldExclude = >(c: TDef) => { + const shouldExclude = >( + c: TDef + ) => { if (isAccessorColumnDef(c)) { return exclude.includes(c.accessorKey) } else if (isDisplayColumnDef(c)) { @@ -138,5 +140,7 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => { return false } - return columns.filter((c) => !shouldExclude(c)) as ColumnDef[] + return columns.filter( + (c) => !shouldExclude(c) + ) as ColumnDef[] } diff --git a/packages/admin-next/dashboard/src/hooks/table/columns/use-shipping-option-table-columns.tsx b/packages/admin-next/dashboard/src/hooks/table/columns/use-shipping-option-table-columns.tsx deleted file mode 100644 index 53085e90aa..0000000000 --- a/packages/admin-next/dashboard/src/hooks/table/columns/use-shipping-option-table-columns.tsx +++ /dev/null @@ -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() - -export const useShippingOptionTableColumns = () => { - return useMemo( - () => [ - columnHelper.accessor("name", { - header: () => , - cell: ({ getValue }) => , - }), - columnHelper.accessor("is_return", { - header: () => , - cell: (cell) => { - const value = cell.getValue() - - return - }, - }), - columnHelper.accessor("price_type", { - header: () => , - cell: ({ getValue }) => { - const type = getValue() - - return - }, - }), - columnHelper.accessor("price_incl_tax", { - header: () => , - cell: ({ getValue, row }) => { - const isCalculated = row.original.price_type === "calculated" - const amount = getValue() - const currencyCode = row.original.region!.currency_code - - return ( - - ) - }, - }), - columnHelper.display({ - id: "min_amount", - header: () => , - cell: ({ row }) => { - return ( - - ) - }, - }), - columnHelper.display({ - id: "max_amount", - header: () => , - cell: ({ row }) => { - return ( - - ) - }, - }), - columnHelper.accessor("admin_only", { - header: () => , - cell: (cell) => { - const value = cell.getValue() || false - - return - }, - }), - ], - [] - ) -} diff --git a/packages/admin-next/dashboard/src/hooks/table/query-v2/use-promotion-table-query.tsx b/packages/admin-next/dashboard/src/hooks/table/query-v2/use-promotion-table-query.tsx index ae2b68b01f..cf586da801 100644 --- a/packages/admin-next/dashboard/src/hooks/table/query-v2/use-promotion-table-query.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/query-v2/use-promotion-table-query.tsx @@ -1,4 +1,4 @@ -import { AdminGetPromotionsParams } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../use-query-params" type UsePromotionTableQueryProps = { @@ -17,7 +17,7 @@ export const usePromotionTableQuery = ({ const { offset, q, created_at, updated_at } = queryObject - const searchParams: AdminGetPromotionsParams = { + const searchParams: HttpTypes.AdminGetPromotionsParams = { limit: pageSize, created_at: created_at ? JSON.parse(created_at) : undefined, updated_at: updated_at ? JSON.parse(updated_at) : undefined, diff --git a/packages/admin-next/dashboard/src/hooks/table/query/use-customer-group-table-query.tsx b/packages/admin-next/dashboard/src/hooks/table/query/use-customer-group-table-query.tsx index 46fd056783..62d3471d5b 100644 --- a/packages/admin-next/dashboard/src/hooks/table/query/use-customer-group-table-query.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/query/use-customer-group-table-query.tsx @@ -1,5 +1,4 @@ -import { AdminGetCustomerGroupsParams } from "@medusajs/medusa" - +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../use-query-params" type UseCustomerGroupTableQueryProps = { @@ -18,7 +17,7 @@ export const useCustomerGroupTableQuery = ({ const { offset, created_at, updated_at, q, order } = queryObject - const searchParams: AdminGetCustomerGroupsParams = { + const searchParams: HttpTypes.AdminGetCustomerGroupsParams = { limit: pageSize, offset: offset ? Number(offset) : 0, order, diff --git a/packages/admin-next/dashboard/src/hooks/table/query/use-customer-table-query.tsx b/packages/admin-next/dashboard/src/hooks/table/query/use-customer-table-query.tsx index c396dbfebe..c925c6060a 100644 --- a/packages/admin-next/dashboard/src/hooks/table/query/use-customer-table-query.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/query/use-customer-table-query.tsx @@ -1,4 +1,4 @@ -import { AdminGetCustomersParams } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../use-query-params" type UseCustomerTableQueryProps = { @@ -26,7 +26,7 @@ export const useCustomerTableQuery = ({ const { offset, groups, created_at, updated_at, has_account, q, order } = queryObject - const searchParams: AdminGetCustomersParams = { + const searchParams: HttpTypes.AdminCustomerFilters = { limit: pageSize, offset: offset ? Number(offset) : 0, groups: groups?.split(","), diff --git a/packages/admin-next/dashboard/src/hooks/table/query/use-order-table-query.tsx b/packages/admin-next/dashboard/src/hooks/table/query/use-order-table-query.tsx index 41913557b9..ab8f0ed6fa 100644 --- a/packages/admin-next/dashboard/src/hooks/table/query/use-order-table-query.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/query/use-order-table-query.tsx @@ -1,4 +1,4 @@ -import { AdminGetOrdersParams } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../use-query-params" type UseOrderTableQueryProps = { @@ -37,7 +37,7 @@ export const useOrderTableQuery = ({ order, } = queryObject - const searchParams: AdminGetOrdersParams = { + const searchParams: HttpTypes.AdminOrderFilters = { limit: pageSize, offset: offset ? Number(offset) : 0, sales_channel_id: sales_channel_id?.split(","), diff --git a/packages/admin-next/dashboard/src/hooks/table/query/use-shipping-option-table-query.tsx b/packages/admin-next/dashboard/src/hooks/table/query/use-shipping-option-table-query.tsx index d3fd484471..3be4d0baab 100644 --- a/packages/admin-next/dashboard/src/hooks/table/query/use-shipping-option-table-query.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/query/use-shipping-option-table-query.tsx @@ -1,4 +1,4 @@ -import { AdminGetShippingOptionsParams } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../use-query-params" type UseShippingOptionTableQueryProps = { @@ -29,10 +29,11 @@ export const useShippingOptionTableQuery = ({ const { offset, order, q, admin_only, is_return, created_at, updated_at } = queryObject - const searchParams: AdminGetShippingOptionsParams = { + const searchParams: HttpTypes.AdminShippingOptionListParams = { limit: pageSize, 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, admin_only: admin_only ? admin_only === "true" : undefined, q, diff --git a/packages/admin-next/dashboard/src/hooks/table/query/use-tax-rate-table-query.tsx b/packages/admin-next/dashboard/src/hooks/table/query/use-tax-rate-table-query.tsx index 04fa145750..4b2c69214e 100644 --- a/packages/admin-next/dashboard/src/hooks/table/query/use-tax-rate-table-query.tsx +++ b/packages/admin-next/dashboard/src/hooks/table/query/use-tax-rate-table-query.tsx @@ -1,4 +1,4 @@ -import { AdminGetTaxRatesParams } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../use-query-params" type UseTaxRateTableQueryProps = { @@ -17,7 +17,7 @@ export const useTaxRateTableQuery = ({ const { offset, q, order, created_at, updated_at } = queryObject - const searchParams: AdminGetTaxRatesParams = { + const searchParams: HttpTypes.AdminTaxRateListParams = { limit: pageSize, offset: offset ? Number(offset) : 0, order, diff --git a/packages/admin-next/dashboard/src/lib/addresses.ts b/packages/admin-next/dashboard/src/lib/addresses.ts index c9177371c2..3c4b233996 100644 --- a/packages/admin-next/dashboard/src/lib/addresses.ts +++ b/packages/admin-next/dashboard/src/lib/addresses.ts @@ -1,8 +1,11 @@ -import { AddressDTO } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" 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) { return false } @@ -22,7 +25,7 @@ export const isSameAddress = (a: AddressDTO | null, b: AddressDTO | null) => { export const getFormattedAddress = ({ address, }: { - address?: Partial | null + address?: HttpTypes.AdminOrderAddress | null }) => { if (!address) { return [] @@ -70,7 +73,7 @@ export const getFormattedAddress = ({ } if (country) { - formattedAddress.push(country.display_name) + formattedAddress.push(country.display_name!) } else if (country_code) { const country = getCountryByIso2(country_code) diff --git a/packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx b/packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx index 9ceecb26e9..2c88205073 100644 --- a/packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx +++ b/packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx @@ -9,7 +9,6 @@ import { ProtectedRoute } from "../../components/authentication/protected-route" import { MainLayout } from "../../components/layout/main-layout" import { SettingsLayout } from "../../components/layout/settings-layout" import { ErrorBoundary } from "../../components/utilities/error-boundary" -import { PriceListRes } from "../../types/api-responses" import { getCountryByIso2 } from "../../lib/data/countries" import { @@ -415,7 +414,8 @@ export const RouteMap: RouteObject[] = [ lazy: () => import("../../routes/price-lists/price-list-detail"), handle: { - crumb: (data: PriceListRes) => data.price_list.title, + crumb: (data: HttpTypes.AdminPriceListResponse) => + data.price_list.title, }, children: [ { diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsx index 2d6c198f4a..190913feca 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsx @@ -1,5 +1,4 @@ import { ArrowPath } from "@medusajs/icons" -import { Customer, Order } from "@medusajs/medusa" import { Button, Container, Heading } from "@medusajs/ui" import { keepPreviousData } from "@tanstack/react-query" 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 { useOrderTableQuery } from "../../../../../hooks/table/query/use-order-table-query" import { useDataTable } from "../../../../../hooks/use-data-table" +import { HttpTypes } from "@medusajs/types" type CustomerGeneralSectionProps = { - customer: Customer + customer: HttpTypes.AdminCustomer } 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() return ( @@ -103,7 +103,7 @@ const CustomerOrderActions = ({ order }: { order: Order }) => { ) } -const columnHelper = createColumnHelper() +const columnHelper = createColumnHelper() const useColumns = () => { const base = useOrderTableColumns({ exclude: ["customer"] }) diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-transfer-ownership/components/transfer-customer-order-ownership-form/transfer-customer-order-ownership-form.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-transfer-ownership/components/transfer-customer-order-ownership-form/transfer-customer-order-ownership-form.tsx index a9afde1924..5b4c85f841 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-transfer-ownership/components/transfer-customer-order-ownership-form/transfer-customer-order-ownership-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-transfer-ownership/components/transfer-customer-order-ownership-form/transfer-customer-order-ownership-form.tsx @@ -1,18 +1,15 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { Order } from "@medusajs/medusa" import { Button } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" import { TransferOwnerShipForm } from "../../../../../components/forms/transfer-ownership-form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { TransferOwnershipSchema } from "../../../../../lib/schemas" +import { HttpTypes } from "@medusajs/types" type TransferCustomerOrderOwnershipFormProps = { - order: Order + order: HttpTypes.AdminOrder } export const TransferCustomerOrderOwnershipForm = ({ @@ -23,7 +20,7 @@ export const TransferCustomerOrderOwnershipForm = ({ const form = useForm>({ defaultValues: { - current_owner_id: order.customer_id, + current_owner_id: order.customer_id ?? undefined, new_owner_id: "", }, resolver: zodResolver(TransferOwnershipSchema), diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-location-levels.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-location-levels.tsx index 993daf33d0..3ca7071f65 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-location-levels.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-location-levels.tsx @@ -1,12 +1,11 @@ import { Button, Container, Heading } from "@medusajs/ui" - -import { InventoryItemRes } from "../../../../types/api-responses" import { ItemLocationListTable } from "./location-levels-table/location-list-table" import { Link } from "react-router-dom" import { useTranslation } from "react-i18next" +import { HttpTypes } from "@medusajs/types" type InventoryItemLocationLevelsSectionProps = { - inventoryItem: InventoryItemRes["inventory_item"] + inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"] } export const InventoryItemLocationLevelsSection = ({ inventoryItem, diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-reservations.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-reservations.tsx index 242d8950a5..532644b700 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-reservations.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-reservations.tsx @@ -1,12 +1,11 @@ import { Button, Container, Heading } from "@medusajs/ui" - -import { InventoryItemRes } from "../../../../types/api-responses" import { Link } from "react-router-dom" import { ReservationItemTable } from "./reservations-table/reservation-list-table" import { useTranslation } from "react-i18next" +import { HttpTypes } from "@medusajs/types" type InventoryItemLocationLevelsSectionProps = { - inventoryItem: InventoryItemRes["inventory_item"] + inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"] } export const InventoryItemReservationsSection = ({ inventoryItem, diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx index b862f1cedd..a2726e9887 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx @@ -1,7 +1,7 @@ import { PencilSquare, Trash } from "@medusajs/icons" import { toast, usePrompt } from "@medusajs/ui" -import { InventoryTypes } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { useTranslation } from "react-i18next" import { ActionMenu } from "../../../../../components/common/action-menu" import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" @@ -9,7 +9,7 @@ import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" export const ReservationActions = ({ reservation, }: { - reservation: InventoryTypes.ReservationItemDTO + reservation: HttpTypes.AdminReservation }) => { const { t } = useTranslation() const prompt = usePrompt() diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-list-table.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-list-table.tsx index e64904d678..4eaad45935 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-list-table.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-list-table.tsx @@ -1,10 +1,13 @@ import { useMemo } from "react" -import { InventoryTypes } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { DataTable } from "../../../../../components/table/data-table" import { useDataTable } from "../../../../../hooks/use-data-table" 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 { useStockLocations } from "../../../../../hooks/api" @@ -13,7 +16,7 @@ const PAGE_SIZE = 20 export const ReservationItemTable = ({ inventoryItem, }: { - inventoryItem: InventoryTypes.InventoryItemDTO + inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"] }) => { const { searchParams, raw } = useReservationsTableQuery({ pageSize: PAGE_SIZE, @@ -29,7 +32,7 @@ export const ReservationItemTable = ({ id: (reservations || []).map((r) => r.location_id), }) - const data = useMemo(() => { + const data = useMemo(() => { const locationMap = new Map((stock_locations || []).map((l) => [l.id, l])) return (reservations || []).map((r) => ({ @@ -45,7 +48,7 @@ export const ReservationItemTable = ({ columns, count, enablePagination: true, - getRowId: (row: InventoryTypes.ReservationItemDTO) => row.id, + getRowId: (row: ExtendedReservationItem) => row.id, pageSize: PAGE_SIZE, }) diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns.tsx index 3e256b0eb2..997c2806cb 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns.tsx @@ -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 { ReservationActions } from "./reservation-actions" import { createColumnHelper } from "@tanstack/react-table" import { useMemo } from "react" 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" /** * Adds missing properties to the InventoryItemDTO type. */ -interface ExtendedReservationItem extends InventoryTypes.ReservationItemDTO { - line_item: { order_id: string } - location: StockLocationDTO +export interface ExtendedReservationItem extends HttpTypes.AdminReservation { + line_item?: { order_id: string } + location?: HttpTypes.AdminStockLocation } const columnHelper = createColumnHelper() diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-item.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-item.tsx index 3dbb7cdfd0..70b731c8e2 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-item.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-item.tsx @@ -2,8 +2,6 @@ import { Trash } from "@medusajs/icons" import { useMemo } from "react" import { useTranslation } from "react-i18next" import * as zod from "zod" - -import { LineItem } from "@medusajs/medusa" import { Input, Text } from "@medusajs/ui" 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 { getFulfillableQuantity } from "../../../../../lib/order-item.ts" import { CreateFulfillmentSchema } from "./constants.ts" +import { HttpTypes } from "@medusajs/types" type OrderEditItemProps = { - item: LineItem + item: HttpTypes.AdminOrderLineItem currencyCode: string locationId?: string onItemRemove: (itemId: string) => void @@ -33,8 +32,8 @@ export function OrderCreateFulfillmentItem({ const { t } = useTranslation() const { variant } = useProductVariant( - item.variant.product_id, - item.variant_id, + item.variant!.product_id!, + item.variant_id!, { fields: "*inventory,*inventory.location_levels", } @@ -79,10 +78,10 @@ export function OrderCreateFulfillmentItem({ {item.title} - {item.variant.sku && ({item.variant.sku})} + {item.variant?.sku && ({item.variant.sku})}
- {item.variant.title} + {item.variant?.title ?? ""}
diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-customer-section/order-customer-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-customer-section/order-customer-section.tsx index 818f943496..26217333fd 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-customer-section/order-customer-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-customer-section/order-customer-section.tsx @@ -1,13 +1,12 @@ -import { Order } from "@medusajs/medusa" import { Container, Heading } from "@medusajs/ui" import { useTranslation } from "react-i18next" - import { ArrowPath, CurrencyDollar, Envelope, FlyingBox } from "@medusajs/icons" import { ActionMenu } from "../../../../../components/common/action-menu" import { CustomerInfo } from "../../../../../components/common/customer-info" +import { HttpTypes } from "@medusajs/types" type OrderCustomerSectionProps = { - order: Order + order: HttpTypes.AdminOrder } export const OrderCustomerSection = ({ order }: OrderCustomerSectionProps) => { diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-general-section/order-general-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-general-section/order-general-section.tsx index e4dd017e91..f079a589ac 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-general-section/order-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-general-section/order-general-section.tsx @@ -1,5 +1,4 @@ import { XCircle } from "@medusajs/icons" -import { Order } from "@medusajs/medusa" import { Container, Copy, @@ -16,9 +15,10 @@ import { getOrderFulfillmentStatus, getOrderPaymentStatus, } from "../../../../../lib/order-helpers" +import { HttpTypes } from "@medusajs/types" type OrderGeneralSectionProps = { - order: Order + order: HttpTypes.AdminOrder } 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 { 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() /** diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-payment-section/order-payment-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-payment-section/order-payment-section.tsx index 997ebf3657..94d2ef9de7 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-payment-section/order-payment-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-payment-section/order-payment-section.tsx @@ -1,8 +1,4 @@ import { ArrowDownRightMini, DocumentText, XCircle } from "@medusajs/icons" -import { - Payment as MedusaPayment, - Refund as MedusaRefund, -} from "@medusajs/medusa" import { AdminPaymentCollection, HttpTypes } from "@medusajs/types" import { Badge, @@ -44,7 +40,7 @@ export const OrderPaymentSection = ({ order }: OrderPaymentSectionProps) => { const refunds = payments .map((payment) => payment?.refunds) .flat(1) - .filter(Boolean) + .filter(Boolean) as HttpTypes.AdminRefund[] return ( @@ -122,7 +118,7 @@ const Refund = ({
{RefundReasonBadge}
- - {getLocaleAmount(refund.amount, currencyCode)} + - {getLocaleAmount(refund.amount as number, currencyCode)}
@@ -136,8 +132,8 @@ const Payment = ({ currencyCode, }: { order: HttpTypes.AdminOrder - payment: MedusaPayment - refunds: MedusaRefund[] + payment: HttpTypes.AdminPayment + refunds: HttpTypes.AdminRefund[] currencyCode: string }) => { const { t } = useTranslation() @@ -148,7 +144,7 @@ const Payment = ({ const res = await prompt({ title: t("orders.payment.capture"), description: t("orders.payment.capturePayment", { - amount: formatCurrency(payment.amount, currencyCode), + amount: formatCurrency(payment.amount as number, currencyCode), }), confirmText: t("actions.confirm"), cancelText: t("actions.cancel"), @@ -160,12 +156,12 @@ const Payment = ({ } await mutateAsync( - { amount: payment.amount }, + { amount: payment.amount as number }, { onSuccess: () => { toast.success( t("orders.payment.capturePaymentSuccess", { - amount: formatCurrency(payment.amount, currencyCode), + amount: formatCurrency(payment.amount as number, currencyCode), }) ) }, @@ -197,7 +193,10 @@ const Payment = ({ {cleanId} - {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" + )}
@@ -212,7 +211,7 @@ const Payment = ({
- {getLocaleAmount(payment.amount, payment.currency_code)} + {getLocaleAmount(payment.amount as number, payment.currency_code)}
{ /** @@ -271,7 +270,10 @@ const PaymentBreakdown = ({ const entries = [...orderRefunds, ...payments] .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) => { return { @@ -279,8 +281,8 @@ const PaymentBreakdown = ({ type: entry.id.startsWith("pay_") ? "payment" : "refund", } }) as ( - | { type: "payment"; event: MedusaPayment } - | { type: "refund"; event: MedusaRefund } + | { type: "payment"; event: HttpTypes.AdminPayment } + | { type: "refund"; event: HttpTypes.AdminRefund } )[] return ( diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/loader.ts b/packages/admin-next/dashboard/src/routes/orders/order-detail/loader.ts index 22b34aa4fc..febd09579e 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/loader.ts @@ -1,9 +1,9 @@ import { LoaderFunctionArgs } from "react-router-dom" +import { HttpTypes } from "@medusajs/types" import { ordersQueryKeys } from "../../../hooks/api/orders" import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { OrderRes } from "../../../types/api-responses" import { DEFAULT_FIELDS } from "./constants" const orderDetailQuery = (id: string) => ({ @@ -19,7 +19,7 @@ export const orderLoader = async ({ params }: LoaderFunctionArgs) => { const query = orderDetailQuery(id!) return ( - queryClient.getQueryData(query.queryKey) ?? + queryClient.getQueryData(query.queryKey) ?? (await queryClient.fetchQuery(query)) ) } diff --git a/packages/admin-next/dashboard/src/routes/price-lists/price-list-detail/loader.ts b/packages/admin-next/dashboard/src/routes/price-lists/price-list-detail/loader.ts index acf902d6b1..08c23dc251 100644 --- a/packages/admin-next/dashboard/src/routes/price-lists/price-list-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/price-lists/price-list-detail/loader.ts @@ -1,8 +1,8 @@ +import { HttpTypes } from "@medusajs/types" import { LoaderFunctionArgs } from "react-router-dom" import { priceListsQueryKeys } from "../../../hooks/api/price-lists" import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { PriceListRes } from "../../../types/api-responses" const pricingDetailQuery = (id: string) => ({ queryKey: priceListsQueryKeys.detail(id), @@ -14,7 +14,8 @@ export const pricingLoader = async ({ params }: LoaderFunctionArgs) => { const query = pricingDetailQuery(id!) return ( - queryClient.getQueryData(query.queryKey) ?? - (await queryClient.fetchQuery(query)) + queryClient.getQueryData( + query.queryKey + ) ?? (await queryClient.fetchQuery(query)) ) } diff --git a/packages/admin-next/dashboard/src/routes/products/product-list/loader.ts b/packages/admin-next/dashboard/src/routes/products/product-list/loader.ts index 344c676916..a75c08c9d9 100644 --- a/packages/admin-next/dashboard/src/routes/products/product-list/loader.ts +++ b/packages/admin-next/dashboard/src/routes/products/product-list/loader.ts @@ -1,9 +1,9 @@ import { QueryClient } from "@tanstack/react-query" +import { HttpTypes } from "@medusajs/types" import { productsQueryKeys } from "../../../hooks/api/products" 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 }), @@ -15,8 +15,9 @@ export const productsLoader = (client: QueryClient) => { const query = productsListQuery() return ( - queryClient.getQueryData(query.queryKey) ?? - (await client.fetchQuery(query)) + queryClient.getQueryData( + query.queryKey + ) ?? (await client.fetchQuery(query)) ) } } diff --git a/packages/admin-next/dashboard/src/routes/products/product-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx b/packages/admin-next/dashboard/src/routes/products/product-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx index 0f485b44cb..c37388b74d 100644 --- a/packages/admin-next/dashboard/src/routes/products/product-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx +++ b/packages/admin-next/dashboard/src/routes/products/product-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx @@ -1,4 +1,3 @@ -import { SalesChannel } from "@medusajs/medusa" import { Button, Checkbox } from "@medusajs/ui" import { RowSelectionState, createColumnHelper } from "@tanstack/react-table" import { useEffect, useMemo, useState } from "react" @@ -153,7 +152,8 @@ export const EditSalesChannelsForm = ({ ) } -const columnHelper = createColumnHelper() +const columnHelper = + createColumnHelper() const useColumns = () => { const columns = useSalesChannelTableColumns() diff --git a/packages/admin-next/dashboard/src/routes/promotions/promotion-detail/loader.ts b/packages/admin-next/dashboard/src/routes/promotions/promotion-detail/loader.ts index b3bde557c3..b476693132 100644 --- a/packages/admin-next/dashboard/src/routes/promotions/promotion-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/promotions/promotion-detail/loader.ts @@ -1,8 +1,8 @@ +import { HttpTypes } from "@medusajs/types" import { LoaderFunctionArgs } from "react-router-dom" import { promotionsQueryKeys } from "../../../hooks/api/promotions" import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { PromotionRes } from "../../../types/api-responses" const promotionDetailQuery = (id: string) => ({ queryKey: promotionsQueryKeys.detail(id), @@ -14,7 +14,8 @@ export const promotionLoader = async ({ params }: LoaderFunctionArgs) => { const query = promotionDetailQuery(id!) return ( - queryClient.getQueryData(query.queryKey) ?? - (await queryClient.fetchQuery(query)) + queryClient.getQueryData( + query.queryKey + ) ?? (await queryClient.fetchQuery(query)) ) } diff --git a/packages/admin-next/dashboard/src/routes/promotions/promotion-list/loader.ts b/packages/admin-next/dashboard/src/routes/promotions/promotion-list/loader.ts index 9b4e252243..42ee449144 100644 --- a/packages/admin-next/dashboard/src/routes/promotions/promotion-list/loader.ts +++ b/packages/admin-next/dashboard/src/routes/promotions/promotion-list/loader.ts @@ -1,8 +1,8 @@ +import { HttpTypes } from "@medusajs/types" import { QueryClient } from "@tanstack/react-query" import { promotionsQueryKeys } from "../../../hooks/api/promotions" import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { PromotionListRes } from "../../../types/api-responses" const params = { limit: 20, @@ -19,8 +19,9 @@ export const promotionsLoader = (client: QueryClient) => { const query = promotionsListQuery() return ( - queryClient.getQueryData(query.queryKey) ?? - (await client.fetchQuery(query)) + queryClient.getQueryData( + query.queryKey + ) ?? (await client.fetchQuery(query)) ) } } diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx index 8f2e8383e2..c4a2c244a8 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx @@ -7,7 +7,7 @@ import { } from "../../../../../components/modals" import { zodResolver } from "@hookform/resolvers/zod" -import { InventoryTypes } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import React from "react" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -16,7 +16,6 @@ import { Combobox } from "../../../../../components/inputs/combobox" import { useInventoryItems } from "../../../../../hooks/api/inventory" import { useCreateReservationItem } from "../../../../../hooks/api/reservations" import { useStockLocations } from "../../../../../hooks/api/stock-locations" -import { InventoryItemRes } from "../../../../../types/api-responses" export const CreateReservationSchema = zod.object({ 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 selectedInventoryItem = inventory_items?.find( (it) => it.id === inventoryItemId - ) as InventoryItemRes["inventory_item"] | undefined + ) as HttpTypes.AdminInventoryItemResponse["inventory_item"] | undefined const locationId = form.watch("location_id") const selectedLocationLevel = selectedInventoryItem?.location_levels?.find( @@ -81,7 +80,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => { { id: 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 }) => { { )} min={1} max={ - selectedLocationLevel + selectedLocationLevel?.available_quantity ? selectedLocationLevel.available_quantity : 0 } diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx index 029cc52d72..efc3c5c1a4 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx @@ -1,6 +1,5 @@ import * as zod from "zod" - -import { InventoryTypes, StockLocationDTO } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { Button, Input, Select, Text, Textarea, toast } from "@medusajs/ui" import { RouteDrawer, useRouteModal } from "../../../../../../components/modals" @@ -10,12 +9,11 @@ import { useTranslation } from "react-i18next" import { z } from "zod" import { Form } from "../../../../../../components/common/form" import { useUpdateReservationItem } from "../../../../../../hooks/api/reservations" -import { InventoryItemRes } from "../../../../../../types/api-responses" type EditReservationFormProps = { - reservation: InventoryTypes.ReservationItemDTO - locations: StockLocationDTO[] - item: InventoryItemRes["inventory_item"] + reservation: HttpTypes.AdminReservationResponse["reservation"] + locations: HttpTypes.AdminStockLocation[] + item: HttpTypes.AdminInventoryItemResponse["inventory_item"] } const EditReservationSchema = z.object({ @@ -43,7 +41,9 @@ const AttributeGridRow = ({ ) } -const getDefaultValues = (reservation: InventoryTypes.ReservationItemDTO) => { +const getDefaultValues = ( + reservation: HttpTypes.AdminReservationResponse["reservation"] +) => { return { quantity: reservation.quantity, location_id: reservation.location_id, @@ -82,8 +82,7 @@ export const EditReservationForm = ({ const locationId = form.watch("location_id") const level = item.location_levels!.find( - (level: InventoryTypes.InventoryLevelDTO) => - level.location_id === locationId + (level: HttpTypes.AdminInventoryLevel) => level.location_id === locationId ) return ( @@ -139,7 +138,7 @@ export const EditReservationForm = ({ title={t("inventory.available")} value={ level!.stocked_quantity - - (level.reserved_quantity - reservation.quantity) - + (level!.reserved_quantity - reservation.quantity) - reservedQuantity } /> @@ -157,7 +156,10 @@ export const EditReservationForm = ({ { const value = e.target.value diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/reservation-actions.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/reservation-actions.tsx index 05bd5abdfb..477f0f8d58 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/reservation-actions.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/reservation-actions.tsx @@ -1,10 +1,10 @@ import { PencilSquare, Trash } from "@medusajs/icons" import { ActionMenu } from "../../../../../components/common/action-menu" -import { ExtendedReservationItem } from "@medusajs/medusa" import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" import { usePrompt } from "@medusajs/ui" import { useTranslation } from "react-i18next" +import { ExtendedReservationItem } from "../../../../inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns" export const ReservationActions = ({ reservation, diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-columns.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-columns.tsx index 84faf34525..21cc3e76d8 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-columns.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-columns.tsx @@ -1,4 +1,3 @@ -import { ExtendedReservationItem } from "@medusajs/medusa" import { createColumnHelper } from "@tanstack/react-table" import { useMemo } from "react" 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 { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell" import { ReservationActions } from "./reservation-actions" +import { ExtendedReservationItem } from "../../../../inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns" const columnHelper = createColumnHelper() diff --git a/packages/admin-next/dashboard/src/routes/users/user-detail/loader.ts b/packages/admin-next/dashboard/src/routes/users/user-detail/loader.ts index b0c44cd827..4851460d64 100644 --- a/packages/admin-next/dashboard/src/routes/users/user-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/users/user-detail/loader.ts @@ -1,9 +1,9 @@ import { LoaderFunctionArgs } from "react-router-dom" +import { HttpTypes } from "@medusajs/types" import { productsQueryKeys } from "../../../hooks/api/products" import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { UserRes } from "../../../types/api-responses" const userDetailQuery = (id: string) => ({ queryKey: productsQueryKeys.detail(id), @@ -15,7 +15,7 @@ export const userLoader = async ({ params }: LoaderFunctionArgs) => { const query = userDetailQuery(id!) return ( - queryClient.getQueryData(query.queryKey) ?? + queryClient.getQueryData(query.queryKey) ?? (await queryClient.fetchQuery(query)) ) } diff --git a/packages/admin-next/dashboard/src/routes/workflow-executions/workflow-execution-detail/loader.ts b/packages/admin-next/dashboard/src/routes/workflow-executions/workflow-execution-detail/loader.ts index 8d9df579a4..d8f331dfc0 100644 --- a/packages/admin-next/dashboard/src/routes/workflow-executions/workflow-execution-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/workflow-executions/workflow-execution-detail/loader.ts @@ -1,9 +1,9 @@ import { LoaderFunctionArgs } from "react-router-dom" +import { HttpTypes } from "@medusajs/types" import { workflowExecutionsQueryKeys } from "../../../hooks/api/workflow-executions" import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { WorkflowExecutionRes } from "../../../types/api-responses" const executionDetailQuery = (id: string) => ({ queryKey: workflowExecutionsQueryKeys.detail(id), @@ -15,7 +15,8 @@ export const executionLoader = async ({ params }: LoaderFunctionArgs) => { const query = executionDetailQuery(id!) return ( - queryClient.getQueryData(query.queryKey) ?? - (await queryClient.fetchQuery(query)) + queryClient.getQueryData( + query.queryKey + ) ?? (await queryClient.fetchQuery(query)) ) } diff --git a/packages/admin-next/dashboard/src/types/api-payloads.ts b/packages/admin-next/dashboard/src/types/api-payloads.ts deleted file mode 100644 index 0a1554bd73..0000000000 --- a/packages/admin-next/dashboard/src/types/api-payloads.ts +++ /dev/null @@ -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 - -// 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 -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 -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 diff --git a/packages/admin-next/dashboard/src/types/api-responses.ts b/packages/admin-next/dashboard/src/types/api-responses.ts deleted file mode 100644 index 33870c77cb..0000000000 --- a/packages/admin-next/dashboard/src/types/api-responses.ts +++ /dev/null @@ -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[] } -export type PromotionRuleOperatorsListRes = { operators: Record[] } -export type PromotionRuleValuesListRes = { values: Record[] } -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 diff --git a/packages/core/js-sdk/src/auth/index.ts b/packages/core/js-sdk/src/auth/index.ts index b21c19587e..07a45e5490 100644 --- a/packages/core/js-sdk/src/auth/index.ts +++ b/packages/core/js-sdk/src/auth/index.ts @@ -1,3 +1,4 @@ +import { HttpTypes } from "@medusajs/types" import { Client } from "../client" import { Config } from "../types" @@ -13,7 +14,7 @@ export class Auth { register = async ( actor: "customer" | "user", method: "emailpass", - payload: { email: string; password: string } + payload: HttpTypes.AdminSignUpWithEmailPassword ) => { const { token } = await this.client.fetch<{ token: string }>( `/auth/${actor}/${method}/register`, @@ -31,7 +32,7 @@ export class Auth { login = async ( actor: "customer" | "user", method: "emailpass", - payload: { email: string; password: string } + payload: HttpTypes.AdminSignInWithEmailPassword ) => { const { token } = await this.client.fetch<{ token: string }>( `/auth/${actor}/${method}`, diff --git a/packages/core/types/src/http/address/entities.ts b/packages/core/types/src/http/address/entities.ts new file mode 100644 index 0000000000..aa0e62039e --- /dev/null +++ b/packages/core/types/src/http/address/entities.ts @@ -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 | null + created_at: Date | string + updated_at: Date | string +} diff --git a/packages/core/types/src/http/address/index.ts b/packages/core/types/src/http/address/index.ts new file mode 100644 index 0000000000..8270e0b265 --- /dev/null +++ b/packages/core/types/src/http/address/index.ts @@ -0,0 +1 @@ +export * from "./entities" diff --git a/packages/core/types/src/http/auth/index.ts b/packages/core/types/src/http/auth/index.ts new file mode 100644 index 0000000000..b57bea2482 --- /dev/null +++ b/packages/core/types/src/http/auth/index.ts @@ -0,0 +1 @@ +export * from "./payloads" diff --git a/packages/core/types/src/http/auth/payloads.ts b/packages/core/types/src/http/auth/payloads.ts new file mode 100644 index 0000000000..6976b0504b --- /dev/null +++ b/packages/core/types/src/http/auth/payloads.ts @@ -0,0 +1,7 @@ +export interface AdminSignUpWithEmailPassword { + email: string + password: string +} + +export interface AdminSignInWithEmailPassword + extends AdminSignUpWithEmailPassword {} diff --git a/packages/core/types/src/http/customer-group/admin/queries.ts b/packages/core/types/src/http/customer-group/admin/queries.ts index 3dc0d67b6f..46b0907eee 100644 --- a/packages/core/types/src/http/customer-group/admin/queries.ts +++ b/packages/core/types/src/http/customer-group/admin/queries.ts @@ -1,5 +1,5 @@ -import { OperatorMap } from "../../../dal" -import { SelectParams } from "../../common" +import { BaseFilterable, OperatorMap } from "../../../dal" +import { FindParams, SelectParams } from "../../common" export interface AdminCustomerInGroupFilters { id?: string | string[] @@ -15,7 +15,9 @@ export interface AdminCustomerInGroupFilters { deleted_at?: OperatorMap } -export interface AdminGetCustomerGroupsParams { +export interface AdminGetCustomerGroupsParams + extends FindParams, + BaseFilterable { limit?: number offset?: number q?: string diff --git a/packages/core/types/src/http/customer/common.ts b/packages/core/types/src/http/customer/common.ts index e3061f26d4..e0a1728e04 100644 --- a/packages/core/types/src/http/customer/common.ts +++ b/packages/core/types/src/http/customer/common.ts @@ -1,4 +1,5 @@ import { BaseFilterable, OperatorMap } from "../../dal" +import { FindParams } from "../common" export interface BaseCustomerGroup { id: string @@ -56,7 +57,8 @@ export interface CustomerGroupInCustomerFilters { } export interface BaseCustomerFilters - extends BaseFilterable { + extends FindParams, + BaseFilterable { q?: string id?: string[] | string | OperatorMap email?: string[] | string | OperatorMap diff --git a/packages/core/types/src/http/index.ts b/packages/core/types/src/http/index.ts index 08409da573..acb4705920 100644 --- a/packages/core/types/src/http/index.ts +++ b/packages/core/types/src/http/index.ts @@ -1,4 +1,6 @@ +export * from "./address" export * from "./api-key" +export * from "./auth" export * from "./campaign" export * from "./cart" export * from "./claim" diff --git a/packages/core/types/src/http/inventory/admin/entities.ts b/packages/core/types/src/http/inventory/admin/entities.ts index b0f4b296cb..6b1b791a57 100644 --- a/packages/core/types/src/http/inventory/admin/entities.ts +++ b/packages/core/types/src/http/inventory/admin/entities.ts @@ -14,4 +14,24 @@ export interface AdminInventoryItem { description?: string | null thumbnail?: string | null metadata?: Record | 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 + reserved_quantity: number + raw_reserved_quantity: Record + incoming_quantity: number + raw_incoming_quantity: Record + metadata: Record | null + inventory_item?: AdminInventoryItem + available_quantity: number | null } diff --git a/packages/core/types/src/http/order/admin/entities.ts b/packages/core/types/src/http/order/admin/entities.ts index 8af116a435..9992d86b6e 100644 --- a/packages/core/types/src/http/order/admin/entities.ts +++ b/packages/core/types/src/http/order/admin/entities.ts @@ -1,4 +1,8 @@ +import { AdminCustomer } from "../../customer" import { AdminPaymentCollection } from "../../payment/admin" +import { AdminProductVariant } from "../../product" +import { AdminRegionCountry } from "../../region" +import { AdminSalesChannel } from "../../sales-channel" import { BaseOrder, BaseOrderAddress, @@ -12,15 +16,26 @@ import { export interface AdminOrder extends BaseOrder { payment_collections: AdminPaymentCollection[] 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 AdminOrderLineItem extends BaseOrderLineItem {} -export interface AdminOrderAddress extends BaseOrderAddress {} + +export interface AdminOrderAddress extends BaseOrderAddress { + country?: AdminRegionCountry +} + export interface AdminOrderShippingMethod extends BaseOrderShippingMethod {} + export interface AdminOrderPreview extends Omit { return_requested_total: number diff --git a/packages/core/types/src/http/order/admin/queries.ts b/packages/core/types/src/http/order/admin/queries.ts index 2eee6271a5..a4b6c56337 100644 --- a/packages/core/types/src/http/order/admin/queries.ts +++ b/packages/core/types/src/http/order/admin/queries.ts @@ -1,7 +1,15 @@ -import { BaseFilterable } from "../../../dal"; -import { FindParams } from "../../common"; +import { OperatorMap } from "../../../dal" +import { FindParams } from "../../common" +import { BaseOrderFilters } from "../common" -export interface AdminOrderFilters extends FindParams, BaseFilterable { +export interface AdminOrderFilters extends FindParams, BaseOrderFilters { id?: string[] | string name?: string[] | string -} \ No newline at end of file + sales_channel_id?: string[] + fulfillment_status?: string[] + payment_status?: string[] + region_id?: string[] + q?: string + created_at?: OperatorMap + updated_at?: OperatorMap +} diff --git a/packages/core/types/src/http/order/common.ts b/packages/core/types/src/http/order/common.ts index cd887545e2..44b390a48f 100644 --- a/packages/core/types/src/http/order/common.ts +++ b/packages/core/types/src/http/order/common.ts @@ -1,6 +1,7 @@ import { BaseFilterable, OperatorMap } from "../../dal" import { BigNumberValue } from "../../totals" import { BaseClaim } from "../claim/common" +import { FindParams } from "../common" import { BasePaymentCollection } from "../payment/common" import { BaseProduct, BaseProductVariant } from "../product/common" @@ -264,9 +265,9 @@ export interface BaseOrder { sales_channel_id: string | null email: string | null currency_code: string - display_id?: string - shipping_address?: BaseOrderAddress - billing_address?: BaseOrderAddress + display_id?: number + shipping_address?: BaseOrderAddress | null + billing_address?: BaseOrderAddress | null items: BaseOrderLineItem[] | null shipping_methods: BaseOrderShippingMethod[] | null payment_collections?: BasePaymentCollection[] @@ -302,7 +303,9 @@ export interface BaseOrder { original_shipping_tax_total: number } -export interface BaseOrderFilters extends BaseFilterable { +export interface BaseOrderFilters + extends FindParams, + BaseFilterable { id?: string[] | string | OperatorMap status?: string[] | string | OperatorMap } diff --git a/packages/core/types/src/http/reservation/admin/entities.ts b/packages/core/types/src/http/reservation/admin/entities.ts index 7619dd32c0..186f96e551 100644 --- a/packages/core/types/src/http/reservation/admin/entities.ts +++ b/packages/core/types/src/http/reservation/admin/entities.ts @@ -2,7 +2,7 @@ export interface AdminReservation { id: string line_item_id: string | null location_id: string - quantity: string + quantity: number external_id: string | null description: string | null inventory_item_id: string diff --git a/packages/core/types/src/http/shipping-option/admin/queries.ts b/packages/core/types/src/http/shipping-option/admin/queries.ts index d0a358ae5e..e66b60e581 100644 --- a/packages/core/types/src/http/shipping-option/admin/queries.ts +++ b/packages/core/types/src/http/shipping-option/admin/queries.ts @@ -6,6 +6,8 @@ export interface AdminShippingOptionListParams extends FindParams { q?: string service_zone_id?: string | string[] stock_location_id?: string | string[] + is_return?: boolean + admin_only?: boolean shipping_profile_id?: string | string[] provider_id?: string | string[] shipping_option_type_id?: string | string[] diff --git a/packages/medusa/src/api/admin/shipping-options/validators.ts b/packages/medusa/src/api/admin/shipping-options/validators.ts index fd2803ab65..d96769c8c4 100644 --- a/packages/medusa/src/api/admin/shipping-options/validators.ts +++ b/packages/medusa/src/api/admin/shipping-options/validators.ts @@ -3,6 +3,7 @@ import { ShippingOptionPriceType as ShippingOptionPriceTypeEnum, } from "@medusajs/utils" import { z } from "zod" +import { booleanString } from "../../utils/common-validators" import { createFindParams, createOperatorMap, @@ -28,6 +29,8 @@ export const AdminGetShippingOptionsParams = createFindParams({ shipping_profile_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(), + is_return: booleanString().optional(), + admin_only: booleanString().optional(), shipping_option_type_id: z .union([z.string(), z.array(z.string())]) .optional(),