From 684d16ca7d78d29d78e5b90610754eff8a11fa11 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Thu, 11 Dec 2025 09:39:27 +0330 Subject: [PATCH] update notification type --- src/pages/notifications/List.tsx | 24 ++++- .../components/EditNotificationTypeModal.tsx | 92 +++++++++++++++++++ .../components/NotificationTableColumns.tsx | 21 ++++- src/pages/notifications/enum/Enum.ts | 6 ++ .../hooks/useNotificationData.ts | 19 +++- .../service/NotificationService.ts | 11 +++ 6 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 src/pages/notifications/components/EditNotificationTypeModal.tsx create mode 100644 src/pages/notifications/enum/Enum.ts diff --git a/src/pages/notifications/List.tsx b/src/pages/notifications/List.tsx index cda4b4e..3cdf7e5 100644 --- a/src/pages/notifications/List.tsx +++ b/src/pages/notifications/List.tsx @@ -1,10 +1,11 @@ -import { type FC } from 'react' +import { type FC, useState } from 'react' import Table from '@/components/Table' import Filters from '@/components/Filters' import { useGetNotifications } from './hooks/useNotificationData' import { useNotificationFilters } from './hooks/useNotificationFilters' import { getNotificationTableColumns } from './components/NotificationTableColumns' import { useNotificationFiltersFields } from './components/NotificationFiltersFields' +import EditNotificationTypeModal from './components/EditNotificationTypeModal' import type { Notification } from './types/Types' const NotificationsList: FC = () => { @@ -20,9 +21,22 @@ const NotificationsList: FC = () => { const { data: notificationsData, isLoading } = useGetNotifications(apiParams) const notifications = notificationsData?.data || [] - const columns = getNotificationTableColumns() const filterFields = useNotificationFiltersFields() + const [isEditModalOpen, setIsEditModalOpen] = useState(false) + const [selectedNotification, setSelectedNotification] = useState(null) + + const handleEdit = (notification: Notification) => { + setSelectedNotification(notification) + setIsEditModalOpen(true) + } + + const handleCloseModal = () => { + setIsEditModalOpen(false) + setSelectedNotification(null) + } + + const columns = getNotificationTableColumns({ onEdit: handleEdit }) const totalPages = Math.ceil(notifications.length / limit) || 1 return ( @@ -50,6 +64,12 @@ const NotificationsList: FC = () => { onPageChange: handlePageChange, }} /> + + ) } diff --git a/src/pages/notifications/components/EditNotificationTypeModal.tsx b/src/pages/notifications/components/EditNotificationTypeModal.tsx new file mode 100644 index 0000000..c477d51 --- /dev/null +++ b/src/pages/notifications/components/EditNotificationTypeModal.tsx @@ -0,0 +1,92 @@ +import { type FC, useState, useEffect } from 'react' +import DefaulModal from '@/components/DefaulModal' +import Select from '@/components/Select' +import Button from '@/components/Button' +import { useUpdateNotification } from '../hooks/useNotificationData' +import { NotificationType } from '../enum/Enum' +import type { Notification } from '../types/Types' + +interface Props { + open: boolean + close: () => void + notification: Notification | null +} + +const EditNotificationTypeModal: FC = ({ open, close, notification }) => { + const [selectedType, setSelectedType] = useState(NotificationType.NONE) + const { mutate: updateNotification, isPending } = useUpdateNotification() + + useEffect(() => { + if (notification) { + setSelectedType(notification.notificationType as NotificationType) + } + }, [notification]) + + if (!notification) return null + + const notificationTypeOptions = [ + { value: NotificationType.SMS, label: 'پیامک' }, + { value: NotificationType.PUSH, label: 'پوش' }, + { value: NotificationType.Both, label: 'هر دو' }, + ] + + const handleSubmit = () => { + updateNotification( + { + id: notification.id, + notificationType: selectedType, + }, + { + onSuccess: () => { + close() + }, + } + ) + } + + return ( + +
+
+ +

+ {notification.title || '-'} +

+
+ +
+