added payment history, setting pages

This commit is contained in:
Jelaletdin12
2026-09-30 20:36:17 +05:00
parent 1c0cbf1023
commit 1ebc133d1c
35 changed files with 1626 additions and 1273 deletions

View File

@@ -99,6 +99,7 @@ export interface IntlPaymentItem extends IntlPaymentDocs {
branch_label: string;
status: IntlPaymentStatus;
note: string | null;
paid: boolean;
// Şahsy maglumatlar
passport_first_name: string;
@@ -293,6 +294,7 @@ function mapBackendToUI(o: BackendIntlPayment): IntlPaymentItem {
branch_label: o.branch?.name ? resolveLocalizedName(o.branch.name) : "",
status,
note: o.notes ?? "",
paid: Boolean(o.paid),
passport_first_name: o.passportName ?? "",
passport_last_name: o.passportSurname ?? "",
phone: formatFromApiPhone(o.phone),

View File

@@ -0,0 +1,169 @@
import { useMemo, useState } from "react";
import { Search } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Skeleton } from "@/components/ui/skeleton";
import { useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
import type { PaymentHistoryStep } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
// ─── Helpers ──────────────────────────────────────────────────────────────────
function formatDateTime(value: string | null | undefined): string {
if (!value) return "—";
const d = new Date(value);
if (Number.isNaN(d.getTime())) return "—";
const p = (n: number) => String(n).padStart(2, "0");
return `${p(d.getDate())}/${p(d.getMonth() + 1)}/${d.getFullYear()}, ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
function detailEntries(detail: PaymentHistoryStep["detail"] | null | undefined): [string, string][] {
if (!detail || typeof detail !== "object") return [];
return Object.entries(detail).map(([key, value]) => [key, value == null ? "—" : String(value)]);
}
function matches(row: PaymentHistoryStep, query: string): boolean {
const haystack = [row.step, row.createdByName, ...detailEntries(row.detail).flat()].join(" ").toLowerCase();
return haystack.includes(query);
}
// ─── Component ────────────────────────────────────────────────────────────────
interface PaymentHistoryTableProps {
orderId: string | undefined;
}
export function PaymentHistoryTable({ orderId }: PaymentHistoryTableProps) {
const { t } = useTranslation();
const [search, setSearch] = useState("");
const { data, isLoading, isError } = useGetOnlinePaymentById(Number(orderId));
const rows = useMemo(() => {
const sorted = [...(data ?? [])].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
const query = search.trim().toLowerCase();
return query ? sorted.filter((row) => matches(row, query)) : sorted;
}, [data, search]);
return (
<div className="p-4">
{/* Search */}
<div className="relative mb-4 max-w-xs">
<Search size={13} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
<input
type="text"
value={search}
onChange={(event) => setSearch(event.target.value)}
placeholder={t("common.search", "Gözlemek")}
className="
h-9
w-full
rounded-md
border
border-border
bg-background
pl-9
pr-3
text-sm
focus:outline-none
focus:ring-2
focus:ring-ring
"
/>
</div>
{/* Loading */}
{isLoading ? (
<div className="flex flex-col gap-2">
{[...Array(4)].map((_, index) => (
<Skeleton key={index} className="h-10 w-full" />
))}
</div>
) : isError ? (
/* Error */
<div className="py-10 text-center text-sm text-destructive">
{t("paymentHistory.loadError", "Töleg taryhyny ýüklemek başartmady")}
</div>
) : rows.length === 0 ? (
/* Empty */
<div className="flex flex-col items-center justify-center py-10 text-muted-foreground/50">
<div className="mb-3 flex h-12 w-12 items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/20">
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth={1.5}>
<rect x="3" y="3" width="18" height="18" rx="2" />
<line x1="3" y1="9" x2="21" y2="9" />
<line x1="9" y1="21" x2="9" y2="9" />
</svg>
</div>
<p className="text-sm">{t("paymentHistory.empty", "Berlen kriteriýalara Töleg gabat gelmedi.")}</p>
</div>
) : (
/* Table */
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead className="bg-muted/50 text-left text-xs text-muted-foreground">
<tr>
<th className="whitespace-nowrap px-4 py-2.5 font-medium">{t("paymentHistory.col.id", "ID")}</th>
<th className="whitespace-nowrap px-4 py-2.5 font-medium">{t("paymentHistory.col.step", "Ädim")}</th>
<th className="px-4 py-2.5 font-medium">{t("paymentHistory.col.detail", "Jikme-jiklik")}</th>
<th className="whitespace-nowrap px-4 py-2.5 font-medium">{t("paymentHistory.col.createdBy", "Kim tarapyndan")}</th>
<th className="whitespace-nowrap px-4 py-2.5 font-medium">{t("paymentHistory.col.createdAt", "Wagty")}</th>
</tr>
</thead>
<tbody>
{rows.map((row) => {
const entries = detailEntries(row.detail);
return (
<tr key={row.id} className="border-t border-border align-top">
{/* ID */}
<td className="px-4 py-2.5 font-mono text-xs text-muted-foreground">{row.id}</td>
{/* Step */}
<td className="whitespace-nowrap px-4 py-2.5 font-medium">{t(`paymentHistory.steps.${row.step}`, row.step)}</td>
{/* Details */}
<td className="px-4 py-2.5">
{entries.length === 0 ? (
<span className="text-muted-foreground/50">—</span>
) : (
<dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs">
{entries.map(([key, value]) => (
<div key={key} className="contents">
<dt className="text-muted-foreground">{key}</dt>
<dd className="break-all">{value}</dd>
</div>
))}
</dl>
)}
</td>
{/* Created By */}
<td className="whitespace-nowrap px-4 py-2.5">{row.createdByName || "—"}</td>
{/* Created At */}
<td className="whitespace-nowrap px-4 py-2.5 text-muted-foreground">{formatDateTime(row.createdAt)}</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
);
}