fix registration validation config
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "no-copy-frontend",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 2999",
|
||||
|
||||
@@ -168,7 +168,7 @@ export async function registration(
|
||||
...(accountType === 'b2b' && { companyName })
|
||||
};
|
||||
|
||||
const validatedFields = SignupFormSchema.safeParse(dataToValidate);
|
||||
const validatedFields = await SignupFormSchema.safeParse(dataToValidate);
|
||||
|
||||
console.log(`try to register ${accountType}`);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as z from 'zod'
|
||||
import { createValidationSchema, createValidationSchemaForPssword } from '@/app/lib/validation-config-parser';
|
||||
import {createValidationSchema, createValidationSchemaForPassword} from '@/app/lib/validation-config-parser';
|
||||
import validationConfig from '@/app/lib/validation-config.json';
|
||||
|
||||
export type FormState =
|
||||
@@ -35,9 +35,6 @@ interface ValidationConfig {
|
||||
|
||||
const defaultConfig = validationConfig as ValidationConfig;
|
||||
|
||||
let cachedSignupSchema: any = null;
|
||||
let schemaPromise: Promise<any> | null = null;
|
||||
|
||||
async function loadConfigFromBackend(accountType?: 'b2b' | 'b2c'): Promise<any> {
|
||||
try {
|
||||
const response = await fetch('/api/validation-config');
|
||||
@@ -51,15 +48,14 @@ async function loadConfigFromBackend(accountType?: 'b2b' | 'b2c'): Promise<any>
|
||||
}
|
||||
|
||||
export async function getSignupFormSchema(schemaType?: 'b2b' | 'b2c' | 'resetPassword') {
|
||||
if (cachedSignupSchema) {
|
||||
return cachedSignupSchema;
|
||||
}
|
||||
let schemaPromise: Promise<any> | null = null;
|
||||
let cachedSignupSchema: any = null;
|
||||
|
||||
if (!schemaPromise) {
|
||||
schemaPromise = (async () => {
|
||||
const config = await loadConfigFromBackend();
|
||||
if (schemaType === 'resetPassword') {
|
||||
cachedSignupSchema = createValidationSchemaForPssword(config);
|
||||
cachedSignupSchema = createValidationSchemaForPassword(config);
|
||||
} else {
|
||||
cachedSignupSchema = createValidationSchema(config, schemaType);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ export function createValidationSchema(config: ValidationConfig, accountType?: '
|
||||
}
|
||||
|
||||
// phone
|
||||
if (config.phone) {
|
||||
if (config.phone) {
|
||||
let phoneSchema = z.string();
|
||||
|
||||
// Минимальная длина
|
||||
@@ -175,7 +175,7 @@ export function createValidationSchema(config: ValidationConfig, accountType?: '
|
||||
});
|
||||
}
|
||||
|
||||
export function createValidationSchemaForPssword(config: ValidationConfig) {
|
||||
export function createValidationSchemaForPassword(config: ValidationConfig) {
|
||||
const schema: Record<string, any> = {};
|
||||
|
||||
// password
|
||||
|
||||
Reference in New Issue
Block a user