add errors handlers and translate

This commit is contained in:
smanylov
2026-02-03 11:44:02 +07:00
parent ab0b68a7b8
commit 8d10aa77c8
5 changed files with 33 additions and 25 deletions
+19 -9
View File
@@ -249,9 +249,9 @@ export async function registration(
error: null
}; */
} catch (error: unknown) {
const errors: Record<string, string> = {};
if (error) {
const typedError = error as any;
const errors: Record<string, string> = {};
switch (typedError.message_code) {
case 1:
@@ -295,7 +295,18 @@ export async function registration(
};
}
throw error;
return {
previousState: {
fullName,
email,
password,
confirm_password,
phone,
companyName,
agree
},
error: errors
};
}
redirect('/pages/dashboard');
@@ -345,7 +356,7 @@ export async function confirmEmail(
export async function resetPassword(
state: any | undefined,
formData: any,
formData: FormData,
) {
const email = formData.get('email');
console.log('resetPassword');
@@ -368,19 +379,20 @@ export async function resetPassword(
});
if (response.ok) {
const parsed = await response.json();
console.log(parsed);
if (parsed.message_code === 0) {
} else {
throw parsed.message_body;
throw 'error';
}
}
} catch (error) {
throw error;
return {
error: error
};
}
console.log('redirect')
redirect(`/reset-password?email=${email}`);
}
@@ -413,8 +425,6 @@ export async function confirmPassword(
const validatedFields = SignupFormSchema.safeParse(dataToValidate);
console.log(validatedFields);
if (!validatedFields.success) {
const errors: Record<string, string> = {}
JSON.parse(validatedFields.error.message).forEach((obj: {
+5 -11
View File
@@ -2,9 +2,8 @@
import styles from '@/app/styles/module/login.module.scss'
import { useActionState } from 'react';
import { useTranslations } from 'next-intl';
import {resetPassword} from '@/app/actions/auth';
import { resetPassword } from '@/app/actions/auth';
export default function ForgotPasswordForm() {
const [state, formAction, isPending] = useActionState(
@@ -26,19 +25,14 @@ export default function ForgotPasswordForm() {
className={`${styles['form-input']}`}
placeholder={t('enter-email')}
/>
{/* {state === 'error' && (
{state?.error === 'error' && (
<p className={`${styles['form-error']}`}>
Восстановление пароля не работает
{t('register-error-email-invalid')}
</p>
)} */}
)}
</div>
{/* {state?.error.server && (
<p className={`${styles['form-error']}`}>
{t(state?.error.server)}
</p>
)} */}
<button type="submit" className={`${styles['btn']}`}>
Восстановить пароль
{t('recover-password')}
</button>
</form>
)
+3 -3
View File
@@ -112,14 +112,14 @@ export default function ResetPasswordForm() {
</div>
<div className={`${styles['form-group']}`}>
<label className={`${styles['form-label']} ${styles['required']}`}>
Код восстановления
{t('recovery-code')}
</label>
<input
type="readOnly"
id="verify-token"
name="verify-token"
className={`${styles['form-input']}`}
placeholder={'Код восстановления'}
placeholder={t('recovery-code')}
defaultValue={formState?.previousState?.verifyToken ? formState?.previousState?.verifyToken : ''}
/>
</div>
@@ -201,7 +201,7 @@ export default function ResetPasswordForm() {
</p>
)} */}
<button type="submit" className={`${styles['btn']}`}>
Изменить пароль
{t('change-password')}
</button>
</form>
)