fix: 新手教程修改地址,注册表单修改form传值

This commit is contained in:
speakeloudest 2025-09-01 05:16:23 -07:00
parent 36bbcbc4f9
commit 2862629516
12 changed files with 82 additions and 46 deletions

View File

@ -150,6 +150,7 @@ export default function RegisterForm({
/> />
<SendCode <SendCode
type='email' type='email'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 1, type: 1,

View File

@ -84,6 +84,7 @@ export default function ResetForm({
/> />
<SendCode <SendCode
type='email' type='email'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 2, type: 2,

View File

@ -5,6 +5,7 @@ import { Button } from '@workspace/ui/components/button';
import { useCountDown } from 'ahooks'; import { useCountDown } from 'ahooks';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
import { useState } from 'react'; import { useState } from 'react';
import { UseFormReturn } from 'react-hook-form'; // For type-safety
interface SendCodeProps { interface SendCodeProps {
type: 'email' | 'phone'; type: 'email' | 'phone';
@ -14,8 +15,9 @@ interface SendCodeProps {
telephone_area_code?: string; telephone_area_code?: string;
telephone?: 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 t = useTranslations('auth');
const [targetDate, setTargetDate] = useState<number>(); const [targetDate, setTargetDate] = useState<number>();
@ -27,21 +29,26 @@ export default function SendCode({ type, params }: SendCodeProps) {
}); });
const getEmailCode = async () => { 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({ await sendEmailCode({
email: params.email, email: latestValues.email,
type: params.type, type: latestValues.type,
}); });
setTargetDate(Date.now() + 60000); setTargetDate(Date.now() + 60000);
} }
}; };
const getPhoneCode = async () => { 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({ await sendSmsCode({
telephone: params.telephone, telephone: latestValues.telephone,
telephone_area_code: params.telephone_area_code, telephone_area_code: latestValues.telephone_area_code,
type: params.type, type: latestValues.type,
}); });
setTargetDate(Date.now() + 60000); setTargetDate(Date.now() + 60000);
} }
@ -49,9 +56,9 @@ export default function SendCode({ type, params }: SendCodeProps) {
const handleSendCode = async () => { const handleSendCode = async () => {
if (type === 'email') { if (type === 'email') {
getEmailCode(); await getEmailCode();
} else { } else {
getPhoneCode(); await getPhoneCode();
} }
}; };
const disabled = const disabled =

View File

@ -18,6 +18,7 @@ interface Item {
title: string; title: string;
updated_at?: string; updated_at?: string;
icon?: string; icon?: string;
download?: string;
} }
export function TutorialButton({ items }: { items: Item[] }) { export function TutorialButton({ items }: { items: Item[] }) {
const t = useTranslations('document'); const t = useTranslations('document');
@ -120,7 +121,6 @@ export function TutorialButton({ items }: { items: Item[] }) {
<motion.div <motion.div
layoutId={`card-${item.title}-${id}`} layoutId={`card-${item.title}-${id}`}
key={`card-${item.title}-${id}`} key={`card-${item.title}-${id}`}
onClick={() => setActive(item)}
className='bg-background hover:bg-accent flex cursor-pointer items-center justify-between rounded-[40px] border p-1 sm:p-4' className='bg-background hover:bg-accent flex cursor-pointer items-center justify-between rounded-[40px] border p-1 sm:p-4'
> >
<div className='flex flex-row items-center gap-4'> <div className='flex flex-row items-center gap-4'>
@ -149,17 +149,34 @@ export function TutorialButton({ items }: { items: Item[] }) {
)} )}
</div> </div>
</div> </div>
<motion.button <div>
layoutId={`button-${item.title}-${id}`} {item.download ? (
className={cn( <a
buttonVariants({ className={cn(
variant: 'primary', buttonVariants({
}), variant: 'default',
'sm:min-w-[100px]', }),
)} 'mr-2 bg-[#EAEAEA] px-3 text-[#225BA9] hover:text-white sm:min-w-[80px]',
> )}
{t('read')} href={item.download}
</motion.button> target='_blank'
>
</a>
) : null}
<motion.button
layoutId={`button-${item.title}-${id}`}
onClick={() => setActive(item)}
className={cn(
buttonVariants({
variant: 'primary',
}),
'px-3 sm:min-w-[80px]',
)}
>
{t('read')}
</motion.button>
</div>
</motion.div> </motion.div>
))} ))}
</ul> </ul>

View File

@ -133,6 +133,7 @@ function MobileBindDialog({
<Input placeholder='Enter code...' type='text' {...field} /> <Input placeholder='Enter code...' type='text' {...field} />
<SendCode <SendCode
type='phone' type='phone'
form={form}
params={{ params={{
telephone_area_code: form.getValues().area_code, telephone_area_code: form.getValues().area_code,
telephone: form.getValues().mobile, telephone: form.getValues().mobile,

View File

@ -173,6 +173,7 @@ export default function RegisterForm({
/> />
<SendCode <SendCode
type='email' type='email'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 1, type: 1,

View File

@ -99,6 +99,7 @@ export default function ResetForm({
/> />
<SendCode <SendCode
type='email' type='email'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 2, type: 2,

View File

@ -121,6 +121,7 @@ export default function LoginForm({
{mode === 'code' && ( {mode === 'code' && (
<SendCode <SendCode
type='phone' type='phone'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 2, type: 2,

View File

@ -173,6 +173,7 @@ export default function RegisterForm({
<SendCode <SendCode
type='phone' type='phone'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 1, type: 1,

View File

@ -121,6 +121,7 @@ export default function ResetForm({
/> />
<SendCode <SendCode
type='phone' type='phone'
form={form}
params={{ params={{
...form.getValues(), ...form.getValues(),
type: 2, type: 2,

View File

@ -6,6 +6,7 @@ import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
import { useCountDown } from 'ahooks'; import { useCountDown } from 'ahooks';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { UseFormReturn } from 'react-hook-form';
interface SendCodeProps { interface SendCodeProps {
type: 'email' | 'phone'; type: 'email' | 'phone';
@ -15,8 +16,9 @@ interface SendCodeProps {
telephone_area_code?: string; telephone_area_code?: string;
telephone?: 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 t = useTranslations('auth');
const { common } = useGlobalStore(); const { common } = useGlobalStore();
const { verify_code_interval } = common.verify_code; const { verify_code_interval } = common.verify_code;
@ -49,21 +51,25 @@ export default function SendCode({ type, params }: SendCodeProps) {
}; };
const getEmailCode = async () => { const getEmailCode = async () => {
if (params.email && params.type) { // Use form.getValues() to get the latest form data
const latestValues = form.getValues();
if (latestValues.email && latestValues.type) {
await sendEmailCode({ await sendEmailCode({
email: params.email, email: latestValues.email,
type: params.type, type: latestValues.type,
}); });
setCodeTimer(); setCodeTimer();
} }
}; };
const getPhoneCode = async () => { 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({ await sendSmsCode({
telephone: params.telephone, telephone: latestValues.telephone,
telephone_area_code: params.telephone_area_code, telephone_area_code: latestValues.telephone_area_code,
type: params.type, type: latestValues.type,
}); });
setCodeTimer(); setCodeTimer();
} }
@ -71,9 +77,9 @@ export default function SendCode({ type, params }: SendCodeProps) {
const handleSendCode = async () => { const handleSendCode = async () => {
if (type === 'email') { if (type === 'email') {
getEmailCode(); await getEmailCode();
} else { } else {
getPhoneCode(); await getPhoneCode();
} }
}; };
const disabled = const disabled =

View File

@ -1,7 +1,6 @@
import { NEXT_PUBLIC_CDN_URL } from '@/config/constants';
import matter from 'gray-matter'; import matter from 'gray-matter';
const BASE_URL = `${NEXT_PUBLIC_CDN_URL}/gh/perfect-panel/ppanel-tutorial`; const BASE_URL = `https://airoport.co/md`;
// async function getVersion() { // async function getVersion() {
// // API rate limit: 60 requests per hour // // API rate limit: 60 requests per hour
@ -11,24 +10,23 @@ const BASE_URL = `${NEXT_PUBLIC_CDN_URL}/gh/perfect-panel/ppanel-tutorial`;
// const json = await response.json(); // const json = await response.json();
// return json[0].version; // return json[0].version;
// } // }
//
async function getVersionPath() { // async function getVersionPath() {
// return getVersion() // // return getVersion()
// .then((version) => `${BASE_URL}@${version}`) // // .then((version) => `${BASE_URL}@${version}`)
// .catch((error) => { // // .catch((error) => {
// console.warn('Error fetching the version:', error); // // console.warn('Error fetching the version:', error);
// return `${BASE_URL}@latest`; // // return `${BASE_URL}@latest`;
// }); // // });
return `${BASE_URL}@latest`; // return `${BASE_URL}@latest`;
} // }
export async function getTutorial(path: string): Promise<{ export async function getTutorial(path: string): Promise<{
config?: Record<string, unknown>; config?: Record<string, unknown>;
content: string; content: string;
}> { }> {
const versionPath = await getVersionPath();
try { try {
const url = `${versionPath}/${path}`; const url = `${BASE_URL}/${path}`;
const response = await fetch(url); const response = await fetch(url);
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`); throw new Error(`HTTP error! status: ${response.status}`);