diff --git a/src/app/actions/yooKassa.ts b/src/app/actions/yooKassa.ts index 899abde..0e2668d 100644 --- a/src/app/actions/yooKassa.ts +++ b/src/app/actions/yooKassa.ts @@ -2,18 +2,58 @@ import { YooCheckout, ICreatePayment } from '@a2seven/yoo-checkout'; import { getSessionData } from '@/app/actions/session'; +import { API_BASE_URL } from '@/app/actions/definitions'; const checkout = new YooCheckout({ shopId: '1276731', secretKey: 'test_0Yns_0NHV5GJf6ypJ5HC4NSfnLO8SJkw-1PwrVWsDl4' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; -export async function yooKasaCreatePayment(amount: number, tariff: string) { +export async function makePaymentOperation(email: string, tariffId: number, operationUuid: string) { + console.log('makePaymentOperation'); + console.log({ + email, + tariffId: tariffId, + operationType: 'TARIFF', + operationUuid, + }); + + const formData = new FormData(); + + formData.append('email', email); + formData.append('tariffId', tariffId.toString()); + formData.append('operationType', 'TARIFF'); + formData.append('operationUuid', operationUuid); + + try { + const response = await fetch(`${API_BASE_URL}/api/payments/create`, { + method: 'POST', + body: formData + }); + + if (response.ok) { + const parsed = await response.json() + console.log(parsed); + return true + + } else { + return null + } + } catch (error) { + return null + } +} + +export async function yooKasaCreatePayment(amount: number, tariff: number) { console.log(amount); console.log(tariff); /* return true; */ const userEmail = await getSessionData('email'); + if (!userEmail) { + return null; + } + const createPayload: ICreatePayment = { amount: { value: amount.toLocaleString(), @@ -34,10 +74,18 @@ export async function yooKasaCreatePayment(amount: number, tariff: string) { try { const payment = await checkout.createPayment(createPayload, Date.now().toLocaleString()); - console.log(payment); - return payment?.confirmation.confirmation_url; + const response = await makePaymentOperation(userEmail, tariff, payment.id); + console.log('yooKasaCreatePayment') + console.log(response); + if (response) { + return payment?.confirmation.confirmation_url; + } else { + return null + } + /* return payment; */ } catch (error) { console.error(error); + return null } } diff --git a/src/app/components/TanstakTable.tsx b/src/app/components/TanstakTable.tsx index 45a7b8c..0360e14 100644 --- a/src/app/components/TanstakTable.tsx +++ b/src/app/components/TanstakTable.tsx @@ -11,7 +11,7 @@ import { SortingState, ColumnFiltersState, } from '@tanstack/react-table'; -import { IconEye, IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload, IconShieldExclamation } from '@/app/ui/icons/icons'; +import { IconEye, IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload, IconShieldExclamation, IconInfo } from '@/app/ui/icons/icons'; import { useTranslations, useLocale } from 'next-intl'; import DropDownList from '@/app/components/DropDownList'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; @@ -21,6 +21,7 @@ import { toast } from 'sonner'; import { pluralize } from '@/app/lib/pluralize'; import { convertBytes } from '@/app/lib/convertBytes'; import { FileInfoModalWindow } from '@/app/ui/modal-windows/file-info-modal-window'; +import { FileMonitoringModalWindow } from '@/app/ui/modal-windows/file-monitoring-modal-window'; import { FileTypeIcon } from '@/app/components/FileTypeIcon'; type FileType = 'image' | 'video' | 'audio'; @@ -404,12 +405,13 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) { }, cell: ({ row }) => (
-
+
{/* )}
@@ -461,7 +459,6 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) { console.log(file); const fileInfo = await viewFileInfo(file.id); - console.log(fileInfo); setOpenWindowChildren(() => { return ( @@ -498,85 +495,19 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) { } }; - const handleProtect = (file: FileItem) => { - console.log(`Щиток: ${file.fileName}`); - }; + const handleMonitoring = async (file: FileItem) => { + console.log(`Мониторинг:`, file); - const handleOpenWindowForRemove = async (file: FileItem) => { + const fileInfo = await viewFileInfo(file.id); setOpenWindowChildren(() => { return ( -
-

- {t('you-sure-you-want-to-delete')} -

-
{file.fileName}
-
- - -
-
+ ) }) setOpenWindow(true); }; - const deleteMutation = useMutation({ - mutationFn: ({ fileId, removeParam }: { fileId: string; removeParam: number }) => - removeUserFile(fileId, removeParam), - - onMutate: async ({ fileId, removeParam }: { fileId: string; removeParam: number }) => { - await queryClient.cancelQueries({ queryKey: ['userFilesData'] }); - - queryClient.setQueryData(['userFilesData'], (old) => { - if (!old?.files) return old; - return { - ...old, - files: old.files.filter(file => file.id !== fileId) - }; - }); - }, - - onError: () => { - queryClient.invalidateQueries({ queryKey: ['userFilesData'] }); - toast.error(t('error')); - }, - - onSuccess: (response, { fileId }) => { - if (response === fileId) { - queryClient.invalidateQueries({ - queryKey: ['userFilesData'], - refetchType: 'active' - }); - - queryClient.invalidateQueries({ - queryKey: ['userFilesInfo'] - }); - - setOpenWindow(false); - setOpenWindowChildren(null); - toast.success(t('file-has-been-deleted')); - } - }, - }); - // Фильтрация по типу файла и дате const filteredData = useMemo(() => { let result = tableData; @@ -693,7 +624,9 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) { } })()} - + + {openWindowChildren} + {/* Фильтры */}
diff --git a/src/app/styles/pages-styles.scss b/src/app/styles/pages-styles.scss index 1639155..5fff366 100644 --- a/src/app/styles/pages-styles.scss +++ b/src/app/styles/pages-styles.scss @@ -4094,4 +4094,31 @@ } } } +} + +.monitoring { + + &-title { + font-size: 22px; + font-weight: 800; + margin-bottom: 15px; + } + + &-status { + margin-bottom: 15px; + } + + &-actions { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 5px; + + .btn-primary { + width: 100%; + color: v.$p-color; + border: 2px solid v.$p-color; + cursor: pointer; + background: #fff; + } + } } \ No newline at end of file diff --git a/src/app/ui/icons/icons.tsx b/src/app/ui/icons/icons.tsx index 9ec5852..42161eb 100644 --- a/src/app/ui/icons/icons.tsx +++ b/src/app/ui/icons/icons.tsx @@ -181,4 +181,10 @@ export function IconDiscet() { ) +} + +export function IconInfo() { + return ( + + ) } \ No newline at end of file diff --git a/src/app/ui/modal-windows/file-monitoring-modal-window.tsx b/src/app/ui/modal-windows/file-monitoring-modal-window.tsx new file mode 100644 index 0000000..0769d5e --- /dev/null +++ b/src/app/ui/modal-windows/file-monitoring-modal-window.tsx @@ -0,0 +1,74 @@ +'use client' + +import { useEffect, useState } from 'react'; + +export function FileMonitoringModalWindow({ file, setWindowClose, setWindowChildren }: any) { + const [status, setStatus] = useState('null'); + + function closeHandler() { + setWindowChildren(null); + setWindowClose(false); + } + + useEffect(() => { + console.log(file); + }, [file]) + + return ( +
+

+ Выберете интервал мониторинга
+ для файла - {file.fileName} +

+

+ Текущий статус мониторинга - {status} +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+ ) +} \ No newline at end of file diff --git a/src/app/ui/payment/payment-tab-tariffs.tsx b/src/app/ui/payment/payment-tab-tariffs.tsx index 01335b2..dba749b 100644 --- a/src/app/ui/payment/payment-tab-tariffs.tsx +++ b/src/app/ui/payment/payment-tab-tariffs.tsx @@ -27,10 +27,11 @@ export default function PaymentTabTariffs() { value: number; tariff: string; tokens: number; + tariffId: number } | null>(null); const [isProcessing, setIsProcessing] = useState(false); - async function createPayment(value: number, tariff: string) { + async function createPayment(value: number, tariff: number) { if (isProcessing) return; setIsProcessing(true); @@ -48,8 +49,8 @@ export default function PaymentTabTariffs() { } } - function openPaymentWindow(value: number, tariff: string, tokens: number) { - setSelectedTariff({ value, tariff, tokens }); + function openPaymentWindow(value: number, tariff: string, tokens: number, tariffId: number) { + setSelectedTariff({ value, tariff, tokens, tariffId }); setIsProcessing(false); setOpenWindow(true); } @@ -64,7 +65,7 @@ export default function PaymentTabTariffs() { if (!selectedTariff) return null; const handleConfirm = () => { - createPayment(selectedTariff.value, selectedTariff.tariff); + createPayment(selectedTariff.value, selectedTariff.tariffId); }; const handleCancel = () => { @@ -170,7 +171,7 @@ export default function PaymentTabTariffs() {