|
@@ -1,14 +1,32 @@
|
|
"use client";
|
|
"use client";
|
|
-import { GlobalNoticeRep, updateGlobalNoticeApi, updateUserNoticeApi } from "@/api/home";
|
|
|
|
|
|
+import {
|
|
|
|
+ EmailNoticeRep,
|
|
|
|
+ GlobalNoticeRep,
|
|
|
|
+ updateGlobalNoticeApi,
|
|
|
|
+ updateUserNoticeApi,
|
|
|
|
+} from "@/api/home";
|
|
import Tabs from "@/components/Tabs";
|
|
import Tabs from "@/components/Tabs";
|
|
|
|
+import { useRouter } from "@/i18n/routing";
|
|
|
|
+import { server } from "@/utils/client";
|
|
import { useTranslations } from "next-intl";
|
|
import { useTranslations } from "next-intl";
|
|
|
|
+import { useSearchParams } from "next/navigation";
|
|
import { FC, useState } from "react";
|
|
import { FC, useState } from "react";
|
|
import actions from "./actions";
|
|
import actions from "./actions";
|
|
|
|
+import Email from "./components/Email";
|
|
import { default as Notices } from "./components/Notices";
|
|
import { default as Notices } from "./components/Notices";
|
|
|
|
|
|
|
|
+const getEmailNotices = () => {
|
|
|
|
+ return server.request<EmailNoticeRep[]>({
|
|
|
|
+ url: "/v1/api/user/mail/getMailList",
|
|
|
|
+ method: "POST",
|
|
|
|
+ data: {},
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
interface Props {
|
|
interface Props {
|
|
systemNotices: GlobalNoticeRep[];
|
|
systemNotices: GlobalNoticeRep[];
|
|
userNotices: GlobalNoticeRep[];
|
|
userNotices: GlobalNoticeRep[];
|
|
|
|
+ emailNotices: EmailNoticeRep[];
|
|
}
|
|
}
|
|
const setReadData = (data: GlobalNoticeRep[], key: number) => {
|
|
const setReadData = (data: GlobalNoticeRep[], key: number) => {
|
|
const newNotices = data.map((item) => {
|
|
const newNotices = data.map((item) => {
|
|
@@ -21,8 +39,14 @@ const setReadData = (data: GlobalNoticeRep[], key: number) => {
|
|
return newNotices;
|
|
return newNotices;
|
|
};
|
|
};
|
|
const NotificationClient: FC<Props> = (props) => {
|
|
const NotificationClient: FC<Props> = (props) => {
|
|
|
|
+ const searchParams = useSearchParams();
|
|
|
|
+ const router = useRouter();
|
|
const [systemNotices, setSystemNotices] = useState(props.systemNotices);
|
|
const [systemNotices, setSystemNotices] = useState(props.systemNotices);
|
|
const [userNotices, setUserNotices] = useState(props.userNotices);
|
|
const [userNotices, setUserNotices] = useState(props.userNotices);
|
|
|
|
+ const [emailNotices, setEmailNotices] = useState(props.emailNotices || []);
|
|
|
|
+
|
|
|
|
+ const [actKey, setActKey] = useState(searchParams.get("type") || "1");
|
|
|
|
+
|
|
const t = useTranslations("ProfilePage");
|
|
const t = useTranslations("ProfilePage");
|
|
const handler = async (active: string, key: string) => {
|
|
const handler = async (active: string, key: string) => {
|
|
if (key === "system") {
|
|
if (key === "system") {
|
|
@@ -30,29 +54,71 @@ const NotificationClient: FC<Props> = (props) => {
|
|
if (isRead) return;
|
|
if (isRead) return;
|
|
updateGlobalNoticeApi(+active).then((r) => {});
|
|
updateGlobalNoticeApi(+active).then((r) => {});
|
|
setSystemNotices(setReadData(systemNotices, +active));
|
|
setSystemNotices(setReadData(systemNotices, +active));
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ if (key === "user") {
|
|
const isRead = userNotices.find((item) => item.id === +active)?.is_read;
|
|
const isRead = userNotices.find((item) => item.id === +active)?.is_read;
|
|
if (isRead) return;
|
|
if (isRead) return;
|
|
setUserNotices(setReadData(userNotices, +active));
|
|
setUserNotices(setReadData(userNotices, +active));
|
|
updateUserNoticeApi(+active).then((r) => {});
|
|
updateUserNoticeApi(+active).then((r) => {});
|
|
}
|
|
}
|
|
|
|
+ if (key === "email") {
|
|
|
|
+ const res = await getEmailNotices();
|
|
|
|
+ setEmailNotices(res?.data || []);
|
|
|
|
+ }
|
|
|
|
|
|
await actions();
|
|
await actions();
|
|
};
|
|
};
|
|
|
|
+
|
|
const defaultTabs = [
|
|
const defaultTabs = [
|
|
{
|
|
{
|
|
id: 1,
|
|
id: 1,
|
|
- name: t("systemMessage"),
|
|
|
|
|
|
+ key: "1",
|
|
|
|
+ name: (
|
|
|
|
+ <div className="flex items-center text-[.14rem]">
|
|
|
|
+ <i className="iconfont icon-laba mr-[.02rem] text-[.14rem]"></i>
|
|
|
|
+ <div>{t("systemMessage")}</div>
|
|
|
|
+ </div>
|
|
|
|
+ ),
|
|
content: systemNotices.reduce((count, notice) => count + (notice.is_read ? 0 : 1), 0),
|
|
content: systemNotices.reduce((count, notice) => count + (notice.is_read ? 0 : 1), 0),
|
|
render: <Notices data={systemNotices} type={"system"} handler={handler} />,
|
|
render: <Notices data={systemNotices} type={"system"} handler={handler} />,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 2,
|
|
id: 2,
|
|
- name: t("personalMessage"),
|
|
|
|
|
|
+ key: "2",
|
|
|
|
+ name: (
|
|
|
|
+ <div className="flex items-center text-[.14rem]">
|
|
|
|
+ <i className="iconfont icon-yonghu mr-[.02rem] text-[.16rem]"></i>
|
|
|
|
+ <div>{t("personalMessage")}</div>
|
|
|
|
+ </div>
|
|
|
|
+ ),
|
|
content: userNotices.reduce((count, notice) => count + (notice.is_read ? 0 : 1), 0),
|
|
content: userNotices.reduce((count, notice) => count + (notice.is_read ? 0 : 1), 0),
|
|
render: <Notices data={userNotices} type={"user"} handler={handler} />,
|
|
render: <Notices data={userNotices} type={"user"} handler={handler} />,
|
|
},
|
|
},
|
|
|
|
+ {
|
|
|
|
+ id: 3,
|
|
|
|
+ key: "3",
|
|
|
|
+ name: (
|
|
|
|
+ <div className="flex items-center text-[.14rem]">
|
|
|
|
+ <i className="iconfont icon-duanxinguanli mr-[.02rem] text-[.18rem]"></i>
|
|
|
|
+ <div>{t("email")}</div>
|
|
|
|
+ </div>
|
|
|
|
+ ),
|
|
|
|
+ content: emailNotices.reduce(
|
|
|
|
+ (count, notice) => count + (notice.status === 0 ? 1 : 0),
|
|
|
|
+ 0
|
|
|
|
+ ),
|
|
|
|
+ render: <Email data={emailNotices} handler={handler}></Email>,
|
|
|
|
+ },
|
|
];
|
|
];
|
|
- return <Tabs items={defaultTabs} />;
|
|
|
|
|
|
+ return (
|
|
|
|
+ <Tabs
|
|
|
|
+ items={defaultTabs}
|
|
|
|
+ activeKey={actKey}
|
|
|
|
+ onChanage={(key) => {
|
|
|
|
+ setActKey(key as string);
|
|
|
|
+ router.replace(`/notification?type=${key}`);
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ );
|
|
};
|
|
};
|
|
export default NotificationClient;
|
|
export default NotificationClient;
|