Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): Add FE validation for conditional prices #10523

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/selfish-coats-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

fix(dashboard): Add FE validation for conditional prices
95 changes: 32 additions & 63 deletions packages/admin/dashboard/src/i18n/translations/$schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2978,15 +2978,11 @@
"type": "string"
}
},
"required": [
"stockedQuantity"
],
"required": ["stockedQuantity"],
"additionalProperties": false
}
},
"required": [
"errors"
],
"required": ["errors"],
"additionalProperties": false
},
"toast": {
Expand Down Expand Up @@ -3792,10 +3788,7 @@
"type": "string"
}
},
"required": [
"title",
"requestSuccess"
],
"required": ["title", "requestSuccess"],
"additionalProperties": false
},
"shippingAddress": {
Expand All @@ -3808,10 +3801,7 @@
"type": "string"
}
},
"required": [
"title",
"requestSuccess"
],
"required": ["title", "requestSuccess"],
"additionalProperties": false
},
"billingAddress": {
Expand All @@ -3824,18 +3814,11 @@
"type": "string"
}
},
"required": [
"title",
"requestSuccess"
],
"required": ["title", "requestSuccess"],
"additionalProperties": false
}
},
"required": [
"email",
"shippingAddress",
"billingAddress"
],
"required": ["email", "shippingAddress", "billingAddress"],
"additionalProperties": false
},
"returns": {
Expand Down Expand Up @@ -4987,11 +4970,7 @@
"type": "string"
}
},
"required": [
"shipping_address",
"billing_address",
"email"
],
"required": ["shipping_address", "billing_address", "email"],
"additionalProperties": false
}
},
Expand Down Expand Up @@ -5560,9 +5539,7 @@
"type": "string"
}
},
"required": [
"cartItemTotal"
],
"required": ["cartItemTotal"],
"additionalProperties": false
},
"summaries": {
Expand All @@ -5578,11 +5555,7 @@
"type": "string"
}
},
"required": [
"range",
"greaterThan",
"lessThan"
],
"required": ["range", "greaterThan", "lessThan"],
"additionalProperties": false
},
"actions": {
Expand All @@ -5595,10 +5568,7 @@
"type": "string"
}
},
"required": [
"addPrice",
"manageConditionalPrices"
],
"required": ["addPrice", "manageConditionalPrices"],
"additionalProperties": false
},
"rules": {
Expand All @@ -5614,11 +5584,7 @@
"type": "string"
}
},
"required": [
"amount",
"gte",
"lte"
],
"required": ["amount", "gte", "lte"],
"additionalProperties": false
},
"customRules": {
Expand All @@ -5640,13 +5606,7 @@
"type": "string"
}
},
"required": [
"label",
"tooltip",
"eq",
"gt",
"lt"
],
"required": ["label", "tooltip", "eq", "gt", "lt"],
"additionalProperties": false
},
"errors": {
Expand All @@ -5660,12 +5620,20 @@
},
"minGreaterThanMax": {
"type": "string"
},
"duplicateAmount": {
"type": "string"
},
"overlappingConditions": {
"type": "string"
}
},
"required": [
"amountRequired",
"minOrMaxRequired",
"minGreaterThanMax"
"minGreaterThanMax",
"duplicateAmount",
"overlappingConditions"
],
"additionalProperties": false
}
Expand Down Expand Up @@ -8842,16 +8810,6 @@
"deleteSalesChannelWarning": {
"type": "string"
},
"tooltip": {
"type": "object",
"properties": {
"cannotDeleteDefault": {
"type": "string"
}
},
"required": ["cannotDeleteDefault"],
"additionalProperties": false
},
"toast": {
"type": "object",
"properties": {
Expand All @@ -8868,6 +8826,16 @@
"required": ["create", "update", "delete"],
"additionalProperties": false
},
"tooltip": {
"type": "object",
"properties": {
"cannotDeleteDefault": {
"type": "string"
}
},
"required": ["cannotDeleteDefault"],
"additionalProperties": false
},
"products": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -8916,6 +8884,7 @@
"productAlreadyAdded",
"deleteSalesChannelWarning",
"toast",
"tooltip",
"products"
],
"additionalProperties": false
Expand Down
4 changes: 3 additions & 1 deletion packages/admin/dashboard/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,9 @@
"errors": {
"amountRequired": "Shipping option price is required",
"minOrMaxRequired": "At least one of minimum or maximum cart item total must be provided",
"minGreaterThanMax": "Minimum cart item total must be less than or equal to maximum cart item total"
"minGreaterThanMax": "Minimum cart item total must be less than or equal to maximum cart item total",
"duplicateAmount": "Shipping option price must be unique for each condition",
"overlappingConditions": "Conditions must be unique across all price rules"
}
},
"fields": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
Badge,
Button,
clx,
CurrencyInput,
Heading,
IconButton,
Expand Down Expand Up @@ -110,14 +111,28 @@ export const ConditionalPriceForm = ({
remove(index)
}

const handleOnSubmit = conditionalPriceForm.handleSubmit((values) => {
setFormValue(name, values.prices, {
shouldDirty: true,
shouldValidate: true,
shouldTouch: true,
})
onCloseConditionalPricesModal()
})
const handleOnSubmit = conditionalPriceForm.handleSubmit(
(values) => {
setFormValue(name, values.prices, {
shouldDirty: true,
shouldValidate: true,
shouldTouch: true,
})
onCloseConditionalPricesModal()
},
(e) => {
const indexesWithErrors = Object.keys(e.prices || {})
setValue((prev) => {
const values = new Set(prev)

indexesWithErrors.forEach((index) => {
values.add(getRuleValue(Number(index)))
})

return Array.from(values)
})
}
)

// Intercept the Cmd + Enter key to only save the inner form.
const handleOnKeyDown = (event: React.KeyboardEvent<HTMLFormElement>) => {
Expand Down Expand Up @@ -255,7 +270,9 @@ const ConditionalPriceItem = ({
return (
<Accordion.Item
value={getRuleValue(index)}
className="bg-ui-bg-component shadow-elevation-card-rest rounded-lg"
className={clx(
"bg-ui-bg-component shadow-elevation-card-rest rounded-lg"
)}
>
<Accordion.Trigger asChild>
<div className="group/trigger flex w-full cursor-pointer items-start justify-between gap-x-2 p-3">
Expand Down
Loading
Loading