Enhance CreateProductDialog and MerchantStore components for product editing functionality

- Update CreateProductDialog to support both creating and editing products, with dynamic button text and pre-populated fields for existing products.
- Refactor product submission logic to handle updates, including error handling and user feedback.
- Modify MerchantStore to manage product editing state and integrate updated product handling in the dialog.

These changes improve the user experience by allowing merchants to easily edit existing products, enhancing the overall product management workflow.
This commit is contained in:
padreug 2025-09-09 03:35:43 +02:00
parent c00a172fb6
commit 98544e2e79
2 changed files with 134 additions and 21 deletions

View file

@ -293,7 +293,11 @@
<!-- Product Actions -->
<div class="flex justify-end pt-2 border-t">
<Button variant="ghost" size="sm">
<Button
@click="editProduct(product)"
variant="ghost"
size="sm"
>
Edit
</Button>
</div>
@ -316,8 +320,10 @@
<CreateProductDialog
:is-open="showCreateProductDialog"
:stall="activeStall"
@close="showCreateProductDialog = false"
:product="editingProduct"
@close="closeProductDialog"
@created="onProductCreated"
@updated="onProductUpdated"
/>
</template>
@ -370,6 +376,7 @@ const isLoadingProducts = ref(false)
// Dialog state
const showCreateStoreDialog = ref(false)
const showCreateProductDialog = ref(false)
const editingProduct = ref<Product | null>(null)
// Computed properties
const userHasMerchantProfile = computed(() => {
@ -556,6 +563,21 @@ const onProductCreated = async (_product: Product) => {
toast.success('Product created successfully!')
}
const onProductUpdated = async (_product: Product) => {
await loadStallProducts()
toast.success('Product updated successfully!')
}
const editProduct = (product: Product) => {
editingProduct.value = product
showCreateProductDialog.value = true
}
const closeProductDialog = () => {
showCreateProductDialog.value = false
editingProduct.value = null
}
// Lifecycle
onMounted(async () => {
console.log('Merchant Store component loaded')