diff --git a/src/hooks/api/collections.tsx b/src/hooks/api/collections.tsx index c2db6a7c..3c9f7d7a 100644 --- a/src/hooks/api/collections.tsx +++ b/src/hooks/api/collections.tsx @@ -55,7 +55,6 @@ export const useCollections = ( >, "queryFn" | "queryKey" >, - id?: string ) => { const { data, ...rest } = useQuery({ queryKey: collectionsQueryKeys.list(query), @@ -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 } } diff --git a/src/hooks/api/customer-groups.tsx b/src/hooks/api/customer-groups.tsx index 9b0df374..54f0597c 100644 --- a/src/hooks/api/customer-groups.tsx +++ b/src/hooks/api/customer-groups.tsx @@ -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( @@ -50,9 +51,7 @@ export const useCustomerGroups = ( UseQueryOptions< HttpTypes.AdminGetCustomerGroupsParams, FetchError, - HttpTypes.AdminCustomerGroupListResponse & { - customer_group?: any - }, + CustomerGroupListResponse, QueryKey >, "queryFn" | "queryKey" @@ -67,7 +66,7 @@ export const useCustomerGroups = ( queryKey: customerGroupsQueryKeys.list(query), ...options, }) - + const filteredData = filterCustomerGroups( data?.customer_groups, filters, @@ -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, } } diff --git a/src/hooks/api/price-lists.tsx b/src/hooks/api/price-lists.tsx index b339ac65..95184a12 100644 --- a/src/hooks/api/price-lists.tsx +++ b/src/hooks/api/price-lists.tsx @@ -10,6 +10,10 @@ 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" @@ -72,9 +76,9 @@ export const usePriceLists = ( query?: HttpTypes.AdminPriceListListParams, options?: Omit< UseQueryOptions< - HttpTypes.AdminPriceListListResponse, + PriceListListResponse, FetchError, - any, + PriceListListResponse, QueryKey >, "queryKey" | "queryFn" @@ -90,8 +94,12 @@ export const usePriceLists = ( ...options, }) - const price_lists = data?.price_lists?.filter((item: any) => item.price_list) - const count = price_lists?.length || 0 + 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 + return { ...data, price_lists, count, ...rest } } diff --git a/src/hooks/api/promotions.tsx b/src/hooks/api/promotions.tsx index 861fbdc0..ac8787f2 100644 --- a/src/hooks/api/promotions.tsx +++ b/src/hooks/api/promotions.tsx @@ -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 }, diff --git a/src/hooks/api/stock-locations.tsx b/src/hooks/api/stock-locations.tsx index a110ef43..a458e426 100644 --- a/src/hooks/api/stock-locations.tsx +++ b/src/hooks/api/stock-locations.tsx @@ -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( @@ -25,7 +26,7 @@ export const useStockLocation = ( UseQueryOptions< HttpTypes.AdminStockLocationResponse, FetchError, - HttpTypes.AdminStockLocationResponse, + VendorExtendedAdminStockLocationResponse, QueryKey >, "queryKey" | "queryFn" @@ -40,7 +41,7 @@ export const useStockLocation = ( queryKey: stockLocationsQueryKeys.detail(id, query), ...options, }) - + return { ...data, ...rest } } diff --git a/src/hooks/table/columns/use-customer-group-table-columns.tsx b/src/hooks/table/columns/use-customer-group-table-columns.tsx index 0488df16..515397af 100644 --- a/src/hooks/table/columns/use-customer-group-table-columns.tsx +++ b/src/hooks/table/columns/use-customer-group-table-columns.tsx @@ -1,3 +1,4 @@ +import { HttpTypes } from "@medusajs/types" import { createColumnHelper } from "@tanstack/react-table" import { useMemo } from "react" @@ -6,7 +7,6 @@ import { TextCell, TextHeader, } from "../../../components/table/table-cells/common/text-cell" -import { HttpTypes } from "@medusajs/types" const columnHelper = createColumnHelper() @@ -20,9 +20,7 @@ export const useCustomerGroupTableColumns = () => { cell: ({ row }) => { return ( ) }, diff --git a/src/hooks/table/filters/use-product-table-filters.tsx b/src/hooks/table/filters/use-product-table-filters.tsx index 88156ae9..541bcea2 100644 --- a/src/hooks/table/filters/use-product-table-filters.tsx +++ b/src/hooks/table/filters/use-product-table-filters.tsx @@ -8,6 +8,7 @@ const excludeableFields = [ "categories", "product_types", "product_tags", + "sales_channel_id", ] as const export const useProductTableFilters = ( diff --git a/src/lib/addresses.ts b/src/lib/addresses.ts index 3c4b2339..212abf62 100644 --- a/src/lib/addresses.ts +++ b/src/lib/addresses.ts @@ -25,25 +25,26 @@ 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 + 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 + const name = [first_name, last_name].filter(Boolean).join(" ") const formattedAddress: string[] = [] @@ -75,10 +76,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()) } diff --git a/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx b/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx index c920bd5e..07122c9a 100644 --- a/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx +++ b/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx @@ -56,7 +56,7 @@ export const EditCampaignBudgetForm = ({ } ) }) - + return ( @@ -95,7 +95,7 @@ export const EditCampaignBudgetForm = ({ key="usage" min={0} {...field} - value={value} + value={value || undefined} onChange={(e) => { onChange( e.target.value === "" diff --git a/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx b/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx index eb79108a..e0032ff6 100644 --- a/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx +++ b/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx @@ -20,6 +20,7 @@ import { } from "../../../../../lib/data/currencies" import { CampaignFormFields, WithNestedCampaign } from "../../../../../types/campaign" + type CreateCampaignFormFieldsProps = { form: UseFormReturn fieldScope?: string @@ -29,6 +30,7 @@ export const CreateCampaignFormFields = ) => { + const { t } = useTranslation() const { store } = useStore() diff --git a/src/routes/collections/collection-detail/breadcrumb.tsx b/src/routes/collections/collection-detail/breadcrumb.tsx index 677ca48b..2710534e 100644 --- a/src/routes/collections/collection-detail/breadcrumb.tsx +++ b/src/routes/collections/collection-detail/breadcrumb.tsx @@ -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 {collection.title} + return {product_collection.title} } diff --git a/src/routes/collections/collection-metadata/collection-metadata.tsx b/src/routes/collections/collection-metadata/collection-metadata.tsx index 05b0605f..5b1d614e 100644 --- a/src/routes/collections/collection-metadata/collection-metadata.tsx +++ b/src/routes/collections/collection-metadata/collection-metadata.tsx @@ -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) { @@ -17,7 +17,7 @@ export const CollectionMetadata = () => { return ( { 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} + rowHref={(row: any) => `/customer-groups/${row.original.customer_group_id}` + } action={{ label: t("actions.create"), to: "/customer-groups/create", @@ -82,7 +80,7 @@ export const CustomerGroupListTable = () => { ) } -const columnHelper = createDataTableColumnHelper() +const columnHelper = createDataTableColumnHelper() const useColumns = () => { const { t } = useTranslation() @@ -130,7 +128,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"), @@ -139,7 +137,7 @@ const useColumns = () => { return }, }), - columnHelper.accessor("customers", { + columnHelper.accessor("customer_group.customers", { header: t("customers.domain"), cell: ({ row }) => { return ( diff --git a/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx b/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx index 714c8dad..74845f3f 100644 --- a/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx +++ b/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx @@ -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" @@ -10,12 +10,13 @@ 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" import { sanitizeNumberInput } from "../../../../../../lib/sanitize-number-input" type AdjustInventoryFormProps = { item: HttpTypes.AdminInventoryItem level: InventoryLevelDTO - location: StockLocationDTO + location: VendorExtendedAdminStockLocation } const AttributeGridRow = ({ diff --git a/src/routes/inventory/inventory-detail/components/location-levels-table/location-list-table.tsx b/src/routes/inventory/inventory-detail/components/location-levels-table/location-list-table.tsx index 5a3d7d8a..7b7d4f69 100644 --- a/src/routes/inventory/inventory-detail/components/location-levels-table/location-list-table.tsx +++ b/src/routes/inventory/inventory-detail/components/location-levels-table/location-list-table.tsx @@ -22,7 +22,6 @@ export const ItemLocationListTable = ({ fields: "*stock_locations", } ) - const columns = useLocationListTableColumns() const filteredLocationLevels = location_levels?.filter( diff --git a/src/routes/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx b/src/routes/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx index ec01398b..a2c7744f 100644 --- a/src/routes/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx +++ b/src/routes/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx @@ -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?.map((location) => location.name).join(", ") if (!locationName) { return diff --git a/src/routes/locations/common/components/conditional-price-form/conditional-price-form.tsx b/src/routes/locations/common/components/conditional-price-form/conditional-price-form.tsx index 64d4254e..b52e4ae4 100644 --- a/src/routes/locations/common/components/conditional-price-form/conditional-price-form.tsx +++ b/src/routes/locations/common/components/conditional-price-form/conditional-price-form.tsx @@ -401,10 +401,9 @@ interface OperatorInputProps { currency: CurrencyInfo placeholder: string label: string - field: ControllerRenderProps< - CondtionalPriceRuleSchemaType, - `prices.${number}.lte` | `prices.${number}.gte` - > + field: + | ControllerRenderProps + | ControllerRenderProps } const OperatorInput = ({ diff --git a/src/routes/locations/location-detail/components/location-fulfillment-providers-section/location-fulfillment-providers-section.tsx b/src/routes/locations/location-detail/components/location-fulfillment-providers-section/location-fulfillment-providers-section.tsx index 5f7e8e4b..7d567aa2 100644 --- a/src/routes/locations/location-detail/components/location-fulfillment-providers-section/location-fulfillment-providers-section.tsx +++ b/src/routes/locations/location-detail/components/location-fulfillment-providers-section/location-fulfillment-providers-section.tsx @@ -7,12 +7,12 @@ import { ActionMenu } from "../../../../../components/common/action-menu" import { NoRecords } from "../../../../../components/common/empty-table-content" import { IconAvatar } from "../../../../../components/common/icon-avatar" import { formatProvider } from "../../../../../lib/format-provider" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminStockLocation } from "../../../../../types/stock-location" function LocationsFulfillmentProvidersSection({ location, }: { - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation }) { const { t } = useTranslation() diff --git a/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx b/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx index f6428d4f..e874ebf6 100644 --- a/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx +++ b/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx @@ -50,9 +50,10 @@ import { FulfillmentSetType, ShippingOptionPriceType, } from "../../../common/constants" +import { VendorExtendedAdminStockLocation, VendorExtendedAdminFulfillmentSet, VendorExtendedAdminServiceZone } from "../../../../../types/stock-location" type LocationGeneralSectionProps = { - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation } export const LocationGeneralSection = ({ @@ -183,7 +184,7 @@ function ShippingOption({ } type ServiceZoneOptionsProps = { - zone: HttpTypes.AdminServiceZone + zone: VendorExtendedAdminServiceZone locationId: string fulfillmentSetId: string type: FulfillmentSetType @@ -264,7 +265,7 @@ function ServiceZoneOptions({ } type ServiceZoneProps = { - zone: HttpTypes.AdminServiceZone + zone: VendorExtendedAdminServiceZone locationId: string fulfillmentSetId: string type: FulfillmentSetType @@ -435,7 +436,7 @@ function ServiceZone({ } type FulfillmentSetProps = { - fulfillmentSet?: HttpTypes.AdminFulfillmentSet + fulfillmentSet?: VendorExtendedAdminFulfillmentSet locationName: string locationId: string type: FulfillmentSetType @@ -583,7 +584,7 @@ function FulfillmentSet(props: FulfillmentSetProps) { ) } -const Actions = ({ location }: { location: HttpTypes.AdminStockLocation }) => { +const Actions = ({ location }: { location: VendorExtendedAdminStockLocation }) => { const navigate = useNavigate() const { t } = useTranslation() const { mutateAsync } = useDeleteStockLocation(location.id) diff --git a/src/routes/locations/location-detail/components/location-sales-channels-section/locations-sales-channels-section.tsx b/src/routes/locations/location-detail/components/location-sales-channels-section/locations-sales-channels-section.tsx index caaf23af..00c46715 100644 --- a/src/routes/locations/location-detail/components/location-sales-channels-section/locations-sales-channels-section.tsx +++ b/src/routes/locations/location-detail/components/location-sales-channels-section/locations-sales-channels-section.tsx @@ -1,5 +1,5 @@ import { Channels, PencilSquare } from "@medusajs/icons" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminStockLocation } from "../../../../../types/stock-location" import { Container, Heading, Text } from "@medusajs/ui" import { useTranslation } from "react-i18next" @@ -10,7 +10,7 @@ import { ListSummary } from "../../../../../components/common/list-summary" import { useSalesChannels } from "../../../../../hooks/api/sales-channels" type LocationsSalesChannelsSectionProps = { - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation } function LocationsSalesChannelsSection({ diff --git a/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx b/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx index ec18946b..793acd86 100644 --- a/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx +++ b/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminStockLocation } from "../../../../../types/stock-location" import { Button, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -12,7 +12,7 @@ import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useUpdateStockLocation } from "../../../../../hooks/api/stock-locations" type EditLocationFormProps = { - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation } const EditLocationSchema = zod.object({ diff --git a/src/routes/locations/location-fulfillment-providers/components/edit-fulfillment-providers-form/edit-fulfillment-providers-form.tsx b/src/routes/locations/location-fulfillment-providers/components/edit-fulfillment-providers-form/edit-fulfillment-providers-form.tsx index 05464604..d5f502cd 100644 --- a/src/routes/locations/location-fulfillment-providers/components/edit-fulfillment-providers-form/edit-fulfillment-providers-form.tsx +++ b/src/routes/locations/location-fulfillment-providers/components/edit-fulfillment-providers-form/edit-fulfillment-providers-form.tsx @@ -1,4 +1,5 @@ import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminStockLocation } from "../../../../../types/stock-location" import { Button, Checkbox, toast } from "@medusajs/ui" import { keepPreviousData } from "@tanstack/react-query" import { @@ -26,7 +27,7 @@ import { useFulfillmentProvidersTableQuery } from "../../../../../hooks/table/qu import { useDataTable } from "../../../../../hooks/use-data-table" type LocationEditFulfillmentProvidersFormProps = { - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation } const EditFulfillmentProvidersFormSchema = zod.object({ diff --git a/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx b/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx index 6dfad6d1..60e21fef 100644 --- a/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx +++ b/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx @@ -1,5 +1,6 @@ import { zodResolver } from "@hookform/resolvers/zod" import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminStockLocation } from "../../../../../types/stock-location" import { Button, createDataTableColumnHelper, @@ -24,7 +25,7 @@ import { useSalesChannels } from "../../../../../hooks/api/sales-channels" import { useUpdateStockLocationSalesChannels } from "../../../../../hooks/api/stock-locations" type EditSalesChannelsFormProps = { - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation } const EditSalesChannelsSchema = zod.object({ @@ -167,7 +168,7 @@ const useColumns = () => { return useMemo(() => [columnHelper.select(), ...base], [base]) } -function getInitialState(location: HttpTypes.AdminStockLocation) { +function getInitialState(location: VendorExtendedAdminStockLocation) { return ( location.sales_channels?.reduce((acc, curr) => { acc[curr.id] = true diff --git a/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx b/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx index f7d70a76..f9d3a5af 100644 --- a/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx +++ b/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminStockLocation, VendorExtendedAdminFulfillmentSet } from "../../../../../types/stock-location" import { Button, Heading, InlineTip, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -27,9 +27,9 @@ const CreateServiceZoneSchema = z.object({ }) type CreateServiceZoneFormProps = { - fulfillmentSet: HttpTypes.AdminFulfillmentSet + fulfillmentSet: VendorExtendedAdminFulfillmentSet type: FulfillmentSetType - location: HttpTypes.AdminStockLocation + location: VendorExtendedAdminStockLocation } export function CreateServiceZoneForm({ diff --git a/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx b/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx index 50aa6ecd..44a333a5 100644 --- a/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx +++ b/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx @@ -1,4 +1,4 @@ -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminServiceZone } from "../../../../../types/stock-location" import { Button, InlineTip, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -10,7 +10,7 @@ import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useUpdateFulfillmentSetServiceZone } from "../../../../../hooks/api/fulfillment-sets" type EditServiceZoneFormProps = { - zone: HttpTypes.AdminServiceZone + zone: VendorExtendedAdminServiceZone fulfillmentSetId: string locationId: string } diff --git a/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx b/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx index f099fc2c..62f11082 100644 --- a/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx +++ b/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminServiceZone } from "../../../../../types/stock-location" import { Button, Heading, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -25,7 +25,7 @@ const EditeServiceZoneSchema = z.object({ type EditServiceZoneAreasFormProps = { fulfillmentSetId: string locationId: string - zone: HttpTypes.AdminServiceZone + zone: VendorExtendedAdminServiceZone } export function EditServiceZoneAreasForm({ diff --git a/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-option-details-form.tsx b/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-option-details-form.tsx index 8c922b30..266aca7d 100644 --- a/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-option-details-form.tsx +++ b/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-option-details-form.tsx @@ -2,7 +2,7 @@ import { Heading, Input, RadioGroup, Text } from "@medusajs/ui" import { UseFormReturn } from "react-hook-form" import { useTranslation } from "react-i18next" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminServiceZone } from "../../../../../types/stock-location" import { Form } from "../../../../../components/common/form" import { Combobox } from "../../../../../components/inputs/combobox" @@ -17,7 +17,7 @@ import { CreateShippingOptionSchema } from "./schema" type CreateShippingOptionDetailsFormProps = { form: UseFormReturn isReturn?: boolean - zone: HttpTypes.AdminServiceZone + zone: VendorExtendedAdminServiceZone type: FulfillmentSetType } @@ -25,7 +25,7 @@ export const CreateShippingOptionDetailsForm = ({ form, isReturn = false, zone, - type, + type }: CreateShippingOptionDetailsFormProps) => { const { t } = useTranslation() diff --git a/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx b/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx index c4a85a43..6104254a 100644 --- a/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx +++ b/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { HttpTypes } from "@medusajs/types" +import { VendorExtendedAdminServiceZone } from "../../../../../types/stock-location" import { Button, ProgressStatus, ProgressTabs, toast } from "@medusajs/ui" import { useForm, useWatch } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -30,7 +30,7 @@ enum Tab { } type CreateShippingOptionFormProps = { - zone: HttpTypes.AdminServiceZone + zone: VendorExtendedAdminServiceZone locationId: string isReturn?: boolean type: FulfillmentSetType @@ -265,9 +265,6 @@ export function CreateShippingOptionsForm({ zone={zone} isReturn={isReturn} type={type} - locationId={locationId} - fulfillmentProviderOptions={fulfillmentProviderOptions || []} - selectedProviderId={selectedProviderId} /> diff --git a/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx b/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx index bf2b01e2..afb40855 100644 --- a/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx +++ b/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx @@ -10,6 +10,7 @@ import { AdminOrder, AdminOrderChange, AdminReturn, + HttpTypes, } from "@medusajs/types" import { useTranslation } from "react-i18next" @@ -446,10 +447,10 @@ const useActivityItems = (order: AdminOrder): Activity[] => { ), @@ -468,10 +469,10 @@ const useActivityItems = (order: AdminOrder): Activity[] => { ), diff --git a/src/routes/price-lists/common/components/price-list-customer-group-rule-form/price-list-customer-group-rule-form.tsx b/src/routes/price-lists/common/components/price-list-customer-group-rule-form/price-list-customer-group-rule-form.tsx index d5260e9c..13b4c0f3 100644 --- a/src/routes/price-lists/common/components/price-list-customer-group-rule-form/price-list-customer-group-rule-form.tsx +++ b/src/routes/price-lists/common/components/price-list-customer-group-rule-form/price-list-customer-group-rule-form.tsx @@ -66,16 +66,18 @@ export const PriceListCustomerGroupRuleForm = ({ : raw.order : undefined - const { customer_groups, count, isLoading, isError, error } = + const { customer_groups: customerGroupsData, count, isLoading, isError, error } = useCustomerGroups( { ...searchParams, fields: "id,name,customers.id" }, { placeholderData: keepPreviousData, }, - undefined, - sortParam + sortParam ? { sort: sortParam } : undefined ) + const customerGroups = customerGroupsData + ?.map((item) => item.customer_group) + const updater: OnChangeFn = (value) => { const state = typeof value === "function" ? value(rowSelection) : value const currentIds = Object.keys(rowSelection) @@ -86,11 +88,11 @@ export const PriceListCustomerGroupRuleForm = ({ const removedIds = currentIds.filter((id) => !ids.includes(id)) const newCustomerGroups = - customer_groups - ?.filter((cg) => newIds.includes(cg.customer_group.id)) + customerGroups + ?.filter((cg) => newIds.includes(cg.id)) .map((cg) => ({ - id: cg.customer_group.id, - name: cg.customer_group.name!, + id: cg.id, + name: cg.name!, })) || [] const filteredIntermediate = intermediate.filter( @@ -109,12 +111,12 @@ export const PriceListCustomerGroupRuleForm = ({ const columns = useColumns() const { table } = useDataTable({ - data: customer_groups || [], + data: customerGroups || [], columns, count, enablePagination: true, enableRowSelection: true, - getRowId: (row) => row.customer_group_id, + getRowId: (row) => row.id, rowSelection: { state: rowSelection, updater, @@ -139,16 +141,16 @@ export const PriceListCustomerGroupRuleForm = ({ count={count} isLoading={isLoading} filters={filters} - orderBy={[ - { key: "name", label: t("fields.name") }, - { key: "created_at", label: t("fields.createdAt") }, - { key: "updated_at", label: t("fields.updatedAt") }, - ]} layout="fill" pagination search prefix={PREFIX} queryObject={raw} + orderBy={[ + { key: "name", label: t("fields.name") }, + { key: "created_at", label: t("fields.createdAt") }, + { key: "updated_at", label: t("fields.updatedAt") }, + ]} /> diff --git a/src/routes/price-lists/price-list-configuration/price-list-configuration.tsx b/src/routes/price-lists/price-list-configuration/price-list-configuration.tsx index 45ec6cec..b0429691 100644 --- a/src/routes/price-lists/price-list-configuration/price-list-configuration.tsx +++ b/src/routes/price-lists/price-list-configuration/price-list-configuration.tsx @@ -18,14 +18,15 @@ export const PriceListConfiguration = () => { )?.value || ([] as string[]) const { - customer_groups, + customer_groups: customerGroupsData, isPending: isCustomerGroupsPending, isError: isCustomerGroupsError, error: customerGroupsError, } = useCustomerGroups(undefined, { enabled: !!customerGroupIds?.length }) - const initialCustomerGroups = (customer_groups || []) - .map(({ customer_group }) => customer_group) + const customerGroups = customerGroupsData?.map((item) => item.customer_group) + + const initialCustomerGroups = (customerGroups || []) .filter((group) => customerGroupIds.includes(group.id)) const isCustomerGroupsReady = isPending diff --git a/src/routes/price-lists/price-list-detail/components/price-list-configuration-section/price-list-configuration-section.tsx b/src/routes/price-lists/price-list-detail/components/price-list-configuration-section/price-list-configuration-section.tsx index e5722f51..430b50ca 100644 --- a/src/routes/price-lists/price-list-detail/components/price-list-configuration-section/price-list-configuration-section.tsx +++ b/src/routes/price-lists/price-list-detail/components/price-list-configuration-section/price-list-configuration-section.tsx @@ -59,7 +59,7 @@ const CustomerGroupDisplay = ({ (rule) => rule.attribute === "customer.groups.id" )?.value || ([] as string[]) - const { customer_groups, isPending, isError, error } = useCustomerGroups( + const { customer_groups: customerGroupsData, isPending, isError, error } = useCustomerGroups( undefined, { enabled: !!customerGroupIds?.length, @@ -74,12 +74,13 @@ const CustomerGroupDisplay = ({ return null } - if (isPending || !customer_groups) { + if (isPending || !customerGroupsData) { return } - const customerGroups = customer_groups - .map(({ customer_group }) => customer_group) + const flatCustomerGroups = customerGroupsData.map((item) => item.customer_group) + + const filteredCustomerGroups = flatCustomerGroups .filter((group) => customerGroupIds.includes(group.id)) return ( @@ -89,7 +90,7 @@ const CustomerGroupDisplay = ({ ยท group.name!)} + list={filteredCustomerGroups.map((group) => group.name!)} n={1} className="txt-small-plus text-ui-fg-muted" /> diff --git a/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table-actions.tsx b/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table-actions.tsx index 34883100..f5b7ec75 100644 --- a/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table-actions.tsx +++ b/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table-actions.tsx @@ -1,3 +1,4 @@ + import { PencilSquare, Trash } from "@medusajs/icons" import { HttpTypes } from "@medusajs/types" @@ -24,7 +25,7 @@ export const PriceListListTableActions = ({ actions: [ { label: t("actions.edit"), - to: `${priceList.price_list_id}/edit`, + to: `${priceList.id}/edit`, icon: , }, ], diff --git a/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table.tsx b/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table.tsx index 575cef34..326621c5 100644 --- a/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table.tsx +++ b/src/routes/price-lists/price-list-list/components/price-list-list-table/price-list-list-table.tsx @@ -23,7 +23,7 @@ export const PriceListListTable = () => { placeholderData: keepPreviousData, } ) - + const filters = usePricingTableFilters() const columns = usePricingTableColumns() @@ -72,7 +72,7 @@ export const PriceListListTable = () => { ]} queryObject={raw} pageSize={PAGE_SIZE} - navigateTo={(row) => row.original.price_list_id} + navigateTo={(row) => row.original.id} isLoading={isLoading} pagination search diff --git a/src/routes/price-lists/price-list-list/components/price-list-list-table/use-pricing-table-columns.tsx b/src/routes/price-lists/price-list-list/components/price-list-list-table/use-pricing-table-columns.tsx index 75c4d443..ce1e4905 100644 --- a/src/routes/price-lists/price-list-list/components/price-list-list-table/use-pricing-table-columns.tsx +++ b/src/routes/price-lists/price-list-list/components/price-list-list-table/use-pricing-table-columns.tsx @@ -1,4 +1,3 @@ -import { HttpTypes } from "@medusajs/types" import { createColumnHelper } from "@tanstack/react-table" import { useMemo } from "react" import { useTranslation } from "react-i18next" @@ -10,8 +9,9 @@ import { } from "../../../../../components/table/table-cells/common/text-cell" import { getPriceListStatus } from "../../../common/utils" import { PriceListListTableActions } from "./price-list-list-table-actions" +import { ExtendedPriceList } from "../../../../../types/price-list" -const columnHelper = createColumnHelper() +const columnHelper = createColumnHelper() export const usePricingTableColumns = () => { const { t } = useTranslation() @@ -21,7 +21,7 @@ export const usePricingTableColumns = () => { columnHelper.accessor("title", { header: () => , cell: ({ row }) => { - return row.original?.price_list?.title || "-" + return row.original?.title || "-" }, }), columnHelper.accessor("status", { @@ -35,7 +35,7 @@ export const usePricingTableColumns = () => { columnHelper.accessor("prices", { header: t("priceLists.fields.priceOverrides.header"), cell: ({ row }) => { - const prices = row.original?.price_list?.prices?.length || "-" + const prices = row.original?.prices?.length || "-" return }, }), diff --git a/src/routes/price-lists/price-list-prices-add/price-list-prices-add.tsx b/src/routes/price-lists/price-list-prices-add/price-list-prices-add.tsx index f883114b..fc6aae4c 100644 --- a/src/routes/price-lists/price-list-prices-add/price-list-prices-add.tsx +++ b/src/routes/price-lists/price-list-prices-add/price-list-prices-add.tsx @@ -8,10 +8,10 @@ export const PriceListProductsAdd = () => { const { id } = useParams<{ id: string }>() const { price_list, isPending, isError, error } = usePriceList(id!) - const { currencies, regions, pricePreferences, isReady } = + const currencyData = usePriceListCurrencyData() - const ready = isReady && !isPending && !!price_list + const ready = currencyData.isReady && !isPending && !!price_list if (isError) { throw error @@ -22,9 +22,7 @@ export const PriceListProductsAdd = () => { {ready && ( )} diff --git a/src/routes/price-lists/price-list-prices-edit/components/price-list-prices-edit-form/price-list-prices-edit-form.tsx b/src/routes/price-lists/price-list-prices-edit/components/price-list-prices-edit-form/price-list-prices-edit-form.tsx index 4a06d4d0..bf919849 100644 --- a/src/routes/price-lists/price-list-prices-edit/components/price-list-prices-edit-form/price-list-prices-edit-form.tsx +++ b/src/routes/price-lists/price-list-prices-edit/components/price-list-prices-edit-form/price-list-prices-edit-form.tsx @@ -19,9 +19,10 @@ import { PriceListUpdateProductsSchema, } from "../../../common/schemas" import { isProductRow } from "../../../common/utils" +import { ExtendedPriceList } from "../../../../../types/price-list" type PriceListPricesEditFormProps = { - priceList: HttpTypes.AdminPriceList + priceList: ExtendedPriceList products: HttpTypes.AdminProduct[] regions: HttpTypes.AdminRegion[] currencies: HttpTypes.AdminStoreCurrency[] @@ -122,7 +123,7 @@ export const PriceListPricesEditForm = ({ } function initRecord( - priceList: HttpTypes.AdminPriceList, + priceList: ExtendedPriceList, products: HttpTypes.AdminProduct[] ): PriceListUpdateProductsSchema { const record: PriceListUpdateProductsSchema = {} @@ -130,14 +131,12 @@ function initRecord( const variantPrices = priceList.prices?.reduce((variants, price) => { const variantObject = variants[price.price_set.variant.id] || {} - const isRegionPrice = !!price.price_rules.find( - (item) => item.attribute === "region_id" + const regionPrice = price.price_rules.find( + (item: { attribute: string }) => item.attribute === "region_id" ) - if (isRegionPrice) { - const regionId = price.price_rules.find( - (item) => item.attribute === "region_id" - ).value as string + if (!!regionPrice) { + const regionId = regionPrice.value variantObject.region_prices = { ...variantObject.region_prices, diff --git a/src/routes/price-lists/price-list-prices-edit/price-list-prices-edit.tsx b/src/routes/price-lists/price-list-prices-edit/price-list-prices-edit.tsx index c1825817..0aa8ea46 100644 --- a/src/routes/price-lists/price-list-prices-edit/price-list-prices-edit.tsx +++ b/src/routes/price-lists/price-list-prices-edit/price-list-prices-edit.tsx @@ -18,11 +18,11 @@ export const PriceListPricesEdit = () => { error: productError, } = usePriceListProducts(id!) - const { isReady, regions, currencies, pricePreferences } = + const priceListCurrencyData = usePriceListCurrencyData() const ready = - !isLoading && !!price_list && !isProductsLoading && !!products && isReady + !isLoading && !!price_list && !isProductsLoading && !!products && priceListCurrencyData.isReady if (isError) { throw error @@ -44,9 +44,7 @@ export const PriceListPricesEdit = () => { )} diff --git a/src/routes/promotions/common/edit-rules/components/edit-rules-form/edit-rules-form.tsx b/src/routes/promotions/common/edit-rules/components/edit-rules-form/edit-rules-form.tsx index 89a99f84..a131ce41 100644 --- a/src/routes/promotions/common/edit-rules/components/edit-rules-form/edit-rules-form.tsx +++ b/src/routes/promotions/common/edit-rules/components/edit-rules-form/edit-rules-form.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { PromotionDTO, PromotionRuleDTO } from "@medusajs/types" +import { HttpTypes, PromotionRuleDTO } from "@medusajs/types" import { Button } from "@medusajs/ui" import { useState } from "react" import { useForm } from "react-hook-form" @@ -11,7 +11,7 @@ import { RulesFormField } from "../rules-form-field" import { EditRules, EditRulesType } from "./form-schema" type EditPromotionFormProps = { - promotion: PromotionDTO + promotion: HttpTypes.AdminPromotion rules: PromotionRuleDTO[] ruleType: RuleTypeValues handleSubmit: any diff --git a/src/routes/promotions/common/edit-rules/components/edit-rules-form/utils.ts b/src/routes/promotions/common/edit-rules/components/edit-rules-form/utils.ts index 9f59a821..45b5ccfa 100644 --- a/src/routes/promotions/common/edit-rules/components/edit-rules-form/utils.ts +++ b/src/routes/promotions/common/edit-rules/components/edit-rules-form/utils.ts @@ -1,17 +1,34 @@ -import { PromotionRuleResponse } from "@medusajs/types" +import { + ExtendedPromotionRule, + PromotionRuleFormData, +} from "../../../../../../types/promotion" -export const generateRuleAttributes = (rules?: PromotionRuleResponse[]) => - (rules || []).map((rule) => ({ - id: rule.id, - required: rule.required, - field_type: rule.field_type, - disguised: rule.disguised, - attribute: rule.attribute!, - operator: rule.operator!, - values: - rule.field_type === "number" || rule.operator === "eq" - ? typeof rule.values === "object" - ? rule.values[0]?.value - : rule.values - : rule?.values?.map((v: { value: string }) => v.value!), - })) +export const generateRuleAttributes = ( + rules?: ExtendedPromotionRule[] +): PromotionRuleFormData[] => + (rules || []).map((rule): PromotionRuleFormData => { + let values: number | string | string[] + const firstValue = Array.isArray(rule.values) + ? rule.values[0]?.value + : rule.values + + if (rule.field_type === "number") { + values = firstValue ? Number(firstValue) : 0 + } else if (rule.operator === "eq") { + values = firstValue ? String(firstValue) : "" + } else { + values = Array.isArray(rule.values) + ? rule.values.map((v) => String(v.value || "")).filter(Boolean) + : [] + } + + return { + id: rule.id, + required: rule.required, + field_type: rule.field_type, + disguised: rule.disguised, + attribute: rule.attribute || "", + operator: rule.operator || "", + values, + } + }) diff --git a/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/edit-rules-wrapper.tsx b/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/edit-rules-wrapper.tsx index 0e2328a7..6e3df51e 100644 --- a/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/edit-rules-wrapper.tsx +++ b/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/edit-rules-wrapper.tsx @@ -1,9 +1,8 @@ import { CreatePromotionRuleDTO, - PromotionDTO, + HttpTypes, PromotionRuleDTO, PromotionRuleOperatorValues, - PromotionRuleResponse, } from "@medusajs/types" import { useRouteModal } from "../../../../../../components/modals" import { @@ -12,12 +11,13 @@ import { usePromotionUpdateRules, useUpdatePromotion, } from "../../../../../../hooks/api/promotions" +import { ExtendedPromotionRule } from "../../../../../../types/promotion" import { RuleTypeValues } from "../../edit-rules" import { EditRulesForm } from "../edit-rules-form" import { getRuleValue } from "./utils" type EditPromotionFormProps = { - promotion: PromotionDTO + promotion: HttpTypes.AdminPromotion rules: PromotionRuleDTO[] ruleType: RuleTypeValues } @@ -43,10 +43,10 @@ export const EditRulesWrapper = ({ usePromotionUpdateRules(promotion.id, ruleType) const handleSubmit = ( - rulesToRemove?: { id: string; disguised: boolean; attribute: string }[] + rulesToRemove?: { id: string; disguised?: boolean; attribute: string }[] ) => { - return async function (data: { rules: PromotionRuleResponse[] }) { - const applicationMethodData: Record = {} + return async function (data: { rules: ExtendedPromotionRule[] }) { + const applicationMethodData: Record = {} const { rules: allRules = [] } = data const disguisedRules = allRules.filter((rule) => rule.disguised) const disguisedRulesToRemove = @@ -56,22 +56,32 @@ export const EditRulesWrapper = ({ // database, they are currently all under application_method. If more of these are coming // up, abstract this away. for (const rule of disguisedRules) { - applicationMethodData[rule.attribute] = getRuleValue(rule) + const ruleValue = getRuleValue(rule) + applicationMethodData[rule.attribute!] = Array.isArray(ruleValue) + ? ruleValue[0]?.value || null + : ruleValue } for (const rule of disguisedRulesToRemove) { applicationMethodData[rule.attribute] = null } - // This variable will contain the rules that are actual rule objects, without the disguised - // objects const rulesData = allRules.filter((rule) => !rule.disguised) - const rulesToCreate: CreatePromotionRuleDTO[] = rulesData.filter( - (rule) => !("id" in rule) - ) - const rulesToUpdate = rulesData.filter( - (rule: { id: string }) => typeof rule.id === "string" - ) + + const rulesToCreate: CreatePromotionRuleDTO[] = [] + const rulesToUpdate: ExtendedPromotionRule[] = [] + + for (const rule of rulesData) { + if ("id" in rule && typeof rule.id === "string") { + rulesToUpdate.push(rule) + } else { + rulesToCreate.push({ + attribute: rule.attribute!, + operator: rule.operator!, + values: rule.values as unknown as string | string[], + }) + } + } if (Object.keys(applicationMethodData).length) { await updatePromotion({ @@ -79,33 +89,28 @@ export const EditRulesWrapper = ({ } as any) } - rulesToCreate.length && - (await addPromotionRules({ - rules: rulesToCreate.map((rule) => { - return { - attribute: rule.attribute, - operator: rule.operator, - values: rule.values, - } as any - }), - })) + if (rulesToCreate.length) { + await addPromotionRules({ + rules: rulesToCreate, + }) + } - rulesToRemove?.length && - (await removePromotionRules({ - rule_ids: rulesToRemove.map((r) => r.id).filter(Boolean), - })) + if (rulesToRemove?.length) { + await removePromotionRules({ + rules: rulesToRemove.map((r) => r.id).filter(Boolean) as string[], + } as any) + } - rulesToUpdate.length && - (await updatePromotionRules({ - rules: rulesToUpdate.map((rule: PromotionRuleResponse) => { - return { - id: rule.id!, - attribute: rule.attribute, - operator: rule.operator as PromotionRuleOperatorValues, - values: rule.values as unknown as string | string[], - } - }), - })) + if (rulesToUpdate.length) { + await updatePromotionRules({ + rules: rulesToUpdate.map((rule) => ({ + id: rule.id, + attribute: rule.attribute, + operator: rule.operator as PromotionRuleOperatorValues, + values: rule.values as unknown as string | string[], + })), + }) + } handleSuccess() } diff --git a/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/utils.ts b/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/utils.ts index b88d48b9..ed6a9828 100644 --- a/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/utils.ts +++ b/src/routes/promotions/common/edit-rules/components/edit-rules-wrapper/utils.ts @@ -1,6 +1,6 @@ -import { PromotionRuleResponse } from "@medusajs/types" +import { ExtendedPromotionRule } from "../../../../../../types/promotion" -export const getRuleValue = (rule: PromotionRuleResponse) => { +export const getRuleValue = (rule: ExtendedPromotionRule) => { if (rule.field_type === "number") { return parseInt(rule.values as unknown as string) } diff --git a/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx b/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx index a86618fb..90f9e649 100644 --- a/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx +++ b/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx @@ -1,4 +1,4 @@ -import { RuleAttributeOptionsResponse, StoreDTO } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { Input, Select } from "@medusajs/ui" import { useWatch } from "react-hook-form" import { Form } from "../../../../../../components/common/form" @@ -16,11 +16,11 @@ type RuleValueFormFieldType = { name: string operator: string fieldRule: any - attributes: RuleAttributeOptionsResponse[] + attributes: HttpTypes.AdminRuleAttributeOption[] ruleType: "rules" | "target-rules" | "buy-rules" } -const buildFilters = (attribute?: string, store?: StoreDTO) => { +const buildFilters = (attribute?: string, store?: HttpTypes.AdminStore) => { if (!attribute || !store) { return {} } diff --git a/src/routes/promotions/common/edit-rules/components/rules-form-field/constants.ts b/src/routes/promotions/common/edit-rules/components/rules-form-field/constants.ts index 21c70423..6bc3498b 100644 --- a/src/routes/promotions/common/edit-rules/components/rules-form-field/constants.ts +++ b/src/routes/promotions/common/edit-rules/components/rules-form-field/constants.ts @@ -1,4 +1,6 @@ -export const requiredProductRule = { +import { ExtendedPromotionRule } from "../../../../../../types/promotion" + +export const requiredProductRule: ExtendedPromotionRule = { id: "product", attribute: "items.product.id", attribute_label: "Product", diff --git a/src/routes/promotions/common/edit-rules/components/rules-form-field/rules-form-field.tsx b/src/routes/promotions/common/edit-rules/components/rules-form-field/rules-form-field.tsx index 9c047b49..f891b189 100644 --- a/src/routes/promotions/common/edit-rules/components/rules-form-field/rules-form-field.tsx +++ b/src/routes/promotions/common/edit-rules/components/rules-form-field/rules-form-field.tsx @@ -1,5 +1,5 @@ import { XMarkMini } from "@medusajs/icons" -import { PromotionDTO } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { Badge, Button, Heading, IconButton, Select, Text } from "@medusajs/ui" import { forwardRef, Fragment, useEffect } from "react" import { @@ -20,7 +20,7 @@ import { RuleValueFormField } from "../rule-value-form-field" import { requiredProductRule } from "./constants" type RulesFormFieldType = { - promotion?: PromotionDTO + promotion?: HttpTypes.AdminPromotion form: UseFormReturn ruleType: "rules" | "target-rules" | "buy-rules" setRulesToRemove?: any @@ -84,28 +84,29 @@ export const RulesFormField = ({ if (ruleType === "rules" && !fields.length) { form.resetField("rules") - - replace(generateRuleAttributes(rules) as any) + + const formRules = generateRuleAttributes(rules) + replace(formRules) } if (ruleType === "buy-rules" && !fields.length) { form.resetField("application_method.buy_rules") - const rulesToAppend = - promotion?.id || promotionType === "standard" - ? rules - : [...rules, requiredProductRule] - - replace(generateRuleAttributes(rulesToAppend) as any) + const apiRules = promotion?.id || promotionType === "standard" + ? rules || [] + : [...(rules || []), requiredProductRule] + + const formRules = generateRuleAttributes(apiRules) + replace(formRules) } if (ruleType === "target-rules" && !fields.length) { form.resetField("application_method.target_rules") - const rulesToAppend = - promotion?.id || promotionType === "standard" - ? rules - : [...rules, requiredProductRule] - - replace(generateRuleAttributes(rulesToAppend) as any) + const apiRules = promotion?.id || promotionType === "standard" + ? rules || [] + : [...(rules || []), requiredProductRule] + + const formRules = generateRuleAttributes(apiRules) + replace(formRules) } }, [ promotionType, @@ -300,7 +301,7 @@ export const RulesFormField = ({ name={`${scope}.${index}.values`} operator={`${scope}.${index}.operator`} fieldRule={fieldRule} - attributes={attributes} + attributes={attributes || []} ruleType={ruleType} /> @@ -383,7 +384,13 @@ export const RulesFormField = ({ type DisabledAttributeProps = { label: string - field: ControllerRenderProps + field: + | ControllerRenderProps + | ControllerRenderProps + | ControllerRenderProps + | ControllerRenderProps + | ControllerRenderProps + | ControllerRenderProps } /** diff --git a/src/routes/promotions/promotion-detail/components/promotion-conditions-section/promotion-conditions-section.tsx b/src/routes/promotions/promotion-detail/components/promotion-conditions-section/promotion-conditions-section.tsx index 51da24b5..b449d8db 100644 --- a/src/routes/promotions/promotion-detail/components/promotion-conditions-section/promotion-conditions-section.tsx +++ b/src/routes/promotions/promotion-detail/components/promotion-conditions-section/promotion-conditions-section.tsx @@ -1,17 +1,26 @@ import { PencilSquare } from "@medusajs/icons" -import { HttpTypes, PromotionRuleTypes } from "@medusajs/types" +import { PromotionRuleTypes } from "@medusajs/types" import { Badge, Container, Heading } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { ActionMenu } from "../../../../../components/common/action-menu" import { BadgeListSummary } from "../../../../../components/common/badge-list-summary" import { NoRecords } from "../../../../../components/common/empty-table-content" +import { ExtendedPromotionRuleWithValues, FormattedPromotionRuleTypes } from "../../../../../types/promotion" type RuleProps = { - rule: HttpTypes.AdminPromotionRule + rule: ExtendedPromotionRuleWithValues } - function RuleBlock({ rule }: RuleProps) { + const getValuesList = (): string[] => { + if (rule.field_type === "number") { + return Array.isArray(rule.values) + ? rule.values.map((v) => String(v.value || v)) + : [String(rule.values)] + } + return rule.values?.map((v) => v.label || v.value || String(v)).filter(Boolean) || [] + } + return (
@@ -30,11 +39,7 @@ function RuleBlock({ rule }: RuleProps) { v.label) - } + list={getValuesList()} />
@@ -42,8 +47,8 @@ function RuleBlock({ rule }: RuleProps) { } type PromotionConditionsSectionProps = { - rules: HttpTypes.AdminPromotionRule[] - ruleType: PromotionRuleTypes + rules: ExtendedPromotionRuleWithValues[] + ruleType: FormattedPromotionRuleTypes } export const PromotionConditionsSection = ({ @@ -51,8 +56,8 @@ export const PromotionConditionsSection = ({ ruleType, }: PromotionConditionsSectionProps) => { const { t } = useTranslation() - - const translationKey = `promotions.fields.conditions.${ruleType === "target_rules" ? "target-rules" : "buy-rules"}.title` as const + const translationKey = `promotions.fields.conditions.${ruleType}.title` as const + return (
diff --git a/src/routes/promotions/promotion-detail/promotion-detail.tsx b/src/routes/promotions/promotion-detail/promotion-detail.tsx index abaa384d..9c7a4bbf 100644 --- a/src/routes/promotions/promotion-detail/promotion-detail.tsx +++ b/src/routes/promotions/promotion-detail/promotion-detail.tsx @@ -49,15 +49,18 @@ export const PromotionDetail = () => { > - + {promotion.type === "buyget" && ( )} diff --git a/src/routes/promotions/promotion-list/components/promotion-list-table/promotion-list-table.tsx b/src/routes/promotions/promotion-list/components/promotion-list-table/promotion-list-table.tsx index c89e0b72..c2119138 100644 --- a/src/routes/promotions/promotion-list/components/promotion-list-table/promotion-list-table.tsx +++ b/src/routes/promotions/promotion-list/components/promotion-list-table/promotion-list-table.tsx @@ -1,5 +1,5 @@ import { PencilSquare, Trash } from "@medusajs/icons" -import { HttpTypes, PromotionDTO } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { Button, Container, Heading, usePrompt } from "@medusajs/ui" import { createColumnHelper } from "@tanstack/react-table" import { useMemo } from "react" @@ -90,7 +90,7 @@ export const PromotionListTable = () => { ) } -const PromotionActions = ({ promotion }: { promotion: PromotionDTO }) => { +const PromotionActions = ({ promotion }: { promotion: HttpTypes.AdminPromotion }) => { const { t } = useTranslation() const prompt = usePrompt() const navigate = useNavigate() @@ -147,7 +147,7 @@ const PromotionActions = ({ promotion }: { promotion: PromotionDTO }) => { ) } -const columnHelper = createColumnHelper() +const columnHelper = createColumnHelper() const useColumns = () => { const base = usePromotionTableColumns() diff --git a/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx b/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx index 4d5de128..8004c758 100644 --- a/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx +++ b/src/routes/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx @@ -63,7 +63,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => { const { inventory_items } = useInventoryItems({ fields: "*location_levels", - q: inventorySearch, + q: inventorySearch ?? undefined, }) const inventoryItemId = form.watch("inventory_item_id") diff --git a/src/routes/reservations/reservation-create/reservation-create.tsx b/src/routes/reservations/reservation-create/reservation-create.tsx index ab724060..a944a756 100644 --- a/src/routes/reservations/reservation-create/reservation-create.tsx +++ b/src/routes/reservations/reservation-create/reservation-create.tsx @@ -10,7 +10,7 @@ export const ReservationCreate = () => { return ( - + ) } diff --git a/src/routes/reservations/reservation-detail/components/reservation-general-section/reservation-general-section.tsx b/src/routes/reservations/reservation-detail/components/reservation-general-section/reservation-general-section.tsx index c6ecbee2..21b7b893 100644 --- a/src/routes/reservations/reservation-detail/components/reservation-general-section/reservation-general-section.tsx +++ b/src/routes/reservations/reservation-detail/components/reservation-general-section/reservation-general-section.tsx @@ -1,8 +1,7 @@ -import { AdminReservationResponse } from "@medusajs/types" +import { AdminReservationResponse, HttpTypes } from "@medusajs/types" import { Container, Heading } from "@medusajs/ui" import { ActionMenu } from "../../../../../components/common/action-menu" -import { InventoryTypes } from "@medusajs/types" import { PencilSquare } from "@medusajs/icons" import { SectionRow } from "../../../../../components/common/section" import { useInventoryItem } from "../../../../../hooks/api/inventory" @@ -28,7 +27,7 @@ export const ReservationGeneralSection = ({ const { stock_location: location } = useStockLocation(reservation.location_id) const locationLevel = inventoryItem?.location_levels?.find( - (l: InventoryTypes.InventoryLevelDTO) => + (l: HttpTypes.AdminInventoryLevel) => l.location_id === reservation.location_id ) diff --git a/src/routes/tax-regions/common/components/target-form/target-form.tsx b/src/routes/tax-regions/common/components/target-form/target-form.tsx index 0a5df53e..4767d456 100644 --- a/src/routes/tax-regions/common/components/target-form/target-form.tsx +++ b/src/routes/tax-regions/common/components/target-form/target-form.tsx @@ -46,6 +46,7 @@ import { import { useDataTable } from "../../../../../hooks/use-data-table" import { TaxRateRuleReferenceType } from "../../constants" import { TaxRateRuleReference } from "../../schemas" +import { CustomerGroupData } from "../../../../orders/common/customerGroupFiltering" type TargetFormProps = { referenceType: TaxRateRuleReferenceType @@ -140,8 +141,6 @@ const CustomerGroupTable = ({ intermediate, setIntermediate, }: TableImplementationProps) => { - const { t } = useTranslation() - const [rowSelection, setRowSelection] = useState(initialRowState) @@ -167,8 +166,8 @@ const CustomerGroupTable = ({ const newCustomerGroups = customer_groups - ?.filter((cg) => newIds.includes(cg.id)) - .map((cg) => ({ value: cg.id, label: cg.name! })) || [] + ?.filter((cg) => newIds.includes(cg.customer_group_id)) + .flatMap((cg) => ({ value: cg.customer_group_id, label: cg.customer_group.name! })) || [] const filteredIntermediate = intermediate.filter( (cg) => !removedIds.includes(cg.value) @@ -187,7 +186,7 @@ const CustomerGroupTable = ({ count, enablePagination: true, enableRowSelection: true, - getRowId: (row) => row.id, + getRowId: (row) => row.customer_group_id, rowSelection: { state: rowSelection, updater, @@ -208,11 +207,6 @@ const CustomerGroupTable = ({ count={count} isLoading={isLoading} filters={filters} - orderBy={[ - { key: "name", label: t("fields.name") }, - { key: "created_at", label: t("fields.createdAt") }, - { key: "updated_at", label: t("fields.updatedAt") }, - ]} layout="fill" pagination search @@ -222,7 +216,7 @@ const CustomerGroupTable = ({ ) } -const cgColumnHelper = createColumnHelper() +const cgColumnHelper = createColumnHelper() const useGroupColumns = () => { const base = useCustomerGroupTableColumns() @@ -418,7 +412,7 @@ const ProductCollectionTable = ({ prefix: PREFIX_PRODUCT_COLLECTION, }) - const { collections, count, isLoading, isError, error } = useCollections( + const { product_collections: collections, count, isLoading, isError, error } = useCollections( searchParams, { placeholderData: keepPreviousData, diff --git a/src/routes/tax-regions/common/components/tax-override-card/tax-override-card.tsx b/src/routes/tax-regions/common/components/tax-override-card/tax-override-card.tsx index ba27fe0f..93b1fa2d 100644 --- a/src/routes/tax-regions/common/components/tax-override-card/tax-override-card.tsx +++ b/src/routes/tax-regions/common/components/tax-override-card/tax-override-card.tsx @@ -378,5 +378,13 @@ const useReferenceValues = ( // isError: customerGroups.isError, // error: customerGroups.error, // } + default: + return { + labels: undefined, + isPending: false, + additional: 0, + isError: false, + error: null, + } } } diff --git a/src/routes/tax-regions/common/constants.ts b/src/routes/tax-regions/common/constants.ts index 5775902b..4a44f5c5 100644 --- a/src/routes/tax-regions/common/constants.ts +++ b/src/routes/tax-regions/common/constants.ts @@ -1,7 +1,7 @@ export enum TaxRateRuleReferenceType { PRODUCT = "product", PRODUCT_TYPE = "product_type", - // PRODUCT_COLLECTION = "product_collection", - // PRODUCT_TAG = "product_tag", - // CUSTOMER_GROUP = "customer_group", + PRODUCT_COLLECTION = "product_collection", + PRODUCT_TAG = "product_tag", + CUSTOMER_GROUP = "customer_group", } diff --git a/src/routes/tax-regions/tax-region-create/components/tax-region-create-form/tax-region-create-form.tsx b/src/routes/tax-regions/tax-region-create/components/tax-region-create-form/tax-region-create-form.tsx index c3f41b50..d699a72e 100644 --- a/src/routes/tax-regions/tax-region-create/components/tax-region-create-form/tax-region-create-form.tsx +++ b/src/routes/tax-regions/tax-region-create/components/tax-region-create-form/tax-region-create-form.tsx @@ -55,7 +55,7 @@ export const TaxRegionCreateForm = ({ parentId }: TaxRegionCreateFormProps) => { values.rate?.value === "" ? undefined : parseFloat(values.rate.value!), - code: values.code, + code: values.code || "", } : undefined diff --git a/src/routes/tax-regions/tax-region-metadata/index.ts b/src/routes/tax-regions/tax-region-metadata/index.ts deleted file mode 100644 index f5ec5b29..00000000 --- a/src/routes/tax-regions/tax-region-metadata/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { TaxRegionMetadata as Component } from "./tax-region-metadata.tsx" diff --git a/src/routes/tax-regions/tax-region-metadata/tax-region-metadata.tsx b/src/routes/tax-regions/tax-region-metadata/tax-region-metadata.tsx deleted file mode 100644 index d66f489b..00000000 --- a/src/routes/tax-regions/tax-region-metadata/tax-region-metadata.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import { useParams } from "react-router-dom" - -import { useTaxRegion } from "../../../hooks/api" -import { MetadataForm } from "../../../components/forms/metadata-form" -import { RouteDrawer } from "../../../components/modals" - -/** - * TODO: Tax region update endpoint is missing - */ - -export const TaxRegionMetadata = () => { - const { id } = useParams() - - const { tax_region, isPending, isError, error } = useTaxRegion(id) - const { mutateAsync, isPending: isMutating } = {} // useUpdateTaxRegion(id) - - if (isError) { - throw error - } - - return ( - - - - ) -} diff --git a/src/routes/tax-regions/tax-region-tax-override-create/components/tax-region-override-create-form/tax-region-tax-override-create.tsx b/src/routes/tax-regions/tax-region-tax-override-create/components/tax-region-override-create-form/tax-region-tax-override-create.tsx index c46ddce0..66ba4e4e 100644 --- a/src/routes/tax-regions/tax-region-tax-override-create/components/tax-region-override-create-form/tax-region-tax-override-create.tsx +++ b/src/routes/tax-regions/tax-region-tax-override-create/components/tax-region-override-create-form/tax-region-tax-override-create.tsx @@ -201,6 +201,8 @@ export const TaxRegionCreateTaxOverrideForm = ({ // return productTags // case TaxRateRuleReferenceType.CUSTOMER_GROUP: // return customerGroups + default: + return products } } @@ -227,31 +229,32 @@ export const TaxRegionCreateTaxOverrideForm = ({ // }, ] - const searchPlaceholders = { + const searchPlaceholders: Record = { [TaxRateRuleReferenceType.PRODUCT]: t( "taxRegions.fields.targets.placeholders.product" ), [TaxRateRuleReferenceType.PRODUCT_TYPE]: t( "taxRegions.fields.targets.placeholders.productType" ), - // [TaxRateRuleReferenceType.PRODUCT_COLLECTION]: t( - // "taxRegions.fields.targets.placeholders.productCollection" - // ), - // [TaxRateRuleReferenceType.PRODUCT_TAG]: t( - // "taxRegions.fields.targets.placeholders.productTag" - // ), - // [TaxRateRuleReferenceType.CUSTOMER_GROUP]: t( - // "taxRegions.fields.targets.placeholders.customerGroup" - // ), + [TaxRateRuleReferenceType.PRODUCT_COLLECTION]: t( + "taxRegions.fields.targets.placeholders.product" + ), + [TaxRateRuleReferenceType.PRODUCT_TAG]: t( + "taxRegions.fields.targets.placeholders.product" + ), + [TaxRateRuleReferenceType.CUSTOMER_GROUP]: t( + "taxRegions.fields.targets.placeholders.product" + ), } const getFieldHandler = (type: TaxRateRuleReferenceType) => { - const { fields, remove, append } = getControls(type) + const controls = getControls(type) + const { fields, remove, append } = controls const modalId = getStackedModalId(type) return (references: TaxRateRuleReference[]) => { if (!references.length) { - form.setValue(type, [], { + form.setValue(type as "product" | "product_type", [], { shouldDirty: true, }) setIsOpen(modalId, false) @@ -280,10 +283,11 @@ export const TaxRegionCreateTaxOverrideForm = ({ ]) const disableRule = (type: TaxRateRuleReferenceType) => { - form.setValue(type, [], { + form.setValue(type as "product" | "product_type", [], { shouldDirty: true, }) - form.setValue(`enabled_rules.${type}`, false, { + + form.setValue(`enabled_rules.${type}` as "enabled_rules.product" | "enabled_rules.product_type", false, { shouldDirty: true, }) @@ -291,10 +295,10 @@ export const TaxRegionCreateTaxOverrideForm = ({ } const enableRule = (type: TaxRateRuleReferenceType) => { - form.setValue(`enabled_rules.${type}`, true, { + form.setValue(`enabled_rules.${type}` as "enabled_rules.product" | "enabled_rules.product_type", true, { shouldDirty: true, }) - form.setValue(type, [], { + form.setValue(type as "product" | "product_type", [], { shouldDirty: true, }) @@ -308,7 +312,7 @@ export const TaxRegionCreateTaxOverrideForm = ({ const addRule = () => { const firstDisabledRule = Object.keys(watchedEnabledRules).find( - (key) => !watchedEnabledRules[key as TaxRateRuleReferenceType] + (key) => !watchedEnabledRules[key as keyof typeof watchedEnabledRules] ) if (firstDisabledRule) { @@ -317,7 +321,7 @@ export const TaxRegionCreateTaxOverrideForm = ({ } const visibleRuleTypes = referenceTypeOptions - .filter((option) => watchedEnabledRules[option.value]) + .filter((option) => watchedEnabledRules[option.value as keyof typeof watchedEnabledRules]) .sort((a, b) => { const orderArray = Array.from(displayOrder) return orderArray.indexOf(b.value) - orderArray.indexOf(a.value) @@ -498,7 +502,7 @@ export const TaxRegionCreateTaxOverrideForm = ({
= { [TaxRateRuleReferenceType.PRODUCT]: t( "taxRegions.fields.targets.placeholders.product" ), [TaxRateRuleReferenceType.PRODUCT_TYPE]: t( "taxRegions.fields.targets.placeholders.productType" ), - // [TaxRateRuleReferenceType.PRODUCT_COLLECTION]: t( - // "taxRegions.fields.targets.placeholders.productCollection" - // ), - // [TaxRateRuleReferenceType.PRODUCT_TAG]: t( - // "taxRegions.fields.targets.placeholders.productTag" - // ), - // [TaxRateRuleReferenceType.CUSTOMER_GROUP]: t( - // "taxRegions.fields.targets.placeholders.customerGroup" - // ), + [TaxRateRuleReferenceType.PRODUCT_COLLECTION]: t( + "taxRegions.fields.targets.placeholders.product" + ), + [TaxRateRuleReferenceType.PRODUCT_TAG]: t( + "taxRegions.fields.targets.placeholders.product" + ), + [TaxRateRuleReferenceType.CUSTOMER_GROUP]: t( + "taxRegions.fields.targets.placeholders.product" + ), } const getFieldHandler = (type: TaxRateRuleReferenceType) => { - const { fields, remove, append } = getControls(type) + const controls = getControls(type) + const { fields, remove, append } = controls const modalId = getStackedModalId(type) return (references: TaxRateRuleReference[]) => { if (!references.length) { - form.setValue(type, [], { + form.setValue(type as "product" | "product_type", [], { shouldDirty: true, }) setIsOpen(modalId, false) @@ -282,10 +285,10 @@ export const TaxRegionTaxOverrideEditForm = ({ ]) const disableRule = (type: TaxRateRuleReferenceType) => { - form.setValue(type, [], { + form.setValue(type as "product" | "product_type", [], { shouldDirty: true, }) - form.setValue(`enabled_rules.${type}`, false, { + form.setValue(`enabled_rules.${type}` as "enabled_rules.product" | "enabled_rules.product_type", false, { shouldDirty: true, }) @@ -293,10 +296,10 @@ export const TaxRegionTaxOverrideEditForm = ({ } const enableRule = (type: TaxRateRuleReferenceType) => { - form.setValue(`enabled_rules.${type}`, true, { + form.setValue(`enabled_rules.${type}` as "enabled_rules.product" | "enabled_rules.product_type", true, { shouldDirty: true, }) - form.setValue(type, [], { + form.setValue(type as "product" | "product_type", [], { shouldDirty: true, }) @@ -310,7 +313,7 @@ export const TaxRegionTaxOverrideEditForm = ({ const addRule = () => { const firstDisabledRule = Object.keys(watchedEnabledRules).find( - (key) => !watchedEnabledRules[key as TaxRateRuleReferenceType] + (key) => !watchedEnabledRules[key as keyof typeof watchedEnabledRules] ) if (firstDisabledRule) { @@ -319,7 +322,7 @@ export const TaxRegionTaxOverrideEditForm = ({ } const visibleRuleTypes = referenceTypeOptions - .filter((option) => watchedEnabledRules[option.value]) + .filter((option) => watchedEnabledRules[option.value as keyof typeof watchedEnabledRules]) .sort((a, b) => { const orderArray = Array.from(displayOrder) return orderArray.indexOf(a.value) - orderArray.indexOf(b.value) @@ -469,7 +472,7 @@ export const TaxRegionTaxOverrideEditForm = ({
{ diff --git a/src/routes/tax-regions/tax-region-tax-rate-edit/components/tax-region-tax-rate-edit-form/tax-region-tax-rate-edit-form.tsx b/src/routes/tax-regions/tax-region-tax-rate-edit/components/tax-region-tax-rate-edit-form/tax-region-tax-rate-edit-form.tsx index 7332db17..c1661699 100644 --- a/src/routes/tax-regions/tax-region-tax-rate-edit/components/tax-region-tax-rate-edit-form/tax-region-tax-rate-edit-form.tsx +++ b/src/routes/tax-regions/tax-region-tax-rate-edit/components/tax-region-tax-rate-edit-form/tax-region-tax-rate-edit-form.tsx @@ -52,7 +52,7 @@ export const TaxRegionTaxRateEditForm = ({ await mutateAsync( { name: values.name, - code: values.code, + code: values.code || taxRate.code, rate: values.rate?.float, is_combinable: values.is_combinable, }, diff --git a/src/types/customer-group.ts b/src/types/customer-group.ts new file mode 100644 index 00000000..5077b3ed --- /dev/null +++ b/src/types/customer-group.ts @@ -0,0 +1,8 @@ +import { CustomerGroupData } from "../routes/orders/common/customerGroupFiltering" + +export interface CustomerGroupListResponse { + customer_groups: CustomerGroupData[] + count: number + offset: number + limit: number +} diff --git a/src/types/price-list.ts b/src/types/price-list.ts new file mode 100644 index 00000000..0cbe1a85 --- /dev/null +++ b/src/types/price-list.ts @@ -0,0 +1,34 @@ +import { HttpTypes } from "@medusajs/types" + +export interface ExtendedPriceListPrice extends HttpTypes.AdminPriceListPrice { + price_set: { + id: string + variant: { + id: string + } + } + price_rules: Array<{ + attribute: string + value: string | number + }> +} + +export interface ExtendedPriceList extends Omit { + prices: ExtendedPriceListPrice[] + price_list_rules: Array<{ + value: string[] + attribute: string + }> +} + +export interface PriceListData { + price_list_id: string + price_list: ExtendedPriceList +} + +export interface PriceListListResponse { + price_lists: PriceListData[] + count: number + offset: number + limit: number +} diff --git a/src/types/promotion.ts b/src/types/promotion.ts new file mode 100644 index 00000000..6e4fff06 --- /dev/null +++ b/src/types/promotion.ts @@ -0,0 +1,33 @@ +import { HttpTypes } from "@medusajs/types" + +export interface ExtendedPromotionRuleValue { + id?: string + value?: string + label?: string +} + +export interface ExtendedPromotionRule extends Omit { + field_type?: string + required?: boolean + disguised?: boolean + hydrate?: boolean + attribute_label?: string + operator_label?: string + values: ExtendedPromotionRuleValue[] +} + +// Alias for consistency +export interface ExtendedPromotionRuleWithValues extends ExtendedPromotionRule { +} + +export interface PromotionRuleFormData { + id?: string + attribute: string + operator: string + values: number | string | string[] + required?: boolean + disguised?: boolean + field_type?: string +} + +export type FormattedPromotionRuleTypes = "buy-rules" | "target-rules" | "rules" \ No newline at end of file diff --git a/src/types/stock-location.ts b/src/types/stock-location.ts new file mode 100644 index 00000000..e3f6e9ae --- /dev/null +++ b/src/types/stock-location.ts @@ -0,0 +1,52 @@ +import { HttpTypes } from "@medusajs/types" + +export interface VendorExtendedAdminStockLocationAddress extends HttpTypes.AdminStockLocationAddress { + metadata: Record | null + created_at: string + updated_at: string + deleted_at: string | null + } + + export interface VendorExtendedAdminFulfillmentProvider extends HttpTypes.AdminFulfillmentProvider { + created_at: string + updated_at: string + deleted_at: string | null + } + + export interface VendorExtendedAdminServiceZone { + id: string + name: string + fulfillment_set_id: string + fulfillment_set?: VendorExtendedAdminFulfillmentSet + geo_zones: HttpTypes.AdminGeoZone[] + shipping_options: HttpTypes.AdminShippingOption[] + metadata: Record | null + created_at: string + updated_at: string + deleted_at: string | null + } + + export interface VendorExtendedAdminFulfillmentSet { + id: string + name: string + type: string + location?: VendorExtendedAdminStockLocation + service_zones: VendorExtendedAdminServiceZone[] + created_at: string + updated_at: string + deleted_at: string | null + } + + export interface VendorExtendedAdminStockLocation { + id: string + name: string + address_id: string + address?: VendorExtendedAdminStockLocationAddress + sales_channels?: HttpTypes.AdminSalesChannel[] + fulfillment_providers?: VendorExtendedAdminFulfillmentProvider[] + fulfillment_sets?: VendorExtendedAdminFulfillmentSet[] + } + + export interface VendorExtendedAdminStockLocationResponse { + stock_location: VendorExtendedAdminStockLocation + } \ No newline at end of file