edit payments history
This commit is contained in:
@@ -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'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
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
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -14,7 +14,6 @@ export default function IncomeAndPayments() {
|
||||
return fetchReferralUserStats();
|
||||
},
|
||||
select: (data) => {
|
||||
console.log(data);
|
||||
if (data?.referralLink) {
|
||||
return data
|
||||
} else {
|
||||
|
||||
@@ -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<InviteType[], Error, InviteesType[], ['referralInvitees']>({
|
||||
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<SortingState>([]);
|
||||
@@ -72,7 +27,7 @@ export default function PaymentsHistory() {
|
||||
const locale = useLocale();
|
||||
|
||||
// Определение колонок
|
||||
const columns = useMemo<ColumnDef<InviteesType>[]>(
|
||||
const columns = useMemo<ColumnDef<ReferralPayments>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorKey: 'amount',
|
||||
@@ -103,9 +58,7 @@ export default function PaymentsHistory() {
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<div className="text-center table-item">
|
||||
{/* {row.original.size !== undefined ? convertBytes(row.original.size) : '-'} */}
|
||||
{/* {row.original.email} */}
|
||||
---
|
||||
{row.original.amount ?? '-'}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -211,7 +164,7 @@ export default function PaymentsHistory() {
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="text-center table-item">
|
||||
{row.original.registrationData?.split('T')[0]}
|
||||
{formatDate(row.original.createdAt) ? formatDate(row.original.createdAt) : '---'}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
@@ -247,7 +200,7 @@ export default function PaymentsHistory() {
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="text-center table-item">
|
||||
{row.original.registrationData?.split('T')[0]}
|
||||
{row.original.updatedAt ? formatDate(row.original.updatedAt) : '---'}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user