fix: 新手教程修改地址,注册表单修改form传值
This commit is contained in:
parent
36bbcbc4f9
commit
2862629516
@ -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 =
|
||||
|
||||
@ -18,6 +18,7 @@ interface Item {
|
||||
title: string;
|
||||
updated_at?: string;
|
||||
icon?: string;
|
||||
download?: string;
|
||||
}
|
||||
export function TutorialButton({ items }: { items: Item[] }) {
|
||||
const t = useTranslations('document');
|
||||
@ -120,7 +121,6 @@ export function TutorialButton({ items }: { items: Item[] }) {
|
||||
<motion.div
|
||||
layoutId={`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'
|
||||
>
|
||||
<div className='flex flex-row items-center gap-4'>
|
||||
@ -149,17 +149,34 @@ export function TutorialButton({ items }: { items: Item[] }) {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<motion.button
|
||||
layoutId={`button-${item.title}-${id}`}
|
||||
className={cn(
|
||||
buttonVariants({
|
||||
variant: 'primary',
|
||||
}),
|
||||
'sm:min-w-[100px]',
|
||||
)}
|
||||
>
|
||||
{t('read')}
|
||||
</motion.button>
|
||||
<div>
|
||||
{item.download ? (
|
||||
<a
|
||||
className={cn(
|
||||
buttonVariants({
|
||||
variant: 'default',
|
||||
}),
|
||||
'mr-2 bg-[#EAEAEA] px-3 text-[#225BA9] hover:text-white sm:min-w-[80px]',
|
||||
)}
|
||||
href={item.download}
|
||||
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>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@ -133,6 +133,7 @@ function MobileBindDialog({
|
||||
<Input placeholder='Enter code...' type='text' {...field} />
|
||||
<SendCode
|
||||
type='phone'
|
||||
form={form}
|
||||
params={{
|
||||
telephone_area_code: form.getValues().area_code,
|
||||
telephone: form.getValues().mobile,
|
||||
|
||||
@ -173,6 +173,7 @@ export default function RegisterForm({
|
||||
/>
|
||||
<SendCode
|
||||
type='email'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 1,
|
||||
|
||||
@ -99,6 +99,7 @@ export default function ResetForm({
|
||||
/>
|
||||
<SendCode
|
||||
type='email'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 2,
|
||||
|
||||
@ -121,6 +121,7 @@ export default function LoginForm({
|
||||
{mode === 'code' && (
|
||||
<SendCode
|
||||
type='phone'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 2,
|
||||
|
||||
@ -173,6 +173,7 @@ export default function RegisterForm({
|
||||
|
||||
<SendCode
|
||||
type='phone'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 1,
|
||||
|
||||
@ -121,6 +121,7 @@ export default function ResetForm({
|
||||
/>
|
||||
<SendCode
|
||||
type='phone'
|
||||
form={form}
|
||||
params={{
|
||||
...form.getValues(),
|
||||
type: 2,
|
||||
|
||||
@ -6,6 +6,7 @@ import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
||||
import { useCountDown } from 'ahooks';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { UseFormReturn } from 'react-hook-form';
|
||||
|
||||
interface SendCodeProps {
|
||||
type: 'email' | 'phone';
|
||||
@ -15,8 +16,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 { common } = useGlobalStore();
|
||||
const { verify_code_interval } = common.verify_code;
|
||||
@ -49,21 +51,25 @@ 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();
|
||||
if (latestValues.email && latestValues.type) {
|
||||
await sendEmailCode({
|
||||
email: params.email,
|
||||
type: params.type,
|
||||
email: latestValues.email,
|
||||
type: latestValues.type,
|
||||
});
|
||||
setCodeTimer();
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
});
|
||||
setCodeTimer();
|
||||
}
|
||||
@ -71,9 +77,9 @@ export default function SendCode({ type, params }: SendCodeProps) {
|
||||
|
||||
const handleSendCode = async () => {
|
||||
if (type === 'email') {
|
||||
getEmailCode();
|
||||
await getEmailCode();
|
||||
} else {
|
||||
getPhoneCode();
|
||||
await getPhoneCode();
|
||||
}
|
||||
};
|
||||
const disabled =
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { NEXT_PUBLIC_CDN_URL } from '@/config/constants';
|
||||
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() {
|
||||
// // 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();
|
||||
// return json[0].version;
|
||||
// }
|
||||
|
||||
async function getVersionPath() {
|
||||
// return getVersion()
|
||||
// .then((version) => `${BASE_URL}@${version}`)
|
||||
// .catch((error) => {
|
||||
// console.warn('Error fetching the version:', error);
|
||||
// return `${BASE_URL}@latest`;
|
||||
// });
|
||||
return `${BASE_URL}@latest`;
|
||||
}
|
||||
//
|
||||
// async function getVersionPath() {
|
||||
// // return getVersion()
|
||||
// // .then((version) => `${BASE_URL}@${version}`)
|
||||
// // .catch((error) => {
|
||||
// // console.warn('Error fetching the version:', error);
|
||||
// // return `${BASE_URL}@latest`;
|
||||
// // });
|
||||
// return `${BASE_URL}@latest`;
|
||||
// }
|
||||
|
||||
export async function getTutorial(path: string): Promise<{
|
||||
config?: Record<string, unknown>;
|
||||
content: string;
|
||||
}> {
|
||||
const versionPath = await getVersionPath();
|
||||
try {
|
||||
const url = `${versionPath}/${path}`;
|
||||
const url = `${BASE_URL}/${path}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user