add input mask, edit valitation and validation message

This commit is contained in:
smanylov
2025-12-08 13:57:26 +07:00
parent fb7c17caee
commit bf37ea95a4
4 changed files with 121 additions and 24 deletions
+14 -10
View File
@@ -83,7 +83,7 @@ export async function authorization(
let parsed = await response.json();
await createSession(parsed.token, parsed.email);
} else {
throw new Error(`Something went wrong. Status from server ${response.status}`);
throw (`Запрос завершился с ошибкой: ${response.status}`);
}
} catch (error) {
@@ -113,6 +113,7 @@ type FormState = {
confirm_password: string;
phone: string;
company: string;
agree: string;
}
error: Record<string, string>
};
@@ -127,12 +128,15 @@ export async function registration(
const confirm_password = formData.get('confirm_password') as string || '';
const phone = formData.get('phone') as string || '';
const company = formData.get('company') as string || '';
const agree = formData.get('agree') as string || '';
const validatedFields = SignupFormSchema.safeParse({
full_name,
email,
phone: phone.replace(/[-\(\)\s]/g, ''),
password,
confirm_password,
agree,
});
if (!validatedFields.success) {
@@ -155,17 +159,18 @@ export async function registration(
password,
confirm_password,
phone,
company
company,
agree
},
error: errors
};
}
try {
const { full_name, email, password } = validatedFields.data;
const { full_name, email, password, phone } = validatedFields.data;
const response = await fetch(`${API_BASE_URL}/v1/api/auth/register`, {
method: 'POST',
body: JSON.stringify({ fullName: full_name, email, password, phone, company }),
body: JSON.stringify({ fullName: full_name, email, password, companyName: company, phone: phone}),
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
@@ -176,14 +181,12 @@ export async function registration(
let parsed = await response.json();
await createSession(parsed.token, email);
} else {
throw new Error(`
-error-1. status: ${response.status}
`);
throw (`${response.status}`);
}
} catch (error) {
if (error) {
const errors: Record<string, string> = {}
errors['server'] = `-error-2 -> ${error}`
const errors: Record<string, string> = {};
errors['server'] = `Запрос завершился с ошибкой: ${error}`
return {
previousState: {
@@ -192,7 +195,8 @@ export async function registration(
password,
confirm_password,
phone,
company
company,
agree
},
error: errors
};