diff --git a/package.json b/package.json index db3465f..cf8a32c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "no-copy-frontend", - "version": "0.33.0", + "version": "0.34.0", "private": true, "scripts": { "dev": "next dev -p 2999", diff --git a/src/app/actions/referralsActions.ts b/src/app/actions/referralsActions.ts new file mode 100644 index 0000000..b1bfdc5 --- /dev/null +++ b/src/app/actions/referralsActions.ts @@ -0,0 +1,123 @@ +'use server' + +import { getSessionData } from '@/app/actions/session'; +import { API_BASE_URL } from '@/app/actions/definitions'; + +export async function fetchReferralsLevels() { + 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: 'levels', + token: token, + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + let parsed = await response.json(); + + if (parsed.message_code === 0) { + return parsed.message_body.length ? parsed.message_body : parsed; + } else { + throw parsed; + } + } else { + throw (`${response.status}`); + } + + } catch (error) { + return { + error: error + } + } +} + +export async function fetchReferralUserStats() { + 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: 'userStats', + token: token, + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + let parsed = await response.json(); + + if (parsed.message_code === 0) { + return parsed.message_body; + } else { + throw parsed; + } + } else { + throw (`${response.status}`); + } + + } catch (error) { + return { + error: error + } + } +} + +export async function fetchReferralInvitees() { + 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: 'invitees', + token: token, + pageSize: 10, + pageNumber: 0 + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + let parsed = await response.json(); + + if (parsed.message_code === 0) { + return parsed.message_body; + } else { + throw parsed; + } + } else { + throw (`${response.status}`); + } + + } catch (error) { + return { + error: error + } + } +} \ No newline at end of file diff --git a/src/app/lib/prefetch-queries.ts b/src/app/lib/prefetch-queries.ts index 791c71c..c9e7059 100644 --- a/src/app/lib/prefetch-queries.ts +++ b/src/app/lib/prefetch-queries.ts @@ -1,6 +1,7 @@ import { QueryClient } from '@tanstack/react-query'; import { getUserData, getUserFilesInfo } from '@/app/actions/action'; import { getUserFilesData } from '@/app/actions/fileEntity'; +import {fetchReferralUserStats} from '@/app/actions/referralsActions'; export async function prefetchLayoutQueries(queryClient: QueryClient) { await Promise.all([ @@ -19,5 +20,9 @@ export async function prefetchLayoutQueries(queryClient: QueryClient) { queryKey: ['userFilesInfo'], queryFn: () => getUserFilesInfo() }), + queryClient.prefetchQuery({ + queryKey: ['referralUserStats'], + queryFn: () => fetchReferralUserStats() + }), ]); } \ No newline at end of file diff --git a/src/app/styles/pages-styles.scss b/src/app/styles/pages-styles.scss index 06db882..f671366 100644 --- a/src/app/styles/pages-styles.scss +++ b/src/app/styles/pages-styles.scss @@ -236,6 +236,7 @@ border-bottom: 1px solid v.$b-color-1; align-items: center; overflow: auto; + border-radius: 10px; .stats-item { border: 1px solid v.$b-color-1; diff --git a/src/app/ui/navigation/nav-links.tsx b/src/app/ui/navigation/nav-links.tsx index fc466b2..ed61e04 100644 --- a/src/app/ui/navigation/nav-links.tsx +++ b/src/app/ui/navigation/nav-links.tsx @@ -11,8 +11,25 @@ import navigation from './navigation.json'; import { useSideMenuStore } from '@/app/stores/sideMenuStore'; import { useRef } from 'react'; import { useClickOutside } from '@/app/hooks/useClickOutside'; +import { fetchReferralUserStats } from '@/app/actions/referralsActions'; +import { useQuery } from '@tanstack/react-query'; export default function NavLinks() { + const { + data: referralLink, + isLoading, + isError, + error + } = useQuery({ + queryKey: ['referralUserStats'], + queryFn: () => { + return fetchReferralUserStats(); + }, + select: (data) => { + return data?.referralLink; + } + }); + const pathname = usePathname().replace('/en/', '/').replace('/ru/', '/'); const t = useTranslations('Global'); @@ -69,6 +86,10 @@ export default function NavLinks() { {links.map((link) => { + if (!referralLink && link.name === 'referral-program') { + return null; + } + return (

💰 Доступно к выводу

- 135.00 Б + 0

Минимальная сумма вывода: 100 Б @@ -18,7 +18,7 @@ export default function IncomeAndPayments() {

📈 Всего заработано

- 135.00 Б + 0

За все время участия в программе
@@ -26,7 +26,7 @@ export default function IncomeAndPayments() {

✅ Выплачено

- 0.00 Б + 0

Успешно выплачено на ваши счета
@@ -70,8 +70,8 @@ export default function IncomeAndPayments() { Обработано -
- 100.00 +
+ 0
0 @@ -82,39 +82,7 @@ export default function IncomeAndPayments() {
0
-
- 0 -
- -
- 100.00 -
-
- 0 -
-
- 0 -
-
- 0 -
-
- 0 -
- -
- 100.00 -
-
- 0 -
-
- 0 -
-
- 0 -
-
+
0
diff --git a/src/app/ui/referral-page/commission-levels.tsx b/src/app/ui/referral-page/commission-levels.tsx index 82183b7..d1123ec 100644 --- a/src/app/ui/referral-page/commission-levels.tsx +++ b/src/app/ui/referral-page/commission-levels.tsx @@ -1,4 +1,38 @@ +'use client' + +import { useQuery } from '@tanstack/react-query'; +import { fetchReferralsLevels } from '@/app/actions/referralsActions'; +import { useEffect } from 'react'; + export default function CommissionLevels() { + const { + data: referralsLevels, + isLoading, + isError, + error + } = useQuery({ + queryKey: ['referralsLevels'], + queryFn: () => { + return fetchReferralsLevels(); + }, + select: (data) => { + if (data?.message_body) { + return data?.message_body + } else { + return [] + } + } + }); + + useEffect(() => { + console.log('referralsLevels'); + console.log(referralsLevels); + }, [referralsLevels]) + + if (!referralsLevels?.length) { + return null; + } + return (

diff --git a/src/app/ui/referral-page/invitations-table.tsx b/src/app/ui/referral-page/invitations-table.tsx index 6fc8d2b..6b6fa7f 100644 --- a/src/app/ui/referral-page/invitations-table.tsx +++ b/src/app/ui/referral-page/invitations-table.tsx @@ -17,38 +17,34 @@ 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 FileItem = { +type InviteesType = { status?: string; email?: string; registrationData: number; }; -type ApiFile = { - status?: string; +type InviteType = { + active?: string; email?: string; - registrationData: string; + regDate: number; }; -type ApiResponse = { - files?: ApiFile[]; -}; - - export default function InvitationsTable() { const { - data: testData, + data: referralInvitees, isLoading, isError, error, - } = useQuery({ - queryKey: ['testData'], + } = useQuery({ + queryKey: ['referralInvitees'], queryFn: () => { - return {} + return fetchReferralInvitees(); }, - select: (data: ApiResponse): FileItem[] => { - if (!data?.files) return [ + select: (data: InviteType[]): InviteesType[] => { + if (!data) return [ { status: 'string1', email: 'string1', @@ -66,11 +62,11 @@ export default function InvitationsTable() { } ]; - return data.files.map((item: ApiFile) => { + return data.map((item: InviteType) => { return { - status: 'string', - email: 'string', - registrationData: 40 + status: item.active, + email: item.email, + registrationData: item.regDate }; }); }, @@ -92,7 +88,7 @@ export default function InvitationsTable() { const locale = useLocale(); // Определение колонок - const columns = useMemo[]>( + const columns = useMemo[]>( () => [ { accessorKey: 'email', @@ -207,7 +203,7 @@ export default function InvitationsTable() { // Фильтрация по типу файла и дате const filteredData = useMemo(() => { - let result = testData; + let result = referralInvitees; if (!result) { return []; } @@ -263,7 +259,7 @@ export default function InvitationsTable() { } return result; - }, [testData, statusFilter, dateFilter]); + }, [referralInvitees, statusFilter, dateFilter]); useEffect(() => { const currentPageRows = table.getRowModel().rows; diff --git a/src/app/ui/referral-page/referral-link-section.tsx b/src/app/ui/referral-page/referral-link-section.tsx index e406f43..adbfbf0 100644 --- a/src/app/ui/referral-page/referral-link-section.tsx +++ b/src/app/ui/referral-page/referral-link-section.tsx @@ -1,18 +1,71 @@ +'use client' + +import { fetchReferralUserStats } from '@/app/actions/referralsActions'; +import { useQuery } from '@tanstack/react-query'; +import { useTranslations } from 'next-intl'; +import { useEffect, useRef, useState } from 'react'; +import { toast } from 'sonner'; + export default function ReferralLinkSection() { + const { + data: referralUserStats, + isLoading, + isError, + error + } = useQuery({ + queryKey: ['referralUserStats'], + queryFn: () => { + return fetchReferralUserStats(); + }, + select: (data) => { + return data; + } + }); + + const t = useTranslations('Global') + const [referralUrl, setReferralUrl] = useState(''); + const refLink = useRef(null); + + useEffect(() => { + if (typeof window !== 'undefined') { + setReferralUrl(`${window.location.origin}/register?ref=${referralUserStats?.referralLink}`); + } + }, [referralUserStats]); + + const copyHandler = () => { + if (refLink.current?.textContent) { + navigator.clipboard.writeText(refLink.current?.textContent); + toast.success(`${t('copied')}: ${refLink.current?.textContent}`) + } + }; + + if (!referralUserStats?.referralLink) { + return null; + } + return (
-

🔗 Ваша реферальная ссылка

+

Ваша реферальная ссылка

Поделитесь этой ссылкой с друзьями и получайте комиссию с каждой их покупки

- - https://dashboard.no-copy.ru/register.php?ref=REFA0406AC8 + + {referralUrl} - +

- Код: REFA0406AC8 • - Кликов: 21 • - Комиссия: 15% + Код: {referralUserStats?.referralLink} • + Приглашений: + {referralUserStats?.totalInvitee} +

) diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index ce849ab..b6aee7a 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -212,7 +212,8 @@ "are-no-violations": "There are no violations", "error-reading-image": "Error reading image", "error-user-not-have-tokens-for-protect": "User not have tokens for protect", - "registration-date": "Registration date" + "registration-date": "Registration date", + "copied": "Copied" }, "Login-register-form": { "and": "and", diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index c35bc9b..bd79f56 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -212,7 +212,8 @@ "are-no-violations": "Нарушений нет", "error-reading-image": "Ошибка чтения изображения", "error-user-not-have-tokens-for-protect": "У пользователя нет токенов для защиты.", - "registration-date": "Дата регистрации" + "registration-date": "Дата регистрации", + "copied": "Скопировано" }, "Login-register-form": { "and": "и",