big refactor
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import { refDebounced } from '~/utils/refDebounced'
|
||||
import type { FormCatalogRow } from '~/types/form-catalog'
|
||||
import { productLineLabel, useFormsCatalog } from '~/composables/useFormsCatalog'
|
||||
|
||||
usePageTitle('Forms library · Settings')
|
||||
|
||||
const { rows, version, insurerItems, subRamoItems } = useFormsCatalog()
|
||||
interface FormCatalogRow {
|
||||
id: string
|
||||
description: string
|
||||
insurerSlugs: string[]
|
||||
subRamoLabel: string
|
||||
subRamoKey: string
|
||||
personKinds: 'natural' | 'juridica' | 'both'
|
||||
productLine: string | null
|
||||
fileLabel: string
|
||||
fileUrl: string
|
||||
badge: string | null
|
||||
}
|
||||
|
||||
const rows = ref<FormCatalogRow[]>([])
|
||||
const version = ref('1.0.0')
|
||||
const insurerItems = ref<{ label: string; value: string }[]>([])
|
||||
const subRamoItems = ref<{ label: string; value: string }[]>([])
|
||||
|
||||
const pageSize = ref(10)
|
||||
const page = ref(1)
|
||||
const search = ref('')
|
||||
const debouncedSearch = refDebounced(search, 250)
|
||||
|
||||
const pageSizeItems = [
|
||||
{ label: '10', value: 10 },
|
||||
@@ -32,12 +43,12 @@ function rowSearchText(r: FormCatalogRow): string {
|
||||
}
|
||||
|
||||
const filtered = computed(() => {
|
||||
const q = debouncedSearch.value.trim().toLowerCase()
|
||||
const q = search.value.trim().toLowerCase()
|
||||
if (!q) return rows.value
|
||||
return rows.value.filter((r) => rowSearchText(r).includes(q))
|
||||
})
|
||||
|
||||
watch([debouncedSearch, pageSize], () => {
|
||||
watch([search, pageSize], () => {
|
||||
page.value = 1
|
||||
})
|
||||
|
||||
@@ -73,6 +84,11 @@ function personLabel(pk: FormCatalogRow['personKinds']) {
|
||||
return pk === 'natural' ? 'Natural' : 'Jurídica'
|
||||
}
|
||||
|
||||
function productLineLabel(pl: string | null) {
|
||||
if (!pl) return '—'
|
||||
return pl
|
||||
}
|
||||
|
||||
function exportCsv() {
|
||||
const headers = [
|
||||
'ID',
|
||||
|
||||
Reference in New Issue
Block a user