complite b2b b2c registration
This commit is contained in:
@@ -38,26 +38,28 @@ const defaultConfig = validationConfig as ValidationConfig;
|
||||
let cachedSignupSchema: any = null;
|
||||
let schemaPromise: Promise<any> | null = null;
|
||||
|
||||
async function loadConfigFromBackend(): Promise<any> {
|
||||
async function loadConfigFromBackend(accountType: 'b2b' | 'b2c'): Promise<any> {
|
||||
try {
|
||||
const response = await fetch('/api/validation-config');
|
||||
if (!response.ok) throw new Error('Failed to load config');
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
//сейчас выполняем это пока бека нету
|
||||
console.error('Using default validation config:', error);
|
||||
return defaultConfig;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSignupFormSchema() {
|
||||
export async function getSignupFormSchema(accountType: 'b2b' | 'b2c') {
|
||||
if (cachedSignupSchema) {
|
||||
return cachedSignupSchema;
|
||||
}
|
||||
|
||||
if (!schemaPromise) {
|
||||
schemaPromise = (async () => {
|
||||
const config = await loadConfigFromBackend();
|
||||
cachedSignupSchema = createValidationSchema(config);
|
||||
const config = await loadConfigFromBackend(accountType);
|
||||
cachedSignupSchema = createValidationSchema(config, accountType);
|
||||
|
||||
return cachedSignupSchema;
|
||||
})();
|
||||
}
|
||||
@@ -65,6 +67,7 @@ export async function getSignupFormSchema() {
|
||||
return await schemaPromise;
|
||||
}
|
||||
|
||||
// для валидации в реально времени на клиентской странице
|
||||
export const SignupFormSchema = createValidationSchema(defaultConfig);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user