fixed some params and ui
This commit is contained in:
@@ -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