From 4a6fb229d85599a215170fefa957e36e8a7aa1ec Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 22 Dec 2025 09:10:09 +0330 Subject: [PATCH] notification perfer --- .env | 4 +- .../components/EditNotificationTypeModal.tsx | 66 ++++++++++++++----- .../components/NotificationTableColumns.tsx | 51 ++++++++++---- src/pages/notifications/enum/Enum.ts | 3 +- .../hooks/useNotificationData.ts | 7 +- .../service/NotificationService.ts | 5 +- src/pages/notifications/types/Types.ts | 2 +- 7 files changed, 95 insertions(+), 43 deletions(-) diff --git a/.env b/.env index 7bf4b8d..afe24ad 100644 --- a/.env +++ b/.env @@ -1,7 +1,7 @@ VITE_TOKEN_NAME = 'dmnu_a_t' VITE_REFRESH_TOKEN_NAME = 'dmnu-a-rt' -VITE_BASE_URL = 'https://dmenuplus-api.dev.danakcorp.com' -# VITE_BASE_URL = 'http://192.168.99.242:4000' +# VITE_BASE_URL = 'https://dmenuplus-api.dev.danakcorp.com' +VITE_BASE_URL = 'http://192.168.99.242:4000' VITE_SOCKET_URL = 'https://dmenuplus-api.dev.danakcorp.com' \ No newline at end of file diff --git a/src/pages/notifications/components/EditNotificationTypeModal.tsx b/src/pages/notifications/components/EditNotificationTypeModal.tsx index c477d51..46a9e37 100644 --- a/src/pages/notifications/components/EditNotificationTypeModal.tsx +++ b/src/pages/notifications/components/EditNotificationTypeModal.tsx @@ -1,9 +1,8 @@ import { type FC, useState, useEffect } from 'react' import DefaulModal from '@/components/DefaulModal' -import Select from '@/components/Select' import Button from '@/components/Button' +import { Checkbox } from '@/components/ui/checkbox' import { useUpdateNotification } from '../hooks/useNotificationData' -import { NotificationType } from '../enum/Enum' import type { Notification } from '../types/Types' interface Props { @@ -12,29 +11,50 @@ interface Props { notification: Notification | null } +type ChannelType = "sms" | "push" | "in-app" + +const channelOptions: { value: ChannelType; label: string }[] = [ + { value: "sms", label: 'پیامک' }, + { value: "push", label: 'پوش' }, + { value: "in-app", label: 'درون برنامه' }, +] + +const getTitleLabel = (title: string): string => { + const titleMap: Record = { + 'order.created': 'سفارش ایجاد شد', + 'order.status.changed': 'تغییر وضعیت سفارش', + 'pager.created': 'پیجر ایجاد شد', + 'payment.success': 'پرداخت موفق', + 'review.created': 'نظر ایجاد شد', + } + return titleMap[title] || title +} + const EditNotificationTypeModal: FC = ({ open, close, notification }) => { - const [selectedType, setSelectedType] = useState(NotificationType.NONE) + const [selectedChannels, setSelectedChannels] = useState([]) const { mutate: updateNotification, isPending } = useUpdateNotification() useEffect(() => { if (notification) { - setSelectedType(notification.notificationType as NotificationType) + setSelectedChannels([...notification.channels]) } }, [notification]) if (!notification) return null - const notificationTypeOptions = [ - { value: NotificationType.SMS, label: 'پیامک' }, - { value: NotificationType.PUSH, label: 'پوش' }, - { value: NotificationType.Both, label: 'هر دو' }, - ] + const handleToggleChannel = (channel: ChannelType, checked: boolean) => { + if (checked) { + setSelectedChannels((prev) => [...prev, channel]) + } else { + setSelectedChannels((prev) => prev.filter((c) => c !== channel)) + } + } const handleSubmit = () => { updateNotification( { id: notification.id, - notificationType: selectedType, + channels: selectedChannels, }, { onSuccess: () => { @@ -58,17 +78,29 @@ const EditNotificationTypeModal: FC = ({ open, close, notification }) => عنوان

- {notification.title || '-'} + {notification.title ? getTitleLabel(notification.title) : '-'}

-