2025-11-24 03:47:20 +00:00
|
|
|
import { useEffect } from "react";
|
2025-11-13 08:38:25 +00:00
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
|
|
|
import { useCurrentUser, useToken } from "./auth";
|
|
|
|
|
import { useSetAtom } from "jotai";
|
|
|
|
|
import { isCreateAiLimitReachedDialogOpenAtom } from "@/atoms/global";
|
|
|
|
|
import { VipType } from "@/services/wallet";
|
|
|
|
|
import { isVipDrawerOpenAtom } from "@/atoms/im";
|
|
|
|
|
|
2025-11-24 03:47:20 +00:00
|
|
|
const CREATE_CHARACTER_ROUTE = "/create/type";
|
|
|
|
|
|
2025-11-13 08:38:25 +00:00
|
|
|
const useCreatorNavigation = () => {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const { data: currentUser } = useCurrentUser();
|
|
|
|
|
const { isLogin } = useToken();
|
|
|
|
|
const { isMember, canCreateAiCount, createdAiCount } = currentUser || {}
|
|
|
|
|
const setIsCreateAiLimitReachedDialogOpen = useSetAtom(isCreateAiLimitReachedDialogOpenAtom)
|
|
|
|
|
const setIsVipDrawerOpen = useSetAtom(isVipDrawerOpenAtom)
|
|
|
|
|
|
2025-11-24 03:47:20 +00:00
|
|
|
const loginRedirectHref = `/login?redirect=${encodeURIComponent(CREATE_CHARACTER_ROUTE)}`;
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
router.prefetch(CREATE_CHARACTER_ROUTE);
|
|
|
|
|
router.prefetch(loginRedirectHref);
|
|
|
|
|
}, [router, loginRedirectHref]);
|
|
|
|
|
|
2025-11-13 08:38:25 +00:00
|
|
|
const routerToCreate = () => {
|
|
|
|
|
// 检查是否登录,如果未登录则跳转到登录页面
|
|
|
|
|
if (!isLogin) {
|
2025-11-24 03:47:20 +00:00
|
|
|
router.push(loginRedirectHref);
|
2025-11-13 08:38:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((createdAiCount ?? 0) >= (canCreateAiCount ?? 0)) {
|
|
|
|
|
if (isMember) {
|
|
|
|
|
setIsCreateAiLimitReachedDialogOpen(true)
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
setIsVipDrawerOpen({ open: true, vipType: VipType.ADD_CREATE_AI })
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localStorage.setItem('before_creator_navigation', pathname);
|
2025-11-24 03:47:20 +00:00
|
|
|
router.push(CREATE_CHARACTER_ROUTE);
|
2025-11-13 08:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
routerToCreate,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 03:47:20 +00:00
|
|
|
export default useCreatorNavigation;
|