Add accounts UI with list, create, edit, detail tabs for all sub-entities
Accounts list with paginated table, search, sort. Account detail page with tabs for members, payment methods, tax exemptions, and processor links. All sub-entities have create/edit dialogs and delete actions. Forms use shared Zod schemas via react-hook-form.
This commit is contained in:
43
packages/admin/src/hooks/use-pagination.ts
Normal file
43
packages/admin/src/hooks/use-pagination.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { useNavigate, useSearch } from '@tanstack/react-router'
|
||||
import type { PaginationInput } from '@forte/shared/schemas'
|
||||
|
||||
interface PaginationSearch {
|
||||
page?: number
|
||||
limit?: number
|
||||
q?: string
|
||||
sort?: string
|
||||
order?: 'asc' | 'desc'
|
||||
}
|
||||
|
||||
export function usePagination() {
|
||||
const search = useSearch({ strict: false }) as PaginationSearch
|
||||
const navigate = useNavigate()
|
||||
|
||||
const params: PaginationInput = {
|
||||
page: search.page ?? 1,
|
||||
limit: search.limit ?? 25,
|
||||
q: search.q,
|
||||
sort: search.sort,
|
||||
order: search.order ?? 'asc',
|
||||
}
|
||||
|
||||
function setParams(updates: Partial<PaginationSearch>) {
|
||||
navigate({
|
||||
search: (prev: PaginationSearch) => ({
|
||||
...prev,
|
||||
...updates,
|
||||
// Reset to page 1 when search or sort changes
|
||||
page: updates.q !== undefined || updates.sort !== undefined ? 1 : (updates.page ?? prev.page),
|
||||
}),
|
||||
replace: true,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...params,
|
||||
setPage: (page: number) => setParams({ page }),
|
||||
setSearch: (q: string) => setParams({ q: q || undefined }),
|
||||
setSort: (sort: string, order: 'asc' | 'desc') => setParams({ sort, order }),
|
||||
params,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user