complite b2b b2c registration

This commit is contained in:
smanylov
2026-01-29 21:34:02 +07:00
parent fc81d471ff
commit 8b04485533
4 changed files with 18 additions and 14 deletions
+7 -4
View File
@@ -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);