'use client' import { useState } from 'react' import type { PaginationListColumnType } from '@/types' import useDisclosure from '@/hooks/useDisclosure' import PaginatedList from '@/components/PaginatedList' import Button from '@/components/formElements/Button' import Modal from '@/components/modals/Modal' import AdminTableViewButton from '@/components/ui/AdminTableViewButton' import StatusChip from '@/components/ui/StatusChip' import { APP_ROUTES, CONSUMER_ROUTES } from '@/constants/routes' import { coerceToString, formatPersonName } from '@/helpers' import { API_ROUTES } from '@/services/config' import { formatIranianMobile, formatPersianDate, truncateValue } from '@/lib/formatters' interface InAppNotificationRow { id: string userId: string mobile: string category: string title: string body: string actionUrl: string | null status: string readAt: string | null createdAt: string recipient?: { firstName: string | null lastName: string | null } } const columns: PaginationListColumnType[] = [ { field: 'userId', label: 'گیرنده', filterable: true, sortable: false, type: 'text' }, { field: 'mobile', label: 'موبایل', filterable: true, sortable: false, type: 'text' }, { field: 'title', label: 'عنوان', filterable: false, sortable: false }, { field: 'category', label: 'دسته', filterable: true, sortable: false, type: 'text' }, { field: 'readStatus', label: 'خواندن', filterable: true, sortable: false, type: 'select', filterItems: [ { code: 'unread', name: 'خوانده‌نشده' }, { code: 'read', name: 'خوانده‌شده' }, ], }, { field: 'createdAt', label: 'تاریخ ثبت', filterable: false, sortable: true }, { field: 'actions', label: 'عملیات' }, ] const InAppNotificationsPanel = () => { const { isOpen, onOpen, onOpenChange } = useDisclosure() const [activeRow, setActiveRow] = useState(null) const openDetails = (row: InAppNotificationRow) => { setActiveRow(row) onOpen() } return ( <> {{ userId: (row) => { const notification = row as unknown as InAppNotificationRow const name = formatPersonName(notification.recipient?.firstName, notification.recipient?.lastName) return (
{name !== '—' && {name}} {formatIranianMobile(notification.mobile)}
) }, mobile: (_row, cellValue) => {formatIranianMobile(coerceToString(cellValue))}, title: (row, cellValue) => { const notification = row as unknown as InAppNotificationRow return (
{truncateValue(coerceToString(cellValue), 50)} {truncateValue(notification.body, 70)}
) }, category: (_row, cellValue) => coerceToString(cellValue) || '—', readStatus: (row) => { const notification = row as unknown as InAppNotificationRow return notification.readAt ? ( ) : ( ) }, createdAt: (_row, cellValue) => formatPersianDate(cellValue), actions: (row) => { const notification = row as unknown as InAppNotificationRow return (
) }, }}

عنوان

{activeRow?.title ?? '—'}

متن اعلان

{activeRow?.body ?? '—'}

مسیر مقصد

{activeRow?.actionUrl ?? CONSUMER_ROUTES.PROFILE_NOTIFICATIONS}

دسته

{activeRow?.category ?? '—'}

وضعیت خواندن

{activeRow?.readAt ? formatPersianDate(activeRow.readAt) : 'خوانده نشده'}

تاریخ ثبت

{formatPersianDate(activeRow?.createdAt)}

) } export default InAppNotificationsPanel