"use client"; // import { useSignUp } from "@clerk/nextjs"; import { useRouter } from "next/navigation"; import * as React from "react"; import { Loading } from "@/components/ui/loading"; import { toast } from "@/components/ui/toaster"; import { cn } from "@/lib/utils"; import { OTPInput, SlotProps } from "input-otp"; import service from "@/lib/http/service"; import md5 from "md5"; import { useTranslation } from "react-i18next"; // import { Minus } from "lucide-react"; type Props = { setError: (e: string) => void; emailValue: string; passwordValue: string; }; export const EmailCode: React.FC = ({ setError, emailValue, passwordValue }) => { const router = useRouter(); const { t } = useTranslation(); const [isLoading, setIsLoading] = React.useState(false); const [_timeLeft, _setTimeLeft] = React.useState(0); const verifyCode = async (otp: string) => { console.log("verifyCode", otp, passwordValue, ) setIsLoading(true); await service.post('/api/v1/customer/register', { user_name: emailValue, email: emailValue, password: md5(passwordValue), reg_code: otp, }).then(function (result: any) { setIsLoading(false); console.log("result:", result) if (result && result.header.code != 0) { toast.error(result.header.message) return } toast.success(result.header.message) router.push("/auth/sign-in"); // 自身方法 // localStorage.setItem("data", JSON.stringify(result.data)); // []方法 { {/* localStorage["name"]="bonly"; */ } } }).catch((err: any) => { setIsLoading(false); console.log(err); }); }; const resendCode = async () => { console.log("resendCode", emailValue) try { await service.post('/api/v1/common/auth-code', { user_name: emailValue, email: emailValue, }).then(function (result: any) { setIsLoading(false); console.log("result:", result) if (result && result.header.code != 0) { toast.error(result.header.message) return } toast.success(result.header.message) }).catch((err: any) => { setIsLoading(false); console.log(err); }); } catch (error) { setIsLoading(false); setError((error as Error).message); console.error(error); } }; const [otp, setOtp] = React.useState(""); return (

{t("auth.sign_up")}

{t("auth.verification_code")}

verifyCode(otp)}> verifyCode(otp)} maxLength={6} render={({ slots }) => (
{slots.slice(0, 3).map((slot, idx) => ( ))} {slots.slice(3).map((slot, idx) => ( ))}
)} />

); }; const Slot: React.FC = (props) => (
{props.char !== null &&
{props.char}
}
);