v2.0
This commit is contained in:
parent
c15bd28871
commit
308ed895a0
@ -1,5 +1,6 @@
|
||||
import { useTranslations } from "next-intl";
|
||||
import CreateTabs from "@/ui/(console)/create/create-tabs";
|
||||
import PaypalCallback from "./paypalCallback";
|
||||
|
||||
export default function Page() {
|
||||
const t = useTranslations("createPage");
|
||||
@ -19,6 +20,7 @@ export default function Page() {
|
||||
<CreateTabs />
|
||||
</div>
|
||||
</div>
|
||||
<PaypalCallback />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
47
src/app/(console)/create/paypalCallback.tsx
Normal file
47
src/app/(console)/create/paypalCallback.tsx
Normal file
@ -0,0 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import useFetch from "@/hooks/useFetch";
|
||||
import { useEffect } from "react";
|
||||
import { useSearchParams, useRouter } from "next/navigation";
|
||||
import { useToast } from "@/contexts/ToastContext";
|
||||
import { useTranslations } from "next-intl";
|
||||
import useUser from "@/hooks/useUser";
|
||||
|
||||
export default function PaypalCallback() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const paymentId = searchParams.get("paymentId");
|
||||
const token = searchParams.get("token");
|
||||
const PayerID = searchParams.get("PayerID");
|
||||
const t = useTranslations("pricing");
|
||||
const { addToastSuccess } = useToast();
|
||||
const { updateUser } = useUser();
|
||||
const {
|
||||
fetchData: executePayment,
|
||||
loading: paymentLoading,
|
||||
data: paymentData,
|
||||
} = useFetch({
|
||||
url: "/api/paypal/execute/",
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (paymentId && token && PayerID) {
|
||||
executePayment({
|
||||
paymentId,
|
||||
PayerID,
|
||||
})
|
||||
.then(() => {
|
||||
addToastSuccess(t("PaymentSuccess"));
|
||||
// 删除URL上的参数
|
||||
})
|
||||
.finally(() => {
|
||||
const newUrl = window.location.pathname;
|
||||
window.history.replaceState(null, "", newUrl);
|
||||
updateUser();
|
||||
});
|
||||
}
|
||||
}, [paymentId, token, PayerID]);
|
||||
|
||||
return null;
|
||||
}
|
38
src/hooks/useUser.tsx
Normal file
38
src/hooks/useUser.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import useFetch from "@/hooks/useFetch";
|
||||
import useUserStore from "@/store/userStore";
|
||||
|
||||
export default function useUser() {
|
||||
const setUser = useUserStore((state) => state.setUser);
|
||||
|
||||
const {
|
||||
fetchData: GetUserinfo,
|
||||
loading: userinfoLoading,
|
||||
data: userinfoData,
|
||||
} = useFetch({
|
||||
url: "/api/profile/",
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
const updateUser = async () => {
|
||||
try {
|
||||
const res = await GetUserinfo();
|
||||
console.log("userinfo", res);
|
||||
setUser(res);
|
||||
} catch (error) {
|
||||
console.error("Error updating user:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// useEffect(() => {
|
||||
// updateUser();
|
||||
// }, []); // 空数组依赖确保只在组件挂载时执行一次
|
||||
|
||||
return {
|
||||
updateUser,
|
||||
userinfoLoading,
|
||||
userinfoData,
|
||||
};
|
||||
}
|
@ -238,14 +238,14 @@ export default function LoginForm({ toRegister }: LoginFormProps) {
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleGetCaptcha}
|
||||
className="btn h-10 btn-sm w-32 ml-2 bg-transparent hover:bg-green-500 hover:text-white text-gray-500 rounded-lg"
|
||||
className="btn h-10 btn-sm w-32 ml-2 bg-transparent hover:bg-green-500 hover:text-white text-gray-200 rounded-lg"
|
||||
disabled={
|
||||
captchaTimer > 0 ||
|
||||
captchaLoading
|
||||
}
|
||||
>
|
||||
{captchaLoading ? (
|
||||
<span className="loading loading-spinner loading-md"></span>
|
||||
<span className="loading loading-spinner loading-md text-gray-200"></span>
|
||||
) : captchaTimer > 0 ? (
|
||||
`${captchaTimer}s`
|
||||
) : (
|
||||
|
Loading…
Reference in New Issue
Block a user