'use client' import { type MDXRemoteSerializeResult } from "next-mdx-remote"; import { serialize } from "next-mdx-remote/serialize"; import { MDXRemote } from 'next-mdx-remote/rsc' // import { promises as fs } from "fs"; import { MdxContent } from "../../../components/mdx-content"; // import { Web3Provider } from "@/components/providers/web3-provider"; import { Header, NavBack } from "@/components/header"; import { Footer } from "@/components/footer"; import { Button, Checkbox, Form, GetProp, Input, Radio, RadioChangeEvent, Space } from "antd"; import { useEffect, useRef, useState } from "react"; import service from "@/lib/http/service"; import toast from 'react-hot-toast'; import { UserData } from "@/components/user-menu"; import { useLocalStorage } from "@/lib/hooks/use-local-storage"; import { useTranslation } from "react-i18next"; import Link from "next/link"; import { useSearchParams } from "next/navigation"; import { LoadingView } from "@/components/ui/loading"; import { cn } from "@/lib/utils"; type Frontmatter = { title: string; date: string; }; type Post = { serialized: MDXRemoteSerializeResult; frontmatter: TFrontmatter; }; // export const runtime = "nodejs"; export const runtime = "edge"; interface ExtraData { logs: any; // 此处的类型需根据实际数据类型确定 } export interface Info { email: string; first_name: string; last_name: string; title: string; company: string; tags: string[]; } export interface TagInfo { id: number; name: string; name_cn: string; is_inherent: boolean; //是否内置 不可操作 is_deleted: boolean; // checked: boolean; // created_time: string; updated_time: string; label?: string; extra_data: ExtraData; } type CheckboxValueType = GetProp[number]; export default function PostsPage() { // Get the serialized content and frontmatter const infoRef = useRef({ email: "", first_name: "", last_name: "", title: "", company: "", tags: [], }); const [form] = Form.useForm(); const [clientReady, setClientReady] = useState(false); const [isLoading, setIsLoading] = useState(false); const [isLoadingInfo, setIsLoadingInfo] = useState(false); const [initLoading, setInitLoading] = useState(true); const [isSubscribe, setIsSubscribe] = useState(false); const [isOther, setIsOther] = useState(false); const [tagsRef, setTagsRef] = useState([]); const [tagsRefList, setTagsRefList] = useState([]); const [checkedList, setCheckedList] = useState([]); const [checked, setChecked] = useState(true); const { t, i18n } = useTranslation() const language = i18n.language const [userData, setUserData] = useLocalStorage( 'UserData', { auth_token: "", id: 1, login_ip: "", login_time: 0, role: "", user_name: "", version: "" } as UserData ) const searchParams = useSearchParams() const email = searchParams.get('email') if (!!email) { infoRef.current.email = email } if (!!userData.auth_token) { infoRef.current.email = userData.user_name } // let first_name = "" // let last_name = "" // let title = "" // let company = "" // let tags = [] as string[] // console.log("email", email, userData.auth_token) // To disable submit button at the beginning. useEffect(() => { // console.log("------------email", infoRef.current, userData.auth_token) if (!!infoRef.current.email) { setIsLoadingInfo(true); async function initFunc() { await service.post('/api/v1/customer/sub-info', { email: infoRef.current.email }, { headers: { // 'Authorization': token } }).then(function (result: any) { console.log("result:", result) if (result && result.header.code != 0) { toast.error(result.header.message) return } // categoriesRef.current.values infoRef.current.first_name = result.data.first_name infoRef.current.last_name = result.data.last_name infoRef.current.title = result.data.title infoRef.current.company = result.data.company infoRef.current.tags = result.data.tags setIsLoadingInfo(false); }).catch((err) => { console.log(err); }); } initFunc() } setClientReady(true); }, [userData]); useEffect(() => { let isMounted = true setInitLoading(true); async function initFunc() { await service.post('/api/v1/tag/list', { }, { headers: { // 'Authorization': token } }).then(function (result: any) { console.log("result:", result) if (result && result.header.code != 0) { toast.error(result.header.message) return } // categoriesRef.current.values const tags = result.data.list // setCheckedList(tags.map((i: TagInfo) => i.name)) infoRef.current.tags = tags.map((i: TagInfo) => i.name) setTagsRef(tags.map((r: TagInfo) => { return { ...r, checked: true } })) setTimeout(() => { console.log('-----checkedList--------', tags.map((r: TagInfo) => { return { ...r, checked: true } })) setInitLoading(false); }, 1000); // form.setFieldValue('email', email); }).catch((err) => { setInitLoading(false); console.log(err); }); } initFunc() return () => { isMounted = false } }, []) const [value, setValue] = useState(1); const onChange = (e: RadioChangeEvent) => { console.log('radio checked', e.target.value); if (e.target.value == "Other") { setIsOther(true) } else { setIsOther(false) } setValue(e.target.value); }; const onFinish = async (values: any) => { console.log('Finish:', values); const token = userData.auth_token // if (!token) { // router.push('/auth/sign-in') // return // } // /api/v1/customer/subscribe if (isLoading) return setIsLoading(true); let result: any = await service.post('/api/v1/customer/edit', { language, "first_name": values.first_name, "last_name": values.last_name, "title": values.title, "company": values.company, "email": values.email, }, { headers: { 'Authorization': token } }) setIsLoading(false); console.log("result:", result) if (result && result.header.code != 0) { toast.error(result.header.message) return } if (!values.unall) { // let tags: string[] = [] // if (values.remember) { // tags.push("#Blockchain") // } // if (values.remember2) { // tags.push("#AI") // } console.log("values.first_name", values.first_name) // setIsLoading(true); let result2: any = await service.post('/api/v1/customer/subscribe', { language, "first_name": values.first_name, "email": values.email, "tags": values.tags || [] }, { headers: { 'Authorization': token } }) setIsLoading(false); console.log("result:", result2) if (result2 && result2.header.code != 0) { toast.error(result2.header.message) return } } else { let reason = values.why if (values.why == "Other") { reason = values.whyOther } setIsLoading(true); let result3: any = await service.post('/api/v1/customer/unsubscribe', { language, "email": values.email, "reason": reason }, { headers: { 'Authorization': token } }) setIsLoading(false); console.log("result:", result3) if (result3 && result3.header.code != 0) { toast.error(result3.header.message) return } } toast.success("OK") }; return ( <> {/* */} { !initLoading && !isLoadingInfo ?
1 ? 'fixed bottom-0 bg-[#f6f6f6] z-[999]' : "absolute bg-[#fff]" )} >

{t("subscribe.manage_subscription")}

{t("subscribe.your_profile")}
{t("subscribe.expert_news")}

{t("subscribe.subscription_text")}

{/* { console.log('checked = ', e.target.checked); tagsRef[index].checked = e.target.checked }} checked={item.checked} className="w-full whitespace-nowrap" >{language == 'en' ? item.name : item.name_cn} */} {/* {options.map((r, i) => { return {r.label} })} */} {!initLoading && !isSubscribe && i.name)} // value={checkedList} value={checkedList} onChange={(list) => { console.log('----Checkbox.Group------', list) setCheckedList(list) }} > {/* { tagsRef.map((item, index) => { return { console.log('checked = ', e); // setCheckedList(list); // tagsRef[index].checked = e.target.checked setTagsRef(tagsRef.map((r: TagInfo, i: number) => { if (index = i) { return { ...r, checked: e.target.checked } } return r })) }}>{language == 'en' ? item.name : item.name_cn} }) } */} } {/* {t("subscribe.cryptocurrency")} {t("subscribe.ai")} */}
{ console.log(e.target.checked) setIsSubscribe(e.target.checked) }}>{t("subscribe.unsubscribe_from_all")}
{isSubscribe &&
{t("subscribe.tell_us_why")}
{ [ t("subscribe.reason1"), t("subscribe.reason2"), t("subscribe.reason3"), t("subscribe.reason4"), // "Other", ].map((arg, i) => { return {arg} }) } {t("subscribe.reason5")} {isOther &&
}
} {() => ( )}
: } {/*