From bc1d5d5337bd90bc9d58d15b5be749d028d5e525 Mon Sep 17 00:00:00 2001 From: smanylov Date: Wed, 25 Feb 2026 12:53:18 +0700 Subject: [PATCH] edit payments history --- src/app/actions/referralsActions.ts | 12 +++- .../react-query/useGetReferralPayments.ts | 26 ++++---- src/app/lib/formatDate.ts | 8 +++ .../ui/referral-page/Income-and-payments.tsx | 1 - .../referral-page/table/payments-history.tsx | 65 +++---------------- 5 files changed, 39 insertions(+), 73 deletions(-) diff --git a/src/app/actions/referralsActions.ts b/src/app/actions/referralsActions.ts index 83107a4..1242e01 100644 --- a/src/app/actions/referralsActions.ts +++ b/src/app/actions/referralsActions.ts @@ -192,12 +192,18 @@ export async function getUserPayments() { const parsed = await response.json(); console.log(parsed); - return parsed; + return { + payments: parsed, + error: null + }; } else { - return null + throw 'error'; } } catch (error) { - return null + return { + payments: [], + error: 'error' + }; } } diff --git a/src/app/hooks/react-query/useGetReferralPayments.ts b/src/app/hooks/react-query/useGetReferralPayments.ts index 5895f44..09652ed 100644 --- a/src/app/hooks/react-query/useGetReferralPayments.ts +++ b/src/app/hooks/react-query/useGetReferralPayments.ts @@ -1,20 +1,19 @@ import { useQuery } from '@tanstack/react-query'; -import {getUserPayments} from '@/app/actions/referralsActions'; +import { getUserPayments } from '@/app/actions/referralsActions'; -export interface PaymentsData { +export interface ReferralPayments { amount: number, - cancellationReason: string | null, + completedAt: string | null, createdAt: string, id: number, - operationType: string, - paymentUuid: string, + processAt: string | null + rejectionReason: string | null, status: string, updatedAt: string, } - -export interface UserPayments { - payments: PaymentsData[], +export interface UserReferralPayments { + payments: ReferralPayments[], error: string | null } @@ -22,17 +21,18 @@ export const useGetReferralPayments = () => { return useQuery({ queryKey: ['referralPayments'], queryFn: getUserPayments, - select: (data): UserPayments => { -/* console.log('referralPayments'); - console.log(data); */ + select: (data): UserReferralPayments => { if (!data) { return { payments: [], - error: null + error: 'error' } } - return data; + return { + payments: data.payments, + error: data.error + } }, retry: false }); diff --git a/src/app/lib/formatDate.ts b/src/app/lib/formatDate.ts index e477ccb..0fa749c 100644 --- a/src/app/lib/formatDate.ts +++ b/src/app/lib/formatDate.ts @@ -1,5 +1,9 @@ // Форматирование даты из timestamp export const formatDate = (timestamp: number | string) => { + if (!timestamp) { + return '---' + } + const date = new Date(timestamp); const day = date.getDate().toString().padStart(2, '0'); const month = (date.getMonth() + 1).toString().padStart(2, '0'); @@ -9,6 +13,10 @@ export const formatDate = (timestamp: number | string) => { }; export const formatDateTime = (timestamp: number | string) => { + if (!timestamp) { + return '---' + } + const date = new Date(timestamp); const hours = date.getHours().toString().padStart(2, '0'); const minutes = date.getMinutes().toString().padStart(2, '0'); diff --git a/src/app/ui/referral-page/Income-and-payments.tsx b/src/app/ui/referral-page/Income-and-payments.tsx index 4c23991..341840b 100644 --- a/src/app/ui/referral-page/Income-and-payments.tsx +++ b/src/app/ui/referral-page/Income-and-payments.tsx @@ -14,7 +14,6 @@ export default function IncomeAndPayments() { return fetchReferralUserStats(); }, select: (data) => { - console.log(data); if (data?.referralLink) { return data } else { diff --git a/src/app/ui/referral-page/table/payments-history.tsx b/src/app/ui/referral-page/table/payments-history.tsx index caa6bfe..5f69522 100644 --- a/src/app/ui/referral-page/table/payments-history.tsx +++ b/src/app/ui/referral-page/table/payments-history.tsx @@ -6,57 +6,12 @@ import { useReactTable, getCoreRowModel, getSortedRowModel, getPaginationRowMode import { IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter } from '@/app/ui/icons/icons'; import { useTranslations, useLocale } from 'next-intl'; import DropDownList from '@/app/components/DropDownList'; -import { useQueryClient, useQuery } from '@tanstack/react-query'; import { pluralize } from '@/app/lib/pluralize'; -import { fetchReferralInvitees } from '@/app/actions/referralsActions'; - -type InviteesType = { - status?: string; - email?: string; - registrationData: string; -}; - -type InviteType = { - active?: string; - email?: string; - regDate: string; -}; +import { ReferralPayments } from '@/app/hooks/react-query/useGetReferralPayments'; +import { formatDate } from '@/app/lib/formatDate'; export default function PaymentsHistory() { - - const { data: paymentsData } = useGetReferralPayments(); - - useEffect(() => { - console.log(paymentsData); - }, [paymentsData]); - - const { - data: referralInvitees, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['referralInvitees'], - queryFn: () => { - return fetchReferralInvitees(); - }, - - select: (data: InviteType[]): InviteesType[] => { - if (!data) return [ - ]; - - return data.map((item: InviteType) => { - - return { - status: item?.active ? 'active' : 'not-active', - email: item?.email, - registrationData: item?.regDate - }; - }); - }, - }); - - const queryClient = useQueryClient(); + const { data: paymentsData, isLoading, isError, error, } = useGetReferralPayments(); // Состояния const [sorting, setSorting] = useState([]); @@ -72,7 +27,7 @@ export default function PaymentsHistory() { const locale = useLocale(); // Определение колонок - const columns = useMemo[]>( + const columns = useMemo[]>( () => [ { accessorKey: 'amount', @@ -103,9 +58,7 @@ export default function PaymentsHistory() { ), cell: ({ row }) => (
- {/* {row.original.size !== undefined ? convertBytes(row.original.size) : '-'} */} - {/* {row.original.email} */} - --- + {row.original.amount ?? '-'}
), }, @@ -211,7 +164,7 @@ export default function PaymentsHistory() { cell: ({ row }) => { return (
- {row.original.registrationData?.split('T')[0]} + {formatDate(row.original.createdAt) ? formatDate(row.original.createdAt) : '---'}
) }, @@ -247,7 +200,7 @@ export default function PaymentsHistory() { cell: ({ row }) => { return (
- {row.original.registrationData?.split('T')[0]} + {row.original.updatedAt ? formatDate(row.original.updatedAt) : '---'}
) }, @@ -259,7 +212,7 @@ export default function PaymentsHistory() { // Фильтрация по типу файла и дате const filteredData = useMemo(() => { - let result = referralInvitees; + let result = paymentsData?.payments; if (!result) { return []; } @@ -315,7 +268,7 @@ export default function PaymentsHistory() { } */ return result; - }, [referralInvitees, statusFilter, dateFilter]); + }, [paymentsData, statusFilter, dateFilter]); useEffect(() => { const currentPageRows = table.getRowModel().rows;