Merge branch 'dev' into feat/consultation-82
This commit is contained in:
No files matched your search
@@ -2,6 +2,7 @@ import type { DataTableLoader } from '~/components/pub/my-ui/data-table/type'
|
||||
import type { PaginationMeta } from '~/components/pub/my-ui/pagination/pagination.type'
|
||||
import { refDebounced, useUrlSearchParams } from '@vueuse/core'
|
||||
import * as z from 'zod'
|
||||
import { is } from "date-fns/locale"
|
||||
|
||||
// Default query schema yang bisa digunakan semua list
|
||||
export const defaultQuerySchema = z.object({
|
||||
@@ -75,6 +76,8 @@ export function usePaginatedList<T = any>(options: UsePaginatedListOptions<T>) {
|
||||
|
||||
// Functions
|
||||
async function fetchData() {
|
||||
if (isLoading.isTableLoading) return
|
||||
|
||||
isLoading.isTableLoading = true
|
||||
|
||||
try {
|
||||
@@ -97,7 +100,6 @@ export function usePaginatedList<T = any>(options: UsePaginatedListOptions<T>) {
|
||||
paginationMeta.hasPrev = paginationMeta.page > 1
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error fetching ${entityName} list:`, error)
|
||||
data.value = []
|
||||
paginationMeta.recordCount = 0
|
||||
paginationMeta.totalPage = 0
|
||||
@@ -126,6 +128,7 @@ export function usePaginatedList<T = any>(options: UsePaginatedListOptions<T>) {
|
||||
watch(
|
||||
params,
|
||||
(newParams) => {
|
||||
console.log('watch ~ newParams', newParams)
|
||||
// Sync search input with URL params (for back/forward navigation)
|
||||
if (newParams.search !== searchInput.value) {
|
||||
searchInput.value = newParams.search || ''
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { computed } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
export function useQueryMode(key: string = 'mode') {
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const mode = computed<'list' | 'add'>({
|
||||
get: () => (route.query[key] && route.query[key] === 'add' ? 'add' : 'list'),
|
||||
set: (val) => {
|
||||
router.replace({
|
||||
path: route.path,
|
||||
query: {
|
||||
...route.query,
|
||||
[key]: val === 'list' ? undefined : val,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const openForm = () => (mode.value = 'add')
|
||||
const backToList = () => (mode.value = 'list')
|
||||
|
||||
return { mode, openForm, backToList }
|
||||
}
|
||||
Reference in New Issue
Block a user