From b6c5c5991913ece7890e6feeffbadb37b6fd23f6 Mon Sep 17 00:00:00 2001 From: smanylov Date: Mon, 9 Feb 2026 16:07:49 +0700 Subject: [PATCH] add ref link error, add refill button, update referral invites table --- src/app/actions/auth.ts | 18 +++--- src/app/actions/referralsActions.ts | 56 ++++++++++++++++++- src/app/ui/payment/secure-payments.tsx | 22 ++++++++ .../ui/referral-page/invitations-table.tsx | 35 ++++-------- src/i18n/messages/en.json | 3 +- src/i18n/messages/ru.json | 3 +- 6 files changed, 102 insertions(+), 35 deletions(-) diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 554712a..e68cfe6 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -214,8 +214,8 @@ export async function registration( phone: phone, password, accountType, - /* referralLink: referralCode, */ - ...(accountType === 'b2b' && { companyName: companyName }) + ...(accountType === 'b2b' && { companyName: companyName }), + ...(referralCode !== '' && { referralLink: referralCode }) } }), headers: { @@ -230,8 +230,8 @@ export async function registration( phone: phone, password, accountType, - /* referralLink: referralCode, */ - ...(accountType === 'b2b' && { companyName: companyName }) + ...(accountType === 'b2b' && { companyName: companyName }), + ...(referralCode !== '' && { referralLink: referralCode }) }) if (response.ok) { @@ -282,9 +282,13 @@ export async function registration( switch (typedError.message_code) { case 1: - errors['server'] = 'email-or-already-registered' - break; - + if (typedError.message_desc === 'Refferal link is not exist') { + errors['server'] = 'referral-link-is-not-exist' + break; + } else { + errors['server'] = 'email-or-already-registered' + break; + } case 2: if (typedError.message_body?.fieldErrors) { typedError.message_body?.fieldErrors?.forEach((obj: { diff --git a/src/app/actions/referralsActions.ts b/src/app/actions/referralsActions.ts index 5b40846..01a6020 100644 --- a/src/app/actions/referralsActions.ts +++ b/src/app/actions/referralsActions.ts @@ -97,7 +97,7 @@ export async function fetchReferralInvitees() { message_body: { action: 'invitees', token: token, - pageSize: 10, + pageSize: 100, pageNumber: 0 } }), @@ -109,6 +109,60 @@ export async function fetchReferralInvitees() { if (response.ok) { let parsed = await response.json(); + console.log({ + action: 'invitees', + token: token, + pageSize: 10, + pageNumber: 0 + }) + console.log(parsed); + + if (parsed.message_code === 0) { + return parsed.message_body; + } else { + throw parsed; + } + } else { + throw (`${response.status}`); + } + + } catch (error) { + return { + error: error + } + } +} + +export async function referralRefill() { + const token = await getSessionData('token'); + + try { + const response = await fetch(`${API_BASE_URL}/api/v1/data`, { + method: 'POST', + body: JSON.stringify({ + version: 1, + msg_id: 30003, + message_body: { + action: 'refill', + token: token, + amount: 1, + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + console.log('referralRefill'); + console.log({ + action: 'refill', + token: token, + amount: 1, + }) + let parsed = await response.json(); + console.log(parsed); if (parsed.message_code === 0) { return parsed.message_body; diff --git a/src/app/ui/payment/secure-payments.tsx b/src/app/ui/payment/secure-payments.tsx index d530eaa..d5ff9ff 100644 --- a/src/app/ui/payment/secure-payments.tsx +++ b/src/app/ui/payment/secure-payments.tsx @@ -1,9 +1,31 @@ +'use client' + +import { referralRefill } from '@/app/actions/referralsActions'; +import { toast } from 'sonner'; + export default function SecurePayments() { + return (

🔒 Безопасные платежи

+
+ +
diff --git a/src/app/ui/referral-page/invitations-table.tsx b/src/app/ui/referral-page/invitations-table.tsx index 6b6fa7f..33f3bbe 100644 --- a/src/app/ui/referral-page/invitations-table.tsx +++ b/src/app/ui/referral-page/invitations-table.tsx @@ -11,24 +11,23 @@ import { SortingState, ColumnFiltersState, } from '@tanstack/react-table'; -import { IconEye, IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload, IconShieldExclamation } from '@/app/ui/icons/icons'; +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 { useQuery, useQueryClient } from '@tanstack/react-query'; -import { toast } from 'sonner'; import { pluralize } from '@/app/lib/pluralize'; import { fetchReferralInvitees } from '@/app/actions/referralsActions'; type InviteesType = { status?: string; email?: string; - registrationData: number; + registrationData: string; }; type InviteType = { active?: string; email?: string; - regDate: number; + regDate: string; }; export default function InvitationsTable() { @@ -45,28 +44,14 @@ export default function InvitationsTable() { select: (data: InviteType[]): InviteesType[] => { if (!data) return [ - { - status: 'string1', - email: 'string1', - registrationData: 1 - }, - { - status: 'string2', - email: 'string2', - registrationData: 2 - }, - { - status: 'string3', - email: 'string3', - registrationData: 3 - } ]; return data.map((item: InviteType) => { + console.log(item); return { - status: item.active, - email: item.email, - registrationData: item.regDate + status: item?.active ? 'active' : 'not-active', + email: item?.email, + registrationData: item?.regDate }; }); }, @@ -191,7 +176,7 @@ export default function InvitationsTable() { cell: ({ row }) => { return (
- {row.original.registrationData} + {row.original.registrationData?.split('T')[0]}
) }, @@ -214,7 +199,7 @@ export default function InvitationsTable() { } // Фильтр по дате - if (dateFilter !== 'all') { + /* if (dateFilter !== 'all') { const now = Date.now(); const oneDay = 24 * 60 * 60 * 1000; const sevenDays = 7 * oneDay; @@ -256,7 +241,7 @@ export default function InvitationsTable() { }); break; } - } + } */ return result; }, [referralInvitees, statusFilter, dateFilter]); diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index ebf1b59..da92ef3 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -287,6 +287,7 @@ "change-password": "Change Password", "recovery-code": "Recovery code", "referal-code": "Referal code", - "email-invalid": "Invalid email address" + "email-invalid": "Invalid email address", + "referral-link-is-not-exist" : "Referral link is not exist" } } \ No newline at end of file diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index 5cf74ea..7b72f06 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -287,6 +287,7 @@ "change-password": "Изменить пароль", "recovery-code": "Код восстановления", "referal-code": "Реферальный код", - "email-invalid": "Неверный адрес электронной почты" + "email-invalid": "Неверный адрес электронной почты", + "referral-link-is-not-exist" : "Отсутствует реферальная ссылка." } } \ No newline at end of file