fixed some params and ui
This commit is contained in:
@@ -8,6 +8,7 @@ import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { InfiniteSelect } from "@/components/infiniteSelect";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -19,8 +20,18 @@ export interface ColumnMeta {
|
||||
export interface FilterField {
|
||||
id: string;
|
||||
label: string;
|
||||
type?: "select" | "text";
|
||||
type?: "select" | "text" | "infinite-select";
|
||||
options?: { value: string; label: string }[];
|
||||
|
||||
// Infinite Select props
|
||||
loading?: boolean;
|
||||
isLoadingMore?: boolean;
|
||||
hasNextPage?: boolean;
|
||||
onLoadMore?: () => void;
|
||||
searchValue?: string;
|
||||
onSearchChange?: (value: string) => void;
|
||||
searchPlaceholder?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface ActiveFilter {
|
||||
@@ -271,6 +282,23 @@ function FilterDropdown({
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
) : field.type === "infinite-select" ? (
|
||||
<div className="flex-1 min-w-0">
|
||||
<InfiniteSelect
|
||||
value={current}
|
||||
onChange={(val) => onFilterChange(field.id, val)}
|
||||
options={field.options}
|
||||
placeholder="—"
|
||||
searchPlaceholder={field.searchPlaceholder || t("common.search", "Gözle...")}
|
||||
disabled={field.disabled}
|
||||
loading={field.loading}
|
||||
isLoadingMore={field.isLoadingMore}
|
||||
hasNextPage={field.hasNextPage}
|
||||
onLoadMore={field.onLoadMore}
|
||||
searchValue={field.searchValue}
|
||||
onSearchChange={field.onSearchChange}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Select value={current || "__all__"} onValueChange={(val) => onFilterChange(field.id, val === "__all__" ? "" : val)}>
|
||||
|
||||
@@ -86,6 +86,73 @@ const withError = (error?: string) => (error ? "border-destructive focus-visible
|
||||
|
||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
// ─── formatNumber helpers ─────────────────────────────────────────────────────
|
||||
|
||||
/** "1000000.50" → "1 000 000.50" (integer part only gets spaces) */
|
||||
function formatNumberDisplay(raw: string): string {
|
||||
if (!raw) return "";
|
||||
const [intPart, decPart] = raw.split(".");
|
||||
const formatted = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
|
||||
return decPart !== undefined ? `${formatted}.${decPart}` : formatted;
|
||||
}
|
||||
|
||||
/** "1 000 000.50" → "1000000.50" */
|
||||
function stripNumberFormat(display: string): string {
|
||||
return display.replace(/ /g, "");
|
||||
}
|
||||
|
||||
// ─── NumberInput ──────────────────────────────────────────────────────────────
|
||||
|
||||
function NumberInput({ value = "", onChange, placeholder, error, disabled, required, label, className, name, readOnly }: FormInputProps) {
|
||||
// Display state — formatted for the user to see
|
||||
const [display, setDisplay] = useState(() => formatNumberDisplay(value));
|
||||
|
||||
// Sync display when value changes externally (e.g. form reset)
|
||||
useEffect(() => {
|
||||
const current = stripNumberFormat(display);
|
||||
if (current !== value) {
|
||||
setDisplay(formatNumberDisplay(value));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const raw = e.target.value;
|
||||
// Allow only digits, dots, and spaces (we manage spaces ourselves)
|
||||
const stripped = raw.replace(/ /g, "");
|
||||
if (stripped !== "" && !/^\d*\.?\d*$/.test(stripped)) return;
|
||||
if (stripped !== "" && Number(stripped) < 0) return;
|
||||
|
||||
setDisplay(formatNumberDisplay(stripped));
|
||||
onChange?.(stripped);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<div className="relative">
|
||||
<Input
|
||||
name={name}
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn("pr-10", withError(error))}
|
||||
/>
|
||||
<Hash size={14} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
function TextInput({
|
||||
type = "text",
|
||||
value = "",
|
||||
@@ -104,7 +171,6 @@ function TextInput({
|
||||
|
||||
const isPassword = type === "password";
|
||||
const isTextarea = type === "textarea";
|
||||
const isNumber = type === "number";
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@@ -125,21 +191,13 @@ function TextInput({
|
||||
) : (
|
||||
<Input
|
||||
name={name}
|
||||
type={isPassword ? (showPass ? "text" : "password") : isNumber ? "number" : type === "email" ? "email" : "text"}
|
||||
min={isNumber ? 0 : undefined}
|
||||
type={isPassword ? (showPass ? "text" : "password") : type === "email" ? "email" : "text"}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
if (isNumber) {
|
||||
const num = e.target.value;
|
||||
if (num === "" || Number(num) >= 0) onChange?.(num);
|
||||
} else {
|
||||
onChange?.(e.target.value);
|
||||
}
|
||||
}}
|
||||
onChange={(e) => onChange?.(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn(isPassword && "pr-10", isNumber && "pr-10", withError(error))}
|
||||
className={cn(isPassword && "pr-10", withError(error))}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -153,8 +211,6 @@ function TextInput({
|
||||
{showPass ? <EyeOff size={15} /> : <Eye size={15} />}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{isNumber && <Hash size={14} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />}
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
@@ -667,6 +723,7 @@ function FileInput({
|
||||
export function FormInput(props: FormInputProps) {
|
||||
const { type = "text" } = props;
|
||||
|
||||
if (type === "number") return <NumberInput {...props} />;
|
||||
if (type === "phone") return <PhoneInput {...props} />;
|
||||
if (type === "date") return <DateInput {...props} />;
|
||||
if (type === "select") return <SelectInput {...props} />;
|
||||
|
||||
@@ -79,13 +79,23 @@ export function InfiniteSelect({
|
||||
onChange?.("");
|
||||
};
|
||||
|
||||
const loadingRef = useRef(false);
|
||||
|
||||
// Reset loading ref when the query transitions out of loading state
|
||||
useEffect(() => {
|
||||
if (!isLoadingMore) {
|
||||
loadingRef.current = false;
|
||||
}
|
||||
}, [isLoadingMore]);
|
||||
|
||||
// ── Infinite scroll: load more when the sentinel becomes visible ──
|
||||
useEffect(() => {
|
||||
if (!open || !sentinelRef.current || !hasNextPage || isLoadingMore) return;
|
||||
const el = sentinelRef.current;
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries[0]?.isIntersecting && hasNextPage && !isLoadingMore) {
|
||||
if (entries[0]?.isIntersecting && hasNextPage && !isLoadingMore && !loadingRef.current) {
|
||||
loadingRef.current = true;
|
||||
onLoadMore?.();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -175,11 +175,10 @@ export function PassportImage({ label, src, url }: PassportImageProps) {
|
||||
const imageSrc = src ?? url ?? null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:grid sm:grid-cols-[minmax(0,42%)_minmax(0,58%)] items-start py-3 px-4 border-b border-border last:border-0 gap-1 sm:gap-0">
|
||||
<span className="text-xs sm:text-sm text-muted-foreground">{label}</span>
|
||||
<div className="flex flex-col items-start py-3 px-4 border-b border-border last:border-0 gap-1 sm:gap-0">
|
||||
<div className="flex flex-col gap-2">
|
||||
{imageSrc ? (
|
||||
<img src={imageSrc} alt={label} className="w-28 h-20 object-cover rounded-md border border-border" />
|
||||
<img src={imageSrc} alt={label} className="w-full h-46 object-contain rounded-md border border-border" />
|
||||
) : (
|
||||
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
|
||||
<span className="text-xs text-muted-foreground">—</span>
|
||||
|
||||
@@ -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]}
|
||||
|
||||
@@ -553,6 +553,10 @@
|
||||
"loanOrderForm.labels.cardExpYear": "Year",
|
||||
"loanOrderForm.labels.guarantor1Salary": "Average salary",
|
||||
"loanOrderForm.labels.client": "Client",
|
||||
"loanOrderForm.titles.personalName": "Personal data",
|
||||
"loanOrderForm.titles.personalDetails": "Education & family status",
|
||||
"loanOrderForm.titles.residence": "Residence address",
|
||||
"loanOrderForm.titles.loanHistory": "Loan history",
|
||||
"loanOrderForm.steps.status.subtitle": "Status & Note",
|
||||
"loanOrderForm.steps.loan.subtitle": "Type & Amount",
|
||||
"loanOrderForm.steps.location.subtitle": "Region & Branch",
|
||||
@@ -657,6 +661,10 @@
|
||||
"cardOrder.field.bornAt": "Date of birth",
|
||||
"cardOrder.field.bornPlace": "Place of birth",
|
||||
"cardOrder.field.phoneAdditional": "Additional phone",
|
||||
"cardOrder.titles.name": "Name & surname",
|
||||
"cardOrder.titles.birthInfo": "Birth information",
|
||||
"cardOrder.titles.contact": "Contact",
|
||||
"cardOrder.titles.passportIssuer": "Place of issue",
|
||||
"cardOrder.field.passportSerie": "Passport series",
|
||||
"cardOrder.field.passportId": "Passport number",
|
||||
"cardOrder.field.passportGivenAt": "Date of issue",
|
||||
@@ -729,6 +737,21 @@
|
||||
"intlPaymentForm.labels.payerFullName": "Full name",
|
||||
"intlPaymentForm.labels.payerAccount": "Account number",
|
||||
"intlPaymentForm.labels.receiverInfo": "Receiver info",
|
||||
"intlPaymentForm.docs.doc_sberbank_account": "Student's SBERBANK card details",
|
||||
"intlPaymentForm.docs.doc_school_enrollment": "Certificate of studying at a foreign university",
|
||||
"intlPaymentForm.docs.doc_summons": "Copy of the summons letter",
|
||||
"intlPaymentForm.docs.doc_passport_tm": "Original and copy of the TM internal passport",
|
||||
"intlPaymentForm.docs.doc_foreign_passport": "Copy of the foreign passport",
|
||||
"intlPaymentForm.docs.doc_foreign_passport_copy": "Copy of the state page",
|
||||
"intlPaymentForm.docs.doc_exit_permission": "Copy of the page with exit-entry note",
|
||||
"intlPaymentForm.docs.doc_school_foreign_info": "Letter from the university (in the language of instruction)",
|
||||
"intlPaymentForm.docs.doc_school_departure_info": "Letter from the university (in the state language)",
|
||||
"intlPaymentForm.docs.upd_doc_passport_tm": "Original of the TM internal passport (upd)",
|
||||
"intlPaymentForm.docs.upd_doc_foreign_passport": "Copy of the foreign passport (upd)",
|
||||
"intlPaymentForm.docs.upd_doc_visa": "Copy of the visa page",
|
||||
"intlPaymentForm.docs.upd_doc_acceptance_letter": "Acceptance letter and other documents",
|
||||
"intlPaymentForm.docs.upd_doc_passport_biometric": "New (2015+) passport series details",
|
||||
"intlPaymentForm.docs.upd_doc_passport_old": "Older passport series details",
|
||||
"intlPaymentForm.placeholders.payerFullName": "Full name...",
|
||||
"intlPaymentForm.placeholders.payerAccount": "1234 5678 ...",
|
||||
"intlPaymentForm.placeholders.receiverInfo": "Receiver bank, account, Swift...",
|
||||
@@ -1283,6 +1306,13 @@
|
||||
"intlPayment.firstName": "First name",
|
||||
"intlPayment.lastName": "Last name",
|
||||
"intlPayment.createBtn": "Create Visa/Master payment",
|
||||
"intlPayment.editBtn": "Edit",
|
||||
"intlPayment.regions.AG": "Ashgabat",
|
||||
"intlPayment.regions.AH": "Ahal",
|
||||
"intlPayment.regions.BN": "Balkan",
|
||||
"intlPayment.regions.DZ": "Dashoguz",
|
||||
"intlPayment.regions.LB": "Lebap",
|
||||
"intlPayment.regions.MR": "Mary",
|
||||
"permissions.actions.create": "Create permission",
|
||||
"permissions.deleteDialog.description": "Are you sure you want to delete this permission? This action cannot be undone.",
|
||||
"permissions.deleteDialog.title": "Delete permission",
|
||||
|
||||
@@ -553,6 +553,10 @@
|
||||
"loanOrderForm.labels.cardExpYear": "Год",
|
||||
"loanOrderForm.labels.guarantor1Salary": "Средняя зарплата",
|
||||
"loanOrderForm.labels.client": "Клиент",
|
||||
"loanOrderForm.titles.personalName": "Личные данные",
|
||||
"loanOrderForm.titles.personalDetails": "Образование и семейное положение",
|
||||
"loanOrderForm.titles.residence": "Адрес проживания",
|
||||
"loanOrderForm.titles.loanHistory": "Кредитная история",
|
||||
"loanOrderForm.steps.status.subtitle": "Статус и заметка",
|
||||
"loanOrderForm.steps.loan.subtitle": "Тип и сумма",
|
||||
"loanOrderForm.steps.location.subtitle": "Велаят и филиал",
|
||||
@@ -657,6 +661,10 @@
|
||||
"cardOrder.field.bornAt": "Дата рождения",
|
||||
"cardOrder.field.bornPlace": "Место рождения",
|
||||
"cardOrder.field.phoneAdditional": "Дополнительный телефон",
|
||||
"cardOrder.titles.name": "Имя и фамилия",
|
||||
"cardOrder.titles.birthInfo": "Данные о рождении",
|
||||
"cardOrder.titles.contact": "Контакты",
|
||||
"cardOrder.titles.passportIssuer": "Место выдачи",
|
||||
"cardOrder.field.passportSerie": "Серия паспорта",
|
||||
"cardOrder.field.passportId": "Номер паспорта",
|
||||
"cardOrder.field.passportGivenAt": "Дата выдачи",
|
||||
@@ -731,6 +739,21 @@
|
||||
"intlPaymentForm.labels.payerFullName": "Полное имя",
|
||||
"intlPaymentForm.labels.payerAccount": "Номер счета",
|
||||
"intlPaymentForm.labels.receiverInfo": "Информация о получателе",
|
||||
"intlPaymentForm.docs.doc_sberbank_account": "Реквизиты карты SBERBANK студента",
|
||||
"intlPaymentForm.docs.doc_school_enrollment": "Справка об обучении в зарубежном вузе",
|
||||
"intlPaymentForm.docs.doc_summons": "Копия вызова (приглашения)",
|
||||
"intlPaymentForm.docs.doc_passport_tm": "Оригинал и копия внутреннего паспорта РТ",
|
||||
"intlPaymentForm.docs.doc_foreign_passport": "Копия загранпаспорта",
|
||||
"intlPaymentForm.docs.doc_foreign_passport_copy": "Копия государственной страницы",
|
||||
"intlPaymentForm.docs.doc_exit_permission": "Копия страницы с отметкой о выезде-въезде",
|
||||
"intlPaymentForm.docs.doc_school_foreign_info": "Письмо из вуза (на языке обучения)",
|
||||
"intlPaymentForm.docs.doc_school_departure_info": "Письмо из вуза (на государственном языке)",
|
||||
"intlPaymentForm.docs.upd_doc_passport_tm": "Оригинал внутреннего паспорта РТ (upd)",
|
||||
"intlPaymentForm.docs.upd_doc_foreign_passport": "Копия загранпаспорта (upd)",
|
||||
"intlPaymentForm.docs.upd_doc_visa": "Копия страницы с визой",
|
||||
"intlPaymentForm.docs.upd_doc_acceptance_letter": "Письмо о зачислении и другие документы",
|
||||
"intlPaymentForm.docs.upd_doc_passport_biometric": "Данные серии нового (2015+) паспорта",
|
||||
"intlPaymentForm.docs.upd_doc_passport_old": "Данные серии старого паспорта",
|
||||
"intlPaymentForm.placeholders.payerFullName": "Полное имя...",
|
||||
"intlPaymentForm.placeholders.payerAccount": "1234 5678 ...",
|
||||
"intlPaymentForm.placeholders.receiverInfo": "Банк получателя, счет, Swift...",
|
||||
@@ -1284,6 +1307,13 @@
|
||||
"intlPayment.firstName": "Имя",
|
||||
"intlPayment.lastName": "Фамилия",
|
||||
"intlPayment.createBtn": "Создать платеж Visa/Master",
|
||||
"intlPayment.editBtn": "Редактировать",
|
||||
"intlPayment.regions.AG": "Ашхабад",
|
||||
"intlPayment.regions.AH": "Ахал",
|
||||
"intlPayment.regions.BN": "Балкан",
|
||||
"intlPayment.regions.DZ": "Дашогуз",
|
||||
"intlPayment.regions.LB": "Лебап",
|
||||
"intlPayment.regions.MR": "Мары",
|
||||
"permissions.actions.create": "Создать разрешение",
|
||||
"permissions.deleteDialog.description": "Вы уверены, что хотите удалить это разрешение? Это действие необратимо.",
|
||||
"permissions.deleteDialog.title": "Удалить разрешение",
|
||||
|
||||
@@ -552,6 +552,10 @@
|
||||
"loanOrderForm.labels.cardExpYear": "Ýyl",
|
||||
"loanOrderForm.labels.guarantor1Salary": "Ortaca zähmet haky",
|
||||
"loanOrderForm.labels.client": "Müşderi",
|
||||
"loanOrderForm.titles.personalName": "Şahsy maglumatlar",
|
||||
"loanOrderForm.titles.personalDetails": "Bilim we maşgala ýagdaýy",
|
||||
"loanOrderForm.titles.residence": "Ýaşaýyş salgysy",
|
||||
"loanOrderForm.titles.loanHistory": "Karz taryhy",
|
||||
"loanOrderForm.steps.status.subtitle": "Ýagdaý we bellik",
|
||||
"loanOrderForm.steps.loan.subtitle": "Görnüş we möçber",
|
||||
"loanOrderForm.steps.location.subtitle": "Welaýat we şahamça",
|
||||
@@ -656,6 +660,10 @@
|
||||
"cardOrder.field.bornAt": "Doglan senesi",
|
||||
"cardOrder.field.bornPlace": "Doglan ýeri",
|
||||
"cardOrder.field.phoneAdditional": "Telefon goşmaça",
|
||||
"cardOrder.titles.name": "Ady we familiýasy",
|
||||
"cardOrder.titles.birthInfo": "Doglan maglumaty",
|
||||
"cardOrder.titles.contact": "Habarlaşmak",
|
||||
"cardOrder.titles.passportIssuer": "Berlen ýeri",
|
||||
"cardOrder.field.passportSerie": "Pasport seriýasy",
|
||||
"cardOrder.field.passportId": "Pasport belgisi",
|
||||
"cardOrder.field.passportGivenAt": "Berlen senesi",
|
||||
@@ -730,6 +738,21 @@
|
||||
"intlPaymentForm.labels.payerFullName": "Ady Familiýasy Atasynyň ady",
|
||||
"intlPaymentForm.labels.payerAccount": "Goşun hasaby",
|
||||
"intlPaymentForm.labels.receiverInfo": "Töleg kabul edijiniň maglumatlary",
|
||||
"intlPaymentForm.docs.doc_sberbank_account": "Talypyň SBERBANK kartynyň rekwizitleri",
|
||||
"intlPaymentForm.docs.doc_school_enrollment": "Daşary ýurt ÝOM-da okaýandygy barada güwänamasy",
|
||||
"intlPaymentForm.docs.doc_summons": "Çagyrylma hatynyn göçürmesi",
|
||||
"intlPaymentForm.docs.doc_passport_tm": "TM içki pasportynyň asyl görnüşi we göçürmesi",
|
||||
"intlPaymentForm.docs.doc_foreign_passport": "Daşary ýurt pasportynyň göçürmesi",
|
||||
"intlPaymentForm.docs.doc_foreign_passport_copy": "Bakýan döwlet sahypasynyň göçürmesi",
|
||||
"intlPaymentForm.docs.doc_exit_permission": "Çykyş-giriş rugsat bellikli sahypa göçürmesi",
|
||||
"intlPaymentForm.docs.doc_school_foreign_info": "ÝOM-dan hat (okuw dilinde)",
|
||||
"intlPaymentForm.docs.doc_school_departure_info": "ÝOM-dan hat (döwlet dilinde)",
|
||||
"intlPaymentForm.docs.upd_doc_passport_tm": "TM içki pasportynyň asyl görnüşi (upd)",
|
||||
"intlPaymentForm.docs.upd_doc_foreign_passport": "Daşary ýurt pasportynyň göçürmesi (upd)",
|
||||
"intlPaymentForm.docs.upd_doc_visa": "Wiza bellenen sahypasynyň göçürmesi",
|
||||
"intlPaymentForm.docs.upd_doc_acceptance_letter": "Kabul haty we beýleki resminamalar",
|
||||
"intlPaymentForm.docs.upd_doc_passport_biometric": "Täze (2015+) pasport seriýasy maglumatlary",
|
||||
"intlPaymentForm.docs.upd_doc_passport_old": "Könelräk pasport seriýasy maglumatlary",
|
||||
"intlPaymentForm.placeholders.payerFullName": "Doly ady...",
|
||||
"intlPaymentForm.placeholders.payerAccount": "1234 5678 ...",
|
||||
"intlPaymentForm.placeholders.receiverInfo": "Kabul ediji bank, hasap, Swift...",
|
||||
@@ -1282,6 +1305,13 @@
|
||||
"intlPayment.firstName": "Ady",
|
||||
"intlPayment.lastName": "Familiýasy",
|
||||
"intlPayment.createBtn": "Visa/Master tölegler (talyplar üçin) dörediň",
|
||||
"intlPayment.editBtn": "Redaktirläň",
|
||||
"intlPayment.regions.AG": "Aşgabat",
|
||||
"intlPayment.regions.AH": "Ahal",
|
||||
"intlPayment.regions.BN": "Balkan",
|
||||
"intlPayment.regions.DZ": "Daşoguz",
|
||||
"intlPayment.regions.LB": "Lebap",
|
||||
"intlPayment.regions.MR": "Mary",
|
||||
"roles.actions.create": "Rol dörediň",
|
||||
"roles.deleteDialog.description": "Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.",
|
||||
"roles.deleteDialog.title": "Roly pozmak",
|
||||
|
||||
@@ -14,9 +14,9 @@ import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { useCards, useDeleteCard } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import type { CardOrder } from "@/features/orderNewCard/api/orderNewCardApi";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useInfiniteDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useInfiniteCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { getStatusLabel, getStatusOptions, isStatusValue, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
const PER_PAGE = 25;
|
||||
@@ -64,9 +64,33 @@ export default function CardOrdersPage() {
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>(INITIAL_FILTERS);
|
||||
|
||||
// ── Dropdown data ──────────────────────────────────────────────────────────
|
||||
const { data: branchesData } = useBranches({ page, limit: 25 });
|
||||
const { data: districtsData } = useDistricts({ page, limit: 25 });
|
||||
const { data: cardTypesData } = useCardTypes({ page, limit: 25 });
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const [districtSearch, setDistrictSearch] = useState("");
|
||||
const [cardTypeSearch, setCardTypeSearch] = useState("");
|
||||
|
||||
const {
|
||||
data: branchesInfiniteData,
|
||||
fetchNextPage: fetchNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
isFetchingNextPage: isFetchingNextBranches,
|
||||
isLoading: isBranchesLoading,
|
||||
} = useInfiniteBranches(branchSearch);
|
||||
|
||||
const {
|
||||
data: districtsInfiniteData,
|
||||
fetchNextPage: fetchNextDistricts,
|
||||
hasNextPage: hasNextDistricts,
|
||||
isFetchingNextPage: isFetchingNextDistricts,
|
||||
isLoading: isDistrictsLoading,
|
||||
} = useInfiniteDistricts(districtSearch);
|
||||
|
||||
const {
|
||||
data: cardTypesInfiniteData,
|
||||
fetchNextPage: fetchNextCardTypes,
|
||||
hasNextPage: hasNextCardTypes,
|
||||
isFetchingNextPage: isFetchingNextCardTypes,
|
||||
isLoading: isCardTypesLoading,
|
||||
} = useInfiniteCardTypes(cardTypeSearch);
|
||||
|
||||
// ── Query ──────────────────────────────────────────────────────────────────
|
||||
const getFilter = useCallback((id: FilterId) => activeFilters.find((f) => f.fieldId === id)?.value ?? "", [activeFilters]);
|
||||
@@ -183,6 +207,39 @@ export default function CardOrdersPage() {
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
),
|
||||
[branchesInfiniteData, lang],
|
||||
);
|
||||
|
||||
const districtOptions = useMemo(
|
||||
() =>
|
||||
(districtsInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
),
|
||||
[districtsInfiniteData, lang],
|
||||
);
|
||||
|
||||
const cardTypeOptions = useMemo(
|
||||
() =>
|
||||
(cardTypesInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
),
|
||||
[cardTypesInfiniteData, lang],
|
||||
);
|
||||
|
||||
// ── Filter fields ──────────────────────────────────────────────────────────
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
@@ -194,18 +251,26 @@ export default function CardOrdersPage() {
|
||||
{
|
||||
id: "branch_id",
|
||||
label: t("cardOrder.filter.branch", "Şahamça"),
|
||||
options: (branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
type: "infinite-select",
|
||||
options: branchOptions,
|
||||
loading: isBranchesLoading,
|
||||
isLoadingMore: isFetchingNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
onLoadMore: fetchNextBranches,
|
||||
searchValue: branchSearch,
|
||||
onSearchChange: setBranchSearch,
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
label: t("cardOrder.filter.region", "Sebit"),
|
||||
options: (districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
type: "infinite-select",
|
||||
options: districtOptions,
|
||||
loading: isDistrictsLoading,
|
||||
isLoadingMore: isFetchingNextDistricts,
|
||||
hasNextPage: hasNextDistricts,
|
||||
onLoadMore: fetchNextDistricts,
|
||||
searchValue: districtSearch,
|
||||
onSearchChange: setDistrictSearch,
|
||||
},
|
||||
{
|
||||
id: "user_id",
|
||||
@@ -220,13 +285,34 @@ export default function CardOrdersPage() {
|
||||
{
|
||||
id: "card_type_id",
|
||||
label: t("cardOrder.filter.cardTypeId", "Kart görnüşi"),
|
||||
options: (cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
type: "infinite-select",
|
||||
options: cardTypeOptions,
|
||||
loading: isCardTypesLoading,
|
||||
isLoadingMore: isFetchingNextCardTypes,
|
||||
hasNextPage: hasNextCardTypes,
|
||||
onLoadMore: fetchNextCardTypes,
|
||||
searchValue: cardTypeSearch,
|
||||
onSearchChange: setCardTypeSearch,
|
||||
},
|
||||
],
|
||||
[t, lang, branchesData, districtsData, cardTypesData],
|
||||
[
|
||||
t,
|
||||
branchOptions,
|
||||
isBranchesLoading,
|
||||
isFetchingNextBranches,
|
||||
hasNextBranches,
|
||||
branchSearch,
|
||||
districtOptions,
|
||||
isDistrictsLoading,
|
||||
isFetchingNextDistricts,
|
||||
hasNextDistricts,
|
||||
districtSearch,
|
||||
cardTypeOptions,
|
||||
isCardTypesLoading,
|
||||
isFetchingNextCardTypes,
|
||||
hasNextCardTypes,
|
||||
cardTypeSearch,
|
||||
],
|
||||
);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { useCardById, useDeleteCard } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage } from "@/components/viewPageComponents";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { getStatusLabel, isStatusValue, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
@@ -188,10 +188,10 @@ export default function CardOrderDetailPage() {
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardOrder.section.passportParts", "Pasport bölekleri")}>
|
||||
<InfoRow label={t("cardOrder.field.passportOne", "Pasport 1")} value={order.passportOne || "—"} />
|
||||
<InfoRow label={t("cardOrder.field.passportTwo", "Pasport 2")} value={order.passportTwo || "—"} />
|
||||
<InfoRow label={t("cardOrder.field.passportThree", "Pasport 3")} value={order.passportThree || "—"} />
|
||||
<InfoRow label={t("cardOrder.field.passportFour", "Pasport 4")} value={order.passportFour || "—"} />
|
||||
<PassportImage label={t("cardOrder.field.passportOne", "Pasport 1")} src={order.passportOne || "—"} />
|
||||
<PassportImage label={t("cardOrder.field.passportTwo", "Pasport 2")} src={order.passportTwo || "—"} />
|
||||
<PassportImage label={t("cardOrder.field.passportThree", "Pasport 3")} src={order.passportThree || "—"} />
|
||||
<PassportImage label={t("cardOrder.field.passportFour", "Pasport 4")} src={order.passportFour || "—"} />
|
||||
<InfoRow
|
||||
label={t("cardOrder.field.updatedAt", "Täzelenen wagty")}
|
||||
value={order.updatedAt ? new Date(order.updatedAt).toLocaleString() : "—"}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { TableActions } from "@/components/tableActions";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { useLoanOrders, useDeleteLoanOrder } from "@/features/loanOrders/hooks/useLoanOrders";
|
||||
import type { LoanOrder, LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { getStatusLabel, getStatusOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
@@ -42,14 +43,35 @@ const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
// ─── Page Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanOrdersPage() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteLoanOrder();
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const {
|
||||
data: branchesInfiniteData,
|
||||
fetchNextPage: fetchNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
isFetchingNextPage: isFetchingNextBranches,
|
||||
isLoading: isBranchesLoading,
|
||||
} = useInfiniteBranches(branchSearch);
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
),
|
||||
[branchesInfiniteData, lang],
|
||||
);
|
||||
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
@@ -198,7 +220,14 @@ export default function LoanOrdersPage() {
|
||||
{
|
||||
id: "branch",
|
||||
label: t("Branch", "ŞAHAMÇA"),
|
||||
options: [],
|
||||
type: "infinite-select",
|
||||
options: branchOptions,
|
||||
loading: isBranchesLoading,
|
||||
isLoadingMore: isFetchingNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
onLoadMore: fetchNextBranches,
|
||||
searchValue: branchSearch,
|
||||
onSearchChange: setBranchSearch,
|
||||
},
|
||||
{
|
||||
id: "archived",
|
||||
@@ -209,7 +238,7 @@ export default function LoanOrdersPage() {
|
||||
],
|
||||
},
|
||||
],
|
||||
[t, regionOptions],
|
||||
[t, regionOptions, branchOptions, isBranchesLoading, isFetchingNextBranches, hasNextBranches, branchSearch],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -13,8 +13,8 @@ import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { useLoanPaidOffLetters, useDeleteLoanPaidOffLetter } from "@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters";
|
||||
import type { LoanPaidOffLetter } from "@/features/loanPaidOffLetters/api/loanPaidOffLettersApi";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useInfiniteDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { getStatusOptions, STATUS_BADGE_VARIANTS } from "@/constants";
|
||||
|
||||
// ─── Column IDs ────────────────────────────────────────────────────────────────
|
||||
@@ -72,8 +72,24 @@ export default function LoanPaidOffLettersPage() {
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>(INITIAL_FILTERS);
|
||||
|
||||
// ── Dropdown data ──────────────────────────────────────────────────────────
|
||||
const { data: branchesData } = useBranches({ page, limit: 25 });
|
||||
const { data: districtsData } = useDistricts({ page, limit: 25 });
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const [districtSearch, setDistrictSearch] = useState("");
|
||||
|
||||
const {
|
||||
data: branchesInfiniteData,
|
||||
fetchNextPage: fetchNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
isFetchingNextPage: isFetchingNextBranches,
|
||||
isLoading: isBranchesLoading,
|
||||
} = useInfiniteBranches(branchSearch);
|
||||
|
||||
const {
|
||||
data: districtsInfiniteData,
|
||||
fetchNextPage: fetchNextDistricts,
|
||||
hasNextPage: hasNextDistricts,
|
||||
isFetchingNextPage: isFetchingNextDistricts,
|
||||
isLoading: isDistrictsLoading,
|
||||
} = useInfiniteDistricts(districtSearch);
|
||||
|
||||
// ── Query ──────────────────────────────────────────────────────────────────
|
||||
const getFilter = useCallback((id: FilterId) => activeFilters.find((f) => f.fieldId === id)?.value ?? "", [activeFilters]);
|
||||
@@ -96,6 +112,28 @@ export default function LoanPaidOffLettersPage() {
|
||||
const totalPages = Math.max(1, Math.ceil(total / perPage));
|
||||
const isEmpty = !isLoading && (data?.loanPaidLetters?.length ?? 0) === 0;
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
),
|
||||
[branchesInfiniteData, lang],
|
||||
);
|
||||
|
||||
const districtOptions = useMemo(
|
||||
() =>
|
||||
(districtsInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
),
|
||||
[districtsInfiniteData, lang],
|
||||
);
|
||||
|
||||
// ── Filter fields ──────────────────────────────────────────────────────────
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
@@ -112,21 +150,42 @@ export default function LoanPaidOffLettersPage() {
|
||||
{
|
||||
id: "branch_id",
|
||||
label: t("loanPaidOffLetters.filters.branchId", "Şahamça"),
|
||||
options: (branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
type: "infinite-select",
|
||||
options: branchOptions,
|
||||
loading: isBranchesLoading,
|
||||
isLoadingMore: isFetchingNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
onLoadMore: fetchNextBranches,
|
||||
searchValue: branchSearch,
|
||||
onSearchChange: setBranchSearch,
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
label: t("loanPaidOffLetters.filters.region", "Sebit"),
|
||||
options: (districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
type: "infinite-select",
|
||||
options: districtOptions,
|
||||
loading: isDistrictsLoading,
|
||||
isLoadingMore: isFetchingNextDistricts,
|
||||
hasNextPage: hasNextDistricts,
|
||||
onLoadMore: fetchNextDistricts,
|
||||
searchValue: districtSearch,
|
||||
onSearchChange: setDistrictSearch,
|
||||
},
|
||||
],
|
||||
[t, lang, branchesData, districtsData],
|
||||
[
|
||||
t,
|
||||
lang,
|
||||
branchOptions,
|
||||
isBranchesLoading,
|
||||
isFetchingNextBranches,
|
||||
hasNextBranches,
|
||||
branchSearch,
|
||||
districtOptions,
|
||||
isDistrictsLoading,
|
||||
isFetchingNextDistricts,
|
||||
hasNextDistricts,
|
||||
districtSearch,
|
||||
],
|
||||
);
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
@@ -10,7 +10,7 @@ import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar";
|
||||
import { useBranches, useDeleteBranch, useProvinceOptions } from "@/features/branches/hooks/useBranches";
|
||||
import { useBranches, useDeleteBranch, useInfiniteProvinces } from "@/features/branches/hooks/useBranches";
|
||||
import type { Branch } from "@/features/branches/api/branchesApi";
|
||||
|
||||
export function BranchesListPage() {
|
||||
@@ -53,17 +53,38 @@ export function BranchesListPage() {
|
||||
uniqueCode: uniqueCodeFilter,
|
||||
});
|
||||
|
||||
const { data: provinceData } = useProvinceOptions();
|
||||
const provinceOptions = (provinceData ?? []).map((p) => ({
|
||||
value: String(p.id),
|
||||
label: p.name[lang],
|
||||
}));
|
||||
const [provinceSearch, setProvinceSearch] = useState("");
|
||||
const {
|
||||
data: provincesInfiniteData,
|
||||
fetchNextPage: fetchNextProvinces,
|
||||
hasNextPage: hasNextProvinces,
|
||||
isFetchingNextPage: isFetchingNextProvinces,
|
||||
isLoading: isProvincesLoading,
|
||||
} = useInfiniteProvinces(provinceSearch);
|
||||
|
||||
const provinceOptions = useMemo(
|
||||
() =>
|
||||
(provincesInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.provinces ?? []).map((p) => ({
|
||||
value: String(p.id),
|
||||
label: p.name[lang],
|
||||
})),
|
||||
),
|
||||
[provincesInfiniteData, lang],
|
||||
);
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
id: "provinceId",
|
||||
label: t("branches.fields.district", "Etrap"),
|
||||
type: "infinite-select",
|
||||
options: provinceOptions,
|
||||
loading: isProvincesLoading,
|
||||
isLoadingMore: isFetchingNextProvinces,
|
||||
hasNextPage: hasNextProvinces,
|
||||
onLoadMore: fetchNextProvinces,
|
||||
searchValue: provinceSearch,
|
||||
onSearchChange: setProvinceSearch,
|
||||
},
|
||||
{
|
||||
id: "provinceName",
|
||||
|
||||
Reference in New Issue
Block a user