Refactor CreateProductDialog and MerchantStore for improved product handling

- Updated CreateProductDialog to use `model-value` for Checkbox components, enhancing reactivity and consistency.
- Modified MerchantStore to only add active products to the market store, improving product visibility and management.

These changes streamline the product creation and management processes, ensuring better user experience and data integrity.
This commit is contained in:
padreug 2025-09-26 00:32:55 +02:00
parent a75982f8ef
commit bb761abe75
2 changed files with 14 additions and 11 deletions

View file

@ -89,8 +89,9 @@
<FormControl> <FormControl>
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
<Checkbox <Checkbox
:checked="value" :key="`active-checkbox-${props.isOpen}`"
@update:checked="handleChange" :model-value="value"
@update:model-value="handleChange"
:disabled="isCreating" :disabled="isCreating"
/> />
<Label>Product is active and visible</Label> <Label>Product is active and visible</Label>
@ -141,8 +142,8 @@
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
<FormControl> <FormControl>
<Checkbox <Checkbox
:checked="value" :model-value="value"
@update:checked="handleChange" @update:model-value="handleChange"
:disabled="isCreating" :disabled="isCreating"
/> />
</FormControl> </FormControl>
@ -461,13 +462,13 @@ watch(() => props.isOpen, async (isOpen) => {
use_autoreply: false, use_autoreply: false,
autoreply_message: '' autoreply_message: ''
} }
// Reset form with appropriate initial values // Reset form with appropriate initial values
resetForm({ values: initialValues }) resetForm({ values: initialValues })
// Wait for reactivity // Wait for reactivity
await nextTick() await nextTick()
// Clear any previous errors // Clear any previous errors
createError.value = null createError.value = null
} }

View file

@ -523,10 +523,12 @@ const loadStallProducts = async () => {
})) }))
stallProducts.value = enrichedProducts stallProducts.value = enrichedProducts
// Also add them to the market store so they appear in the main market // Only add active products to the market store so they appear in the main market
enrichedProducts.forEach(product => { enrichedProducts
marketStore.addProduct(product) .filter(product => product.active)
}) .forEach(product => {
marketStore.addProduct(product)
})
} catch (error) { } catch (error) {
console.error('Failed to load products:', error) console.error('Failed to load products:', error)
stallProducts.value = [] stallProducts.value = []