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