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ć
2024-10-04 11:09:27 +02:00
committed by GitHub
parent bc8de8e5b1
commit b2a8c897f7

View File

@@ -90,13 +90,20 @@ export const PriceListConfigurationForm = ({
const { mutateAsync } = useUpdatePriceList(priceList.id)
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(
{
starts_at: values.starts_at?.toISOString() || null,
ends_at: values.ends_at?.toISOString() || null,
rules: {
customer_group_id: values.customer_group_id.map((group) => group.id),
},
rules: rules,
},
{
onSuccess: () => {