From 153246b0db57d266a5e4e6c080245b76422ded56 Mon Sep 17 00:00:00 2001 From: Mack <103027852+mackt@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:02:15 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=A2=AB=E9=82=80=E8=AF=B7=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/invite/page.tsx | 51 +++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/app/invite/page.tsx b/src/app/invite/page.tsx index bae5459..ded6e3f 100644 --- a/src/app/invite/page.tsx +++ b/src/app/invite/page.tsx @@ -1,31 +1,68 @@ +/** + * 邀请 分享页 + */ 'use client'; -import { useEffect } from 'react'; + +import { useEffect, useState, useCallback } from 'react'; + +import Image from 'next/image'; import DownloadButton from '@/components/DownloadButton'; +async function fetchInviteInfo(code: string) { + const res = await fetch(`${process.env.NEXT_PUBLIC_HOST}/user/my/userInfo/invite?inviteCode=${code}`); + return res.json(); +} + export default function Invite() { + const [inviteCode, setInviteCode] = useState(null); + const [userInfo, setUserInfo] = useState<{ nickName: string; avatar: string; inviteCode: string } | null>(null); + + const getInviteInfo = useCallback( + (code: string) => { + fetchInviteInfo(code).then((res) => { + if (res.data) setUserInfo(res.data); + }); + }, + [inviteCode], + ); + useEffect(() => { document.title = '加入雀乐'; + const searchParams = new URLSearchParams(window.location.search); + const code = searchParams.get('code'); + if (code) { + setInviteCode(code); + getInviteInfo(code); + } }, []); return (
-
-
+
+
-

{`${1},邀请你加入雀乐`}

+

{`${userInfo?.nickName ?? ''},邀请你加入雀乐`}

一起 记录独立音乐

-
- +
+ +
推荐码
-
xxxxxxx
+
{userInfo?.inviteCode ?? ''}

填写邀请码,双方均可获得积分