Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/hooks/api/promotions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpTypes } from "@medusajs/types"
import { FetchError } from "@medusajs/js-sdk"
import { HttpTypes } from "@medusajs/types"
import {
QueryKey,
useMutation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type RuleValueFormFieldType = {
ruleType: "rules" | "target-rules" | "buy-rules"
}

type VendorPromotionRuleValueParams = HttpTypes.AdminGetPromotionsRuleValueParams & {
promotion_type?: string
application_method_type?: string
}

const buildFilters = (attribute?: string, store?: HttpTypes.AdminStore) => {
if (!attribute || !store) {
return {}
Expand Down Expand Up @@ -49,10 +54,25 @@ export const RuleValueFormField = ({
)

const { store, isLoading: isStoreLoading } = useStore()

const promotionType = useWatch({
control: form.control,
name: "type",
})

const applicationMethodType = useWatch({
control: form.control,
name: "application_method.type",
})

const { values: options = [] } = usePromotionRuleValues(
ruleType,
attribute?.id!,
buildFilters(attribute?.id, store),
{
...buildFilters(attribute?.id, store),
promotion_type: promotionType,
application_method_type: applicationMethodType,
} as VendorPromotionRuleValueParams,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we set VendorPromotionRuleValueParams as the type of the query param in usePromotionRuleValues instead of type-casting it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you are right

{
enabled:
!!attribute?.id &&
Expand Down