fixed some params and ui
This commit is contained in:
@@ -15,7 +15,8 @@ export const userKeys = {
|
||||
|
||||
export function useUsers(params: UsersListParams = {}) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: UsersListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: UsersListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: userKeys.list(queryParams),
|
||||
|
||||
@@ -25,7 +25,8 @@ export const branchKeys = {
|
||||
|
||||
export function useBranches(params: BranchListParams) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: BranchListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: BranchListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: branchKeys.list(queryParams),
|
||||
@@ -33,6 +34,28 @@ export function useBranches(params: BranchListParams) {
|
||||
});
|
||||
}
|
||||
|
||||
const BRANCH_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Paginated branches for infinite-scroll selects.
|
||||
* `search` is debounced server-side search; each keystroke resets to page 1.
|
||||
*/
|
||||
export function useInfiniteBranches(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...branchKeys.lists(), "infinite", effectiveSearch],
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => fetchBranches({ page: pageParam, limit: BRANCH_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.branches?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const PROVINCE_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
@@ -41,7 +64,7 @@ const PROVINCE_PAGE_SIZE = 25;
|
||||
*/
|
||||
export function useInfiniteProvinces(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...branchKeys.provinces, "infinite", effectiveSearch],
|
||||
|
||||
@@ -27,7 +27,8 @@ export const cardReasonKeys = {
|
||||
|
||||
export function useCardReasons(params: CardReasonListParams = {}) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: CardReasonListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: CardReasonListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: cardReasonKeys.list(queryParams),
|
||||
|
||||
@@ -10,7 +10,8 @@ const QUERY_KEY = "cards";
|
||||
|
||||
export function useCardTransactions(params?: CardListParams) {
|
||||
const debouncedSearch = useDebouncedValue(params?.search ?? "");
|
||||
const queryParams: CardListParams = { ...(params ?? {}), search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: CardListParams = { ...(params ?? {}), search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEY, "list", queryParams],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient, useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useDebouncedValue, normalizeSearch } from "@/hooks/useDebouncedSearch";
|
||||
@@ -28,7 +28,8 @@ export const cardTypeKeys = {
|
||||
|
||||
export function useCardTypes(params: CardTypeListParams = {}) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: CardTypeListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: CardTypeListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: cardTypeKeys.list(queryParams),
|
||||
@@ -37,6 +38,28 @@ export function useCardTypes(params: CardTypeListParams = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
const CARD_TYPE_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Paginated card types for infinite-scroll selects.
|
||||
* `search` is debounced server-side search; each keystroke resets to page 1.
|
||||
*/
|
||||
export function useInfiniteCardTypes(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...cardTypeKeys.lists(), "infinite", effectiveSearch],
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => fetchCardTypes({ page: pageParam, limit: CARD_TYPE_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.paymentCards?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ─── useCardTypeById ──────────────────────────────────────────────────────────
|
||||
|
||||
export function useCardTypeById(id: number | undefined) {
|
||||
|
||||
@@ -19,7 +19,8 @@ export const clientKeys = {
|
||||
|
||||
export function useClients(params: ClientsListParams = {}) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: ClientsListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: ClientsListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: clientKeys.list(queryParams),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient, useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useDebouncedValue, normalizeSearch } from "@/hooks/useDebouncedSearch";
|
||||
import {
|
||||
fetchDistricts,
|
||||
fetchDistrictById,
|
||||
@@ -20,9 +21,35 @@ export const districtKeys = {
|
||||
};
|
||||
|
||||
export function useDistricts(params: DistrictListParams) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: DistrictListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: districtKeys.list(params),
|
||||
queryFn: () => fetchDistricts(params),
|
||||
queryKey: districtKeys.list(queryParams),
|
||||
queryFn: () => fetchDistricts(queryParams),
|
||||
});
|
||||
}
|
||||
|
||||
const DISTRICT_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Paginated districts for infinite-scroll selects.
|
||||
* `search` is debounced server-side search; each keystroke resets to page 1.
|
||||
*/
|
||||
export function useInfiniteDistricts(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...districtKeys.lists(), "infinite", effectiveSearch],
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam }) => fetchDistricts({ page: pageParam, limit: DISTRICT_PAGE_SIZE, search: effectiveSearch }),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.provinces?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ function mapPayloadToBackend(payload: LoanOrderPayload | Partial<LoanOrderPayloa
|
||||
source: "web",
|
||||
loanOrderRequiredDocId: payload.loanHistory ? Number(payload.loanHistory) : 0,
|
||||
userId: toNum(payload.userId) ?? 0,
|
||||
uniqueId: "",
|
||||
uniqueId: "541-shbfnkj",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ export const loanTypeKeys = {
|
||||
|
||||
export function useGetLoanTypes(params: LoanTypeListParams = {}) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: LoanTypeListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: LoanTypeListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: loanTypeKeys.list(queryParams),
|
||||
|
||||
@@ -18,7 +18,8 @@ export const operatorKeys = {
|
||||
|
||||
export function useOperators(params: OperatorsListParams = {}) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: OperatorsListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: OperatorsListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: operatorKeys.list(queryParams),
|
||||
@@ -45,7 +46,7 @@ const STAFF_PAGE_SIZE = 25;
|
||||
*/
|
||||
export function useInfiniteStaff(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...operatorKeys.all, "infinite", effectiveSearch] as const,
|
||||
|
||||
@@ -18,7 +18,8 @@ export const permissionKeys = {
|
||||
|
||||
export function usePermissions(params: PermissionsListParams) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: PermissionsListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: PermissionsListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: permissionKeys.list(queryParams),
|
||||
|
||||
@@ -18,7 +18,8 @@ export const roleKeys = {
|
||||
|
||||
export function useRoles(params: RolesListParams) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: RolesListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: RolesListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: roleKeys.list(queryParams),
|
||||
|
||||
@@ -423,7 +423,7 @@ function StepPayment({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepDocs({ form, set, errors }: StepContentProps) {
|
||||
function StepDocs({ form, set, errors, t }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
@@ -431,7 +431,7 @@ function StepDocs({ form, set, errors }: StepContentProps) {
|
||||
{KABUL_DOCS.map(({ key, label }) => (
|
||||
<DocumentUpload
|
||||
key={key}
|
||||
label={label}
|
||||
label={t(`intlPaymentForm.docs.${key}`, label)}
|
||||
value={(form[key] as string) || ""}
|
||||
onChange={(v) => set(key, v as IntlPaymentFormData[typeof key])}
|
||||
error={errors[key]}
|
||||
@@ -445,7 +445,7 @@ function StepDocs({ form, set, errors }: StepContentProps) {
|
||||
{UPGRAD_DOCS.map(({ key, label }) => (
|
||||
<DocumentUpload
|
||||
key={key}
|
||||
label={label}
|
||||
label={t(`intlPaymentForm.docs.${key}`, label)}
|
||||
value={(form[key] as string) || ""}
|
||||
onChange={(v) => set(key, v as IntlPaymentFormData[typeof key])}
|
||||
error={errors[key]}
|
||||
|
||||
Reference in New Issue
Block a user