fix policy dir

This commit is contained in:
2026-03-30 12:48:29 -05:00
parent 5164590bc9
commit ff2d7b18b5
4 changed files with 22 additions and 18 deletions

View File

@@ -100,7 +100,7 @@ const carForm = ref({
chassis_number: '',
engine_number: ''
},
selected_providers: [] as { id: string, email: string }[]
selected_providers: [] as { provider_id: string, email: string }[]
})
const useTypeItems = ref<SelectItem[]>([
@@ -143,16 +143,19 @@ const { data: providersData, pending: providersPending } = useProviders('/provid
const providerItems = computed(() => providersData.value?.data ?? [])
function toggleProvider(provider: any) {
const idx = carForm.value.selected_providers.findIndex(p => p.id === provider.provider_id)
const idx = carForm.value.selected_providers.findIndex(p => p.provider_id === provider.provider_id)
if (idx >= 0) {
carForm.value.selected_providers.splice(idx, 1)
} else {
carForm.value.selected_providers.push({ id: provider.provider_id, email: provider.email })
carForm.value.selected_providers.push({
provider_id: provider.provider_id,
email: provider.email
})
}
}
function isProviderSelected(provider: any) {
return carForm.value.selected_providers.some(p => p.id === provider.provider_id)
return carForm.value.selected_providers.some(p => p.provider_id === provider.provider_id)
}
// ---------------------------------------------------------------------------
@@ -162,11 +165,12 @@ function isProviderSelected(provider: any) {
async function submitCarPolicy() {
submitting.value = true
try {
const data = await $policy('/car-policies', {
const data = await $policy('/policies', {
method: 'POST',
body: {
policy_type: 'car',
applicant_info: applicantInfo.value,
car_details: carForm.value.car_details,
policy_details: carForm.value.car_details,
selected_providers: carForm.value.selected_providers
}
}) as any
@@ -176,7 +180,7 @@ async function submitCarPolicy() {
} catch (e: any) {
toast.add({
title: 'Failed to submit policy',
description: e?.data?.errors ? JSON.stringify(e.data.errors) : e.message,
description: e?.data?.error ? JSON.stringify(e.data.error) : e.message,
color: 'red'
})
} finally {
@@ -460,18 +464,18 @@ const isCarFormValid = computed(() => {
<div v-if="carForm.selected_providers.length > 0" class="flex flex-wrap gap-2 pt-2 border-t">
<div
v-for="p in carForm.selected_providers"
:key="p.id"
:key="p.provider_id"
class="flex items-center gap-1.5 px-3 py-1 bg-primary-50 border border-primary-200 rounded-full text-sm"
>
<UIcon name="i-heroicons-building-office" class="w-3.5 h-3.5 text-primary-500" />
<span class="text-primary-800 font-medium">
{{ providerItems.find(x => x.provider_id === p.id)?.name ?? p.id }}
{{ providerItems.find(x => x.provider_id === p.provider_id)?.name ?? p.provider_id }}
</span>
<UButton
icon="i-heroicons-x-mark"
size="xs" color="gray" variant="ghost"
class="w-4 h-4 p-0"
@click="carForm.selected_providers = carForm.selected_providers.filter(x => x.id !== p.id)"
@click="carForm.selected_providers = carForm.selected_providers.filter(x => x.provider_id !== p.provider_id)"
/>
</div>
</div>