Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/hooks/api/collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const useCollections = (
>,
"queryFn" | "queryKey"
>,
id?: string
) => {
const { data, ...rest } = useQuery({
queryKey: collectionsQueryKeys.list(query),
Expand All @@ -67,15 +66,6 @@ export const useCollections = (
...options,
})

if (id) {
return {
...rest,
...data,
product_collections: data?.product_collections.find(
(item) => item.id === id
),
}
}
return { ...data, ...rest }
}

Expand Down
12 changes: 6 additions & 6 deletions src/hooks/api/customer-groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { customersQueryKeys } from "./customers"
import { filterCustomerGroups } from "../../routes/orders/common/customerGroupFiltering"
import { CustomerGroupListResponse } from "../../types/customer-group"

const CUSTOMER_GROUPS_QUERY_KEY = "customer_groups" as const
export const customerGroupsQueryKeys = queryKeysFactory(
Expand Down Expand Up @@ -50,9 +51,7 @@ export const useCustomerGroups = (
UseQueryOptions<
HttpTypes.AdminGetCustomerGroupsParams,
FetchError,
HttpTypes.AdminCustomerGroupListResponse & {
customer_group?: any
},
CustomerGroupListResponse,
QueryKey
>,
"queryFn" | "queryKey"
Expand All @@ -67,7 +66,7 @@ export const useCustomerGroups = (
queryKey: customerGroupsQueryKeys.list(query),
...options,
})

const filteredData = filterCustomerGroups(
data?.customer_groups,
filters,
Expand All @@ -79,10 +78,11 @@ export const useCustomerGroups = (
const count = customer_groups?.length || 0

return {
...data,
...rest,
count,
customer_groups,
...rest,
offset: data?.offset,
limit: data?.limit,
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/hooks/api/price-lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { fetchQuery, sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { ExtendedPriceList, PriceListListResponse } from "../../types/price-list"
import { customerGroupsQueryKeys } from "./customer-groups"
import { productsQueryKeys } from "./products"

Expand Down Expand Up @@ -72,9 +73,9 @@ export const usePriceLists = (
query?: HttpTypes.AdminPriceListListParams,
options?: Omit<
UseQueryOptions<
HttpTypes.AdminPriceListListResponse,
PriceListListResponse,
FetchError,
any,
PriceListListResponse,
QueryKey
>,
"queryKey" | "queryFn"
Expand All @@ -90,8 +91,15 @@ export const usePriceLists = (
...options,
})

const price_lists = data?.price_lists?.filter((item: any) => item.price_list)
const price_lists: ExtendedPriceList[] | undefined = data?.price_lists
?.filter((item) => item.price_list)
.map((item) => ({
...item.price_list,
id: item.price_list.id,
}))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:
const price_lists: ExtendedPriceList[] = (data?.price_lists || []) .filter((item) => item.price_list) .map((item) => ({ ...item.price_list, id: item.price_list.id, }))

const count = price_lists?.length || 0

return { ...data, price_lists, count, ...rest }
}

Expand Down
1 change: 0 additions & 1 deletion src/hooks/api/promotions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ export const usePromotionUpdateRules = (
)

const rulesIds = rules.map((rule: any) => rule.id)
console.log("rules", rulesIds)
await fetchQuery(`/vendor/promotions/${id}/${ruleType}/batch`, {
method: "POST",
body: { delete: rulesIds },
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/api/stock-locations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { fetchQuery } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { fulfillmentProvidersQueryKeys } from "./fulfillment-providers"
import { VendorExtendedAdminStockLocationResponse } from "../../types/stock-location"

const STOCK_LOCATIONS_QUERY_KEY = "stock_locations" as const
export const stockLocationsQueryKeys = queryKeysFactory(
Expand All @@ -25,7 +26,7 @@ export const useStockLocation = (
UseQueryOptions<
HttpTypes.AdminStockLocationResponse,
FetchError,
HttpTypes.AdminStockLocationResponse,
VendorExtendedAdminStockLocationResponse,
QueryKey
>,
"queryKey" | "queryFn"
Expand All @@ -40,7 +41,7 @@ export const useStockLocation = (
queryKey: stockLocationsQueryKeys.detail(id, query),
...options,
})

return { ...data, ...rest }
}

Expand Down
6 changes: 2 additions & 4 deletions src/hooks/table/columns/use-customer-group-table-columns.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpTypes } from "@medusajs/types"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"

Expand All @@ -6,7 +7,6 @@ import {
TextCell,
TextHeader,
} from "../../../components/table/table-cells/common/text-cell"
import { HttpTypes } from "@medusajs/types"

const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()

Expand All @@ -20,9 +20,7 @@ export const useCustomerGroupTableColumns = () => {
cell: ({ row }) => {
return (
<TextCell
text={
row.original?.customer_group?.name || row.original?.name || "-"
}
text={row.original?.name || "-"}
/>
)
},
Expand Down
1 change: 1 addition & 0 deletions src/hooks/table/filters/use-product-table-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const excludeableFields = [
"categories",
"product_types",
"product_tags",
"sales_channel_id",
] as const

export const useProductTableFilters = (
Expand Down
16 changes: 9 additions & 7 deletions src/lib/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ export const isSameAddress = (
export const getFormattedAddress = ({
address,
}: {
address?: HttpTypes.AdminOrderAddress | null
address?: HttpTypes.AdminOrderAddress | HttpTypes.AdminStockLocationAddress | null
}) => {
if (!address) {
return []
}

const {
first_name,
last_name,
company,
address_1,
address_2,
city,
postal_code,
province,
country,
country_code,
} = address

// Check if it's an AdminOrderAddress (has first_name/last_name)
const first_name = 'first_name' in address ? address.first_name : undefined
const last_name = 'last_name' in address ? address.last_name : undefined
const country = 'country' in address ? address.country : undefined

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the comment and how about just:

const first_name = address?.first_name
const last_name = address?.last_name
const country = address?.country

Copy link
Collaborator Author

@sylwia-werner sylwia-werner Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address can be HttpTypes.AdminOrderAddress | HttpTypes.AdminStockLocationAddress and those properties don't exist on HttpTypes.AdminStockLocationAddress. That's why I left the comment but will be removed 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, got it
but still, how about shortening those consts to
const first_name = address?.first_name const last_name = address?.last_name const country = address?.country

result should be the same -> if there is the key (eg. first_name) should return it, else should be set to undefined

const name = [first_name, last_name].filter(Boolean).join(" ")

const formattedAddress: string[] = []
Expand Down Expand Up @@ -75,10 +77,10 @@ export const getFormattedAddress = ({
if (country) {
formattedAddress.push(country.display_name!)
} else if (country_code) {
const country = getCountryByIso2(country_code)
const countryData = getCountryByIso2(country_code)

if (country) {
formattedAddress.push(country.display_name)
if (countryData) {
formattedAddress.push(countryData.display_name)
} else {
formattedAddress.push(country_code.toUpperCase())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const EditCampaignBudgetForm = ({
}
)
})

return (
<RouteDrawer.Form form={form}>
<KeyboundForm onSubmit={handleSubmit} className="flex flex-1 flex-col">
Expand Down Expand Up @@ -95,7 +95,7 @@ export const EditCampaignBudgetForm = ({
key="usage"
min={0}
{...field}
value={value}
value={value || undefined}
onChange={(e) => {
onChange(
e.target.value === ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "../../../../../lib/data/currencies"
import { CampaignFormFields, WithNestedCampaign } from "../../../../../types/campaign"


type CreateCampaignFormFieldsProps<T extends CampaignFormFields | WithNestedCampaign> = {
form: UseFormReturn<T>
fieldScope?: string
Expand All @@ -29,6 +30,7 @@ export const CreateCampaignFormFields = <T extends CampaignFormFields | WithNest
form,
fieldScope = ""
}: CreateCampaignFormFieldsProps<T>) => {

const { t } = useTranslation()
const { store } = useStore()

Expand Down
9 changes: 4 additions & 5 deletions src/routes/collections/collection-detail/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ export const CollectionDetailBreadcrumb = (
) => {
const { id } = props.params || {}

const { collection } = useCollection(id!, {
initialData: props.data,
enabled: Boolean(id),
const { product_collection } = useCollection(id!, {
initialData: { product_collection: props.data.collection },
})

if (!collection) {
if (!product_collection) {
return null
}

return <span>{collection.title}</span>
return <span>{product_collection.title}</span>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useCollection, useUpdateCollection } from "../../../hooks/api"
export const CollectionMetadata = () => {
const { id } = useParams()

const { collection, isPending, isError, error } = useCollection(id!)
const { product_collection, isPending, isError, error } = useCollection(id!)

const { mutateAsync, isPending: isMutating } = useUpdateCollection(
collection?.id!
product_collection?.id!
)

if (isError) {
Expand All @@ -17,7 +17,7 @@ export const CollectionMetadata = () => {

return (
<MetadataForm
metadata={collection?.metadata}
metadata={product_collection?.metadata}
hook={mutateAsync}
isPending={isPending}
isMutating={isMutating}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PencilSquare, Trash } from "@medusajs/icons"
import { HttpTypes } from "@medusajs/types"
import {
Container,
createDataTableColumnHelper,
Expand All @@ -19,8 +18,8 @@ import {
useDeleteCustomerGroupLazy,
} from "../../../../../hooks/api"
import { useDate } from "../../../../../hooks/use-date"
import { _DataTable } from "../../../../../components/table/data-table"
import { TextCell } from "../../../../../components/table/table-cells/common/text-cell"
import { CustomerGroupData } from "../../../../orders/common/customerGroupFiltering"

const PAGE_SIZE = 10

Expand Down Expand Up @@ -56,10 +55,10 @@ export const CustomerGroupListTable = () => {
heading={t("customerGroups.domain")}
subHeading="Organize customers into groups. Groups can have different promotions and prices."
rowCount={count}
getRowId={(row) => row.id}
rowHref={(row) => {
return `/customer-groups/${row.original.customer_group_id}`
}}
getRowId={(row) => row.customer_group_id}
// For some reason the table requires accessing data on row.original in this specific case
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this comment is unnecessary

Copy link
Collaborator Author

@sylwia-werner sylwia-werner Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this comment I explained why I used any :D but the rows are fixed in pt-3 or pt-4, removing the comment

rowHref={(row: any) => `/customer-groups/${row.original.customer_group_id}`
}
action={{
label: t("actions.create"),
to: "/customer-groups/create",
Expand All @@ -82,7 +81,7 @@ export const CustomerGroupListTable = () => {
)
}

const columnHelper = createDataTableColumnHelper<HttpTypes.AdminCustomerGroup>()
const columnHelper = createDataTableColumnHelper<CustomerGroupData>()

const useColumns = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -130,7 +129,7 @@ const useColumns = () => {

return useMemo(() => {
return [
columnHelper.accessor("name", {
columnHelper.accessor("customer_group.name", {
header: t("fields.name"),
enableSorting: true,
sortAscLabel: t("filters.sorting.alphabeticallyAsc"),
Expand All @@ -139,7 +138,7 @@ const useColumns = () => {
return <TextCell text={row?.original?.customer_group?.name || "-"} />
},
}),
columnHelper.accessor("customers", {
columnHelper.accessor("customer_group.customers", {
header: t("customers.domain"),
cell: ({ row }) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"
import { HttpTypes, InventoryLevelDTO, StockLocationDTO } from "@medusajs/types"
import { HttpTypes, InventoryLevelDTO } from "@medusajs/types"
import { Button, Input, Text, toast } from "@medusajs/ui"
import { useForm, useWatch } from "react-hook-form"
import { useTranslation } from "react-i18next"
Expand All @@ -10,11 +10,12 @@ import { RouteDrawer, useRouteModal } from "../../../../../../components/modals"
import { KeyboundForm } from "../../../../../../components/utilities/keybound-form"
import { useUpdateInventoryLevel } from "../../../../../../hooks/api/inventory"
import { castNumber } from "../../../../../../lib/cast-number"
import { VendorExtendedAdminStockLocation } from "../../../../../../types/stock-location"

type AdjustInventoryFormProps = {
item: HttpTypes.AdminInventoryItem
level: InventoryLevelDTO
location: StockLocationDTO
location: VendorExtendedAdminStockLocation
}

const AttributeGridRow = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export const useLocationListTableColumns = () => {

return useMemo(
() => [
columnHelper.accessor("stock_locations.0.name", {
columnHelper.display({
id: "location",
header: t("fields.location"),
cell: ({ getValue }) => {
const locationName = getValue()
cell: ({ row }) => {
const locationName = row.original.stock_locations?.[0]?.name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if this array always has just 1 element, what do you think about mapping the array in cell? if somehow there will be more values, all of them will be displayed

Copy link
Collaborator Author

@sylwia-werner sylwia-werner Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be just one element, but I can map it just in case


if (!locationName) {
return <PlaceholderCell />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,9 @@ interface OperatorInputProps {
currency: CurrencyInfo
placeholder: string
label: string
field: ControllerRenderProps<
CondtionalPriceRuleSchemaType,
`prices.${number}.lte` | `prices.${number}.gte`
>
field:
| ControllerRenderProps<CondtionalPriceRuleSchemaType, `prices.${number}.gte`>
| ControllerRenderProps<CondtionalPriceRuleSchemaType, `prices.${number}.lte`>
}

const OperatorInput = ({
Expand Down
Loading