From aeb61936cea084bfaab2df175a0c0b11e239f3bc Mon Sep 17 00:00:00 2001 From: smanylov Date: Fri, 20 Feb 2026 14:55:23 +0700 Subject: [PATCH] add dropdown monitoring --- .../tanstak-table/MonitoringDropDown.tsx | 154 ++++++++++++++++++ .../components/tanstak-table/TanstakTable.tsx | 51 +----- src/app/styles/global-styles.scss | 62 +++++++ src/i18n/messages/en.json | 7 +- src/i18n/messages/ru.json | 7 +- 5 files changed, 234 insertions(+), 47 deletions(-) create mode 100644 src/app/components/tanstak-table/MonitoringDropDown.tsx diff --git a/src/app/components/tanstak-table/MonitoringDropDown.tsx b/src/app/components/tanstak-table/MonitoringDropDown.tsx new file mode 100644 index 0000000..24b5bc0 --- /dev/null +++ b/src/app/components/tanstak-table/MonitoringDropDown.tsx @@ -0,0 +1,154 @@ +'use client' + +import { FileItem } from '@/app/components/tanstak-table/TanstakTable'; +import { useEffect, useState, useRef } from 'react'; +import { useClickOutside } from '@/app/hooks/useClickOutside'; +import { useTranslations } from 'next-intl'; +import { useQueryClient } from '@tanstack/react-query'; +import { createPortal } from 'react-dom'; + +export function MonitoringDropDown({ file }: { + file: FileItem +}) { + const [isOpen, setIsOpen] = useState(false); + const [currentMonitoringStatus, setCurrentMonitoringStatus] = useState('without-monitoring'); + const [dropdownPosition, setDropdownPosition] = useState({ top: 0, left: 0, width: 0 }); + + const dropdownRef = useRef(null); + const buttonRef = useRef(null); + + const t = useTranslations('Global') + const queryClient = useQueryClient(); + + useEffect(() => { + if (!isOpen) return; + + const handleClick = (event: MouseEvent) => { + console.log('click'); + if (!dropdownRef?.current) { + return; + } + + if (!buttonRef?.current) { + return; + } + + if (buttonRef?.current.contains(event.target as Node)) { + return; + } + + if (!dropdownRef.current.contains(event.target as Node)) { + setIsOpen(false); + } + }; + + document.addEventListener('mousedown', handleClick); + return () => { + document.removeEventListener('mousedown', handleClick); + }; + }, [dropdownRef, setIsOpen, isOpen]); + + useEffect(() => { + console.log(file); + if (file.status) { + setCurrentMonitoringStatus(file.status === 'ACTIVE' ? 'without-monitoring' : 'without-monitoring'); + } + }, [file]); + + useEffect(() => { + if (isOpen && buttonRef.current) { + const rect = buttonRef.current.getBoundingClientRect(); + setDropdownPosition({ + top: rect.bottom + window.scrollY, + left: rect.left + window.scrollX, + width: rect.width + }); + } + }, [isOpen]); + + async function clickHandler(monitoring: string) { + console.log('click', file.id); + setCurrentMonitoringStatus(monitoring); + await queryClient.invalidateQueries({ queryKey: ['userFilesData'] }); + setIsOpen(false); + } + + return ( +
+ + {isOpen && createPortal( +
+
    +
  • { + clickHandler('without-monitoring') + }} + > + {t('without-monitoring')} +
  • +
  • { + clickHandler('every-day') + }} + > + {t('every-day')} +
  • +
  • { + clickHandler('every-week') + }} + > + {t('every-week')} +
  • +
  • { + clickHandler('every-month') + }} + > + {t('every-month')} +
  • +
+
, + document.body + )} +
+ ) +} \ No newline at end of file diff --git a/src/app/components/tanstak-table/TanstakTable.tsx b/src/app/components/tanstak-table/TanstakTable.tsx index 0227efc..805eea0 100644 --- a/src/app/components/tanstak-table/TanstakTable.tsx +++ b/src/app/components/tanstak-table/TanstakTable.tsx @@ -24,10 +24,11 @@ import { FileInfoModalWindow } from '@/app/ui/modal-windows/file-info-modal-wind import { FileMonitoringModalWindow } from '@/app/ui/modal-windows/file-monitoring-modal-window'; import { FileTypeIcon } from '@/app/components/FileTypeIcon'; import { fetchReferralUserStats } from '@/app/actions/referralsActions'; +import { MonitoringDropDown } from '@/app/components/tanstak-table/MonitoringDropDown'; type FileType = 'image' | 'video' | 'audio'; -type FileItem = { +export type FileItem = { id: string; fileName: string; fileType: string; @@ -379,7 +380,7 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) { header: ({ column }) => (
- {t('status')} + {t('monitoring-status')} + */} {/*