Refactor CreateProductDialog and CreateStoreDialog components for improved form handling
- Remove unnecessary destructuring of form values in CreateProductDialog to simplify code. - Enhance conditional rendering in CreateStoreDialog to ensure proper checks for selected countries. - Update API request handling in CreateStoreDialog to enforce non-null assertions for required fields. - Adjust MerchantStore component to use underscore-prefixed parameters in event handlers for clarity. These changes streamline the form handling process and improve code readability across the components.
This commit is contained in:
parent
0c931cf457
commit
378e534a66
4 changed files with 11 additions and 12 deletions
|
|
@ -267,7 +267,7 @@ const form = useForm({
|
||||||
})
|
})
|
||||||
|
|
||||||
// Destructure product form methods
|
// Destructure product form methods
|
||||||
const { resetForm, values, meta } = form
|
const { resetForm, meta } = form
|
||||||
|
|
||||||
// Product form validation computed
|
// Product form validation computed
|
||||||
const isFormValid = computed(() => meta.value.valid)
|
const isFormValid = computed(() => meta.value.valid)
|
||||||
|
|
|
||||||
|
|
@ -155,10 +155,10 @@
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<div v-if="values.newZone?.selectedCountries?.length > 0" class="mt-2">
|
<div v-if="values.newZone?.selectedCountries && values.newZone.selectedCountries.length > 0" class="mt-2">
|
||||||
<div class="flex flex-wrap gap-1">
|
<div class="flex flex-wrap gap-1">
|
||||||
<Badge
|
<Badge
|
||||||
v-for="country in values.newZone.selectedCountries"
|
v-for="country in (values.newZone?.selectedCountries || [])"
|
||||||
:key="country"
|
:key="country"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
class="text-xs"
|
class="text-xs"
|
||||||
|
|
@ -211,7 +211,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted, watch, nextTick } from 'vue'
|
import { ref, computed, watch, nextTick } from 'vue'
|
||||||
import { useForm } from 'vee-validate'
|
import { useForm } from 'vee-validate'
|
||||||
import { toTypedSchema } from '@vee-validate/zod'
|
import { toTypedSchema } from '@vee-validate/zod'
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
|
|
@ -353,10 +353,10 @@ const addNewZone = async () => {
|
||||||
const createdZone = await nostrmarketAPI.createZone(
|
const createdZone = await nostrmarketAPI.createZone(
|
||||||
currentUser.wallets[0].adminkey,
|
currentUser.wallets[0].adminkey,
|
||||||
{
|
{
|
||||||
name: newZone.name,
|
name: newZone.name!,
|
||||||
currency: values.currency,
|
currency: values.currency!,
|
||||||
cost: newZone.cost,
|
cost: newZone.cost!,
|
||||||
countries: newZone.selectedCountries
|
countries: newZone.selectedCountries!
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,6 @@ import {
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
User
|
User
|
||||||
} from 'lucide-vue-next'
|
} from 'lucide-vue-next'
|
||||||
import type { OrderStatus } from '@/modules/market/stores/market'
|
|
||||||
import type { NostrmarketAPI, Merchant, Stall, Product } from '../services/nostrmarketAPI'
|
import type { NostrmarketAPI, Merchant, Stall, Product } from '../services/nostrmarketAPI'
|
||||||
import { auth } from '@/composables/useAuthService'
|
import { auth } from '@/composables/useAuthService'
|
||||||
import { useToast } from '@/core/composables/useToast'
|
import { useToast } from '@/core/composables/useToast'
|
||||||
|
|
@ -542,12 +541,12 @@ const checkMerchantProfile = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event handlers
|
// Event handlers
|
||||||
const onStoreCreated = async (stall: Stall) => {
|
const onStoreCreated = async (_stall: Stall) => {
|
||||||
await loadStallsList()
|
await loadStallsList()
|
||||||
toast.success('Store created successfully!')
|
toast.success('Store created successfully!')
|
||||||
}
|
}
|
||||||
|
|
||||||
const onProductCreated = async (product: Product) => {
|
const onProductCreated = async (_product: Product) => {
|
||||||
await loadStallProducts()
|
await loadStallProducts()
|
||||||
toast.success('Product created successfully!')
|
toast.success('Product created successfully!')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<!-- Store Metrics -->
|
<!-- Store Metrics -->
|
||||||
<div class="flex items-center justify-between text-sm">
|
<div class="flex items-center justify-between text-sm">
|
||||||
<span class="text-muted-foreground">Products</span>
|
<span class="text-muted-foreground">Products</span>
|
||||||
<span class="font-medium">{{ stall.products?.length || 0 }}</span>
|
<span class="font-medium">-</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center justify-between text-sm">
|
<div class="flex items-center justify-between text-sm">
|
||||||
<span class="text-muted-foreground">Shipping Zones</span>
|
<span class="text-muted-foreground">Shipping Zones</span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue