fix(dashboard): allow to unset PL rule (#9276)

**What**
- unset customer groups rule if no groups are selected
- preserve other rules when updating a PL

---

CLOSES https://github.com/medusajs/medusa/issues/9376
This commit is contained in:
Frane Polić authored and GitHub committed 2024-10-04 09:09:27 +00:00
1 parent bc8de8e5b1
commit b2a8c897f7
1 file changed
+10 -3
@@ -90,13 +90,20 @@ export const PriceListConfigurationForm = ({
const { mutateAsync } = useUpdatePriceList(priceList.id) const { mutateAsync } = useUpdatePriceList(priceList.id)
const handleSubmit = form.handleSubmit(async (values) => { const handleSubmit = form.handleSubmit(async (values) => {
const groupIds = values.customer_group_id.map((group) => group.id)
const rules = { ...priceList.rules } // preserve other rules set on the PL
if (groupIds.length) {
rules["customer_group_id"] = groupIds
} else {
delete rules["customer_group_id"]
}
await mutateAsync( await mutateAsync(
{ {
starts_at: values.starts_at?.toISOString() || null, starts_at: values.starts_at?.toISOString() || null,
ends_at: values.ends_at?.toISOString() || null, ends_at: values.ends_at?.toISOString() || null,
rules: { rules: rules,
customer_group_id: values.customer_group_id.map((group) => group.id),
},
}, },
{ {
onSuccess: () => { onSuccess: () => {