From b90bc9f65de07dae9befb16c66aef07e08beb196 Mon Sep 17 00:00:00 2001 From: jingyang <72259332+zjy365@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:10:28 +0800 Subject: [PATCH] update:dbprovider Pause Hint message (#4902) * update:dbprovider Pause Hint message * fix notifications * fix guide * update workorder * fix (cherry picked from commit e292b8417fbd41910c53736103a7d42cb9348866) --- .../src/components/notification/index.tsx | 119 +++-- .../dbprovider/public/locales/en/common.json | 472 +++++++++-------- .../dbprovider/public/locales/zh/common.json | 475 +++++++++--------- .../src/pages/api/workorder/check.ts | 12 +- 4 files changed, 544 insertions(+), 534 deletions(-) diff --git a/frontend/desktop/src/components/notification/index.tsx b/frontend/desktop/src/components/notification/index.tsx index b06b1b2be7d..6d680a421b9 100644 --- a/frontend/desktop/src/components/notification/index.tsx +++ b/frontend/desktop/src/components/notification/index.tsx @@ -10,28 +10,27 @@ import { produce } from 'immer'; import { useTranslation } from 'next-i18next'; import { useEffect, useRef, useState } from 'react'; import styles from './index.module.scss'; -import { TNotification } from '@/types'; -import { listNotification } from '@/api/platform'; +import { NotificationItem } from '@/types'; -type NotificationProps = { +type TNotification = { disclosure: UseDisclosureReturn; onAmount: (amount: number) => void; }; -export default function Notification(props: NotificationProps) { +export default function Notification(props: TNotification) { const { t, i18n } = useTranslation(); const { disclosure, onAmount } = props; const { installedApps, openApp } = useAppStore(); - const [readNotes, setReadNotes] = useState([]); - const [unReadNotes, setUnReadNotes] = useState([]); + const [readNotes, setReadNotes] = useState([]); + const [unReadNotes, setUnReadNotes] = useState([]); const { message } = useMessage(); const isForbiddenRef = useRef(false); const [MessageConfig, setMessageConfig] = useState<{ activeTab: 'read' | 'unread'; activePage: 'index' | 'detail'; - msgDetail?: TNotification; - popupMessage?: TNotification; + msgDetail?: NotificationItem; + popupMessage?: NotificationItem; }>({ activeTab: 'unread', activePage: 'index', @@ -39,26 +38,35 @@ export default function Notification(props: NotificationProps) { popupMessage: undefined }); - const { refetch } = useQuery(['getNotifications'], () => listNotification(), { - onSuccess: (data) => { - if (data.data) { - handleNotificationData(data.data); - } - }, - refetchInterval: 5 * 60 * 1000, - staleTime: 5 * 60 * 1000 - }); + const { refetch } = useQuery( + ['getNotifications'], + () => request('/api/notification/listNotification'), + { + onSuccess: (data) => { + const messages = data?.data?.items as NotificationItem[]; + if (messages) { + handleNotificationData(messages); + } + }, + refetchInterval: 5 * 60 * 1000, + staleTime: 5 * 60 * 1000 + } + ); - const compareByTimestamp = (a: TNotification, b: TNotification) => b?.timestamp - a?.timestamp; + const handleNotificationData = (data: NotificationItem[]) => { + const parseIsRead = (item: NotificationItem) => + JSON.parse(item?.metadata?.labels?.isRead || 'false'); - const handleNotificationData = (data: TNotification[]) => { - const unReadMessage = data.filter((item) => !item.isRead); - const readMessage = data.filter((item) => item.isRead); + const unReadMessage = data.filter((item) => !parseIsRead(item)); + const readMessage = data.filter(parseIsRead); + + const compareByTimestamp = (a: NotificationItem, b: NotificationItem) => + b?.spec?.timestamp - a?.spec?.timestamp; unReadMessage.sort(compareByTimestamp); readMessage.sort(compareByTimestamp); - if (unReadMessage?.[0]?.desktopPopup && !isForbiddenRef.current) { + if (unReadMessage?.[0]?.spec?.desktopPopup && !isForbiddenRef.current) { setMessageConfig( produce((draft) => { draft.popupMessage = unReadMessage[0]; @@ -93,9 +101,9 @@ export default function Notification(props: NotificationProps) { } }); - const goMsgDetail = (item: TNotification) => { + const goMsgDetail = (item: NotificationItem) => { if (MessageConfig.activeTab === 'unread') { - readMsgMutation.mutate([item?.name]); + readMsgMutation.mutate([item?.metadata?.name]); } setMessageConfig( produce((draft) => { @@ -107,7 +115,7 @@ export default function Notification(props: NotificationProps) { }; const markAllAsRead = () => { - const names = unReadNotes?.map((item: TNotification) => item?.name); + const names = unReadNotes?.map((item: NotificationItem) => item?.metadata?.name); readMsgMutation.mutate(names); setMessageConfig( produce((draft) => { @@ -170,7 +178,9 @@ export default function Notification(props: NotificationProps) { {MessageConfig.activePage === 'index' ? t('common:message_center') - : MessageConfig.msgDetail?.i18n[i18n.language]?.title} + : i18n.language === 'zh' && MessageConfig.msgDetail?.spec?.i18ns?.zh?.title + ? MessageConfig.msgDetail?.spec?.i18ns?.zh?.title + : MessageConfig.msgDetail?.spec?.title} {MessageConfig.activePage === 'index' ? ( @@ -213,18 +223,24 @@ export default function Notification(props: NotificationProps) { - {notifications?.map((item: TNotification) => { + {notifications?.map((item: NotificationItem) => { return ( goMsgDetail(item)} > - {item.i18n[i18n.language]?.title} + + {i18n.language === 'zh' && item.spec?.i18ns?.zh?.title + ? item.spec?.i18ns?.zh?.title + : item?.spec?.title} + - {item.i18n[i18n.language]?.message} + {i18n.language === 'zh' && item.spec?.i18ns?.zh?.message + ? item.spec?.i18ns?.zh?.message + : item?.spec?.message} - {t('common:from')}「{item.i18n[i18n.language]?.from}」 + {t('common:from')}「 + {i18n.language === 'zh' && item.spec?.i18ns?.zh?.from + ? item.spec?.i18ns?.zh?.from + : item?.spec?.from} + 」 + + + {formatTime((item?.spec?.timestamp || 0) * 1000, 'YYYY-MM-DD HH:mm')} - {formatTime((item?.timestamp || 0) * 1000, 'YYYY-MM-DD HH:mm')} ); @@ -257,10 +279,17 @@ export default function Notification(props: NotificationProps) { fontWeight="400" > - {t('common:from')}「{MessageConfig.msgDetail?.i18n[i18n.language]?.from}」 + {t('common:from')}「 + {i18n.language === 'zh' && MessageConfig.msgDetail?.spec?.i18ns?.zh?.from + ? MessageConfig.msgDetail?.spec?.i18ns?.zh?.from + : MessageConfig.msgDetail?.spec?.from} + 」 - {formatTime((MessageConfig.msgDetail?.timestamp || 0) * 1000, 'YYYY-MM-DD HH:mm')} + {formatTime( + (MessageConfig.msgDetail?.spec?.timestamp || 0) * 1000, + 'YYYY-MM-DD HH:mm' + )} - {MessageConfig.msgDetail?.i18n[i18n.language]?.message} + {i18n.language === 'zh' && MessageConfig.msgDetail?.spec?.i18ns?.zh?.message + ? MessageConfig.msgDetail?.spec?.i18ns?.zh?.message + : MessageConfig.msgDetail?.spec?.message} - {MessageConfig.msgDetail?.i18n['en']?.from === 'Debt-System' && ( + {MessageConfig.msgDetail?.spec?.from === 'Debt-System' && ( - {MessageConfig.msgDetail?.i18n['en']?.from === 'Debt-System' && ( + {MessageConfig.msgDetail?.spec?.from === 'Debt-System' && (