fix: 新手教程修改地址,注册表单修改form传值
This commit is contained in:
@@ -150,6 +150,7 @@ export default function RegisterForm({
|
||||
/>
|
||||
<SendCode
|
||||
type='email'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 1,
|
||||
|
||||
@@ -84,6 +84,7 @@ export default function ResetForm({
|
||||
/>
|
||||
<SendCode
|
||||
type='email'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 2,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Button } from '@workspace/ui/components/button';
|
||||
import { useCountDown } from 'ahooks';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useState } from 'react';
|
||||
import { UseFormReturn } from 'react-hook-form'; // For type-safety
|
||||
|
||||
interface SendCodeProps {
|
||||
type: 'email' | 'phone';
|
||||
@@ -14,8 +15,9 @@ interface SendCodeProps {
|
||||
telephone_area_code?: string;
|
||||
telephone?: string;
|
||||
};
|
||||
form: UseFormReturn<any>; // Add the new form prop
|
||||
}
|
||||
export default function SendCode({ type, params }: SendCodeProps) {
|
||||
export default function SendCode({ type, params, form }: SendCodeProps) {
|
||||
const t = useTranslations('auth');
|
||||
const [targetDate, setTargetDate] = useState<number>();
|
||||
|
||||
@@ -27,21 +29,26 @@ export default function SendCode({ type, params }: SendCodeProps) {
|
||||
});
|
||||
|
||||
const getEmailCode = async () => {
|
||||
if (params.email && params.type) {
|
||||
// Use form.getValues() to get the latest form data
|
||||
const latestValues = form.getValues();
|
||||
console.log(11111, latestValues);
|
||||
if (latestValues.email && latestValues.type) {
|
||||
await sendEmailCode({
|
||||
email: params.email,
|
||||
type: params.type,
|
||||
email: latestValues.email,
|
||||
type: latestValues.type,
|
||||
});
|
||||
setTargetDate(Date.now() + 60000);
|
||||
}
|
||||
};
|
||||
|
||||
const getPhoneCode = async () => {
|
||||
if (params.telephone && params.telephone_area_code && params.type) {
|
||||
// Use form.getValues() to get the latest form data
|
||||
const latestValues = form.getValues();
|
||||
if (latestValues.telephone && latestValues.telephone_area_code && latestValues.type) {
|
||||
await sendSmsCode({
|
||||
telephone: params.telephone,
|
||||
telephone_area_code: params.telephone_area_code,
|
||||
type: params.type,
|
||||
telephone: latestValues.telephone,
|
||||
telephone_area_code: latestValues.telephone_area_code,
|
||||
type: latestValues.type,
|
||||
});
|
||||
setTargetDate(Date.now() + 60000);
|
||||
}
|
||||
@@ -49,9 +56,9 @@ export default function SendCode({ type, params }: SendCodeProps) {
|
||||
|
||||
const handleSendCode = async () => {
|
||||
if (type === 'email') {
|
||||
getEmailCode();
|
||||
await getEmailCode();
|
||||
} else {
|
||||
getPhoneCode();
|
||||
await getPhoneCode();
|
||||
}
|
||||
};
|
||||
const disabled =
|
||||
|
||||
Reference in New Issue
Block a user