|
@@ -1,5 +1,10 @@
|
|
|
"use client";
|
|
|
-import { GlobalNoticeRep, updateGlobalNoticeApi, updateUserNoticeApi } from "@/api/home";
|
|
|
+import {
|
|
|
+ EmailNoticeRep,
|
|
|
+ GlobalNoticeRep,
|
|
|
+ updateGlobalNoticeApi,
|
|
|
+ updateUserNoticeApi,
|
|
|
+} from "@/api/home";
|
|
|
import Tabs from "@/components/Tabs";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
import { FC, useState } from "react";
|
|
@@ -10,6 +15,7 @@ import { default as Notices } from "./components/Notices";
|
|
|
interface Props {
|
|
|
systemNotices: GlobalNoticeRep[];
|
|
|
userNotices: GlobalNoticeRep[];
|
|
|
+ emailNotices: EmailNoticeRep[];
|
|
|
}
|
|
|
const setReadData = (data: GlobalNoticeRep[], key: number) => {
|
|
|
const newNotices = data.map((item) => {
|
|
@@ -24,6 +30,7 @@ const setReadData = (data: GlobalNoticeRep[], key: number) => {
|
|
|
const NotificationClient: FC<Props> = (props) => {
|
|
|
const [systemNotices, setSystemNotices] = useState(props.systemNotices);
|
|
|
const [userNotices, setUserNotices] = useState(props.userNotices);
|
|
|
+ const [emailNotices, setEmailNotices] = useState(props.emailNotices || []);
|
|
|
const t = useTranslations("ProfilePage");
|
|
|
const handler = async (active: string, key: string) => {
|
|
|
if (key === "system") {
|
|
@@ -31,15 +38,23 @@ const NotificationClient: FC<Props> = (props) => {
|
|
|
if (isRead) return;
|
|
|
updateGlobalNoticeApi(+active).then((r) => {});
|
|
|
setSystemNotices(setReadData(systemNotices, +active));
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ if (key === "user") {
|
|
|
const isRead = userNotices.find((item) => item.id === +active)?.is_read;
|
|
|
if (isRead) return;
|
|
|
setUserNotices(setReadData(userNotices, +active));
|
|
|
updateUserNoticeApi(+active).then((r) => {});
|
|
|
}
|
|
|
+ if (key === "email") {
|
|
|
+ // const isRead = userNotices.filter((item) => item.status === 0);
|
|
|
+ // if (!isRead) return;
|
|
|
+ // setUserNotices(setReadData(userNotices, +active));
|
|
|
+ // updateUserNoticeApi(+active).then((r) => {});
|
|
|
+ }
|
|
|
|
|
|
await actions();
|
|
|
};
|
|
|
+
|
|
|
const defaultTabs = [
|
|
|
{
|
|
|
id: 1,
|
|
@@ -71,8 +86,11 @@ const NotificationClient: FC<Props> = (props) => {
|
|
|
<div>{t("email")}</div>
|
|
|
</div>
|
|
|
),
|
|
|
- content: userNotices.reduce((count, notice) => count + (notice.is_read ? 0 : 1), 0),
|
|
|
- render: <Email></Email>,
|
|
|
+ content: emailNotices.reduce(
|
|
|
+ (count, notice) => count + (notice.status === 0 ? 0 : 1),
|
|
|
+ 0
|
|
|
+ ),
|
|
|
+ render: <Email data={emailNotices}></Email>,
|
|
|
},
|
|
|
];
|
|
|
return <Tabs items={defaultTabs} />;
|