add reset password

This commit is contained in:
smanylov
2026-02-02 15:00:56 +07:00
parent 19e807a7f6
commit 7789f19055
8 changed files with 457 additions and 95 deletions
+9 -5
View File
@@ -1,5 +1,5 @@
import * as z from 'zod'
import { createValidationSchema } from '@/app/lib/validation-config-parser';
import { createValidationSchema, createValidationSchemaForPssword } from '@/app/lib/validation-config-parser';
import validationConfig from '@/app/lib/validation-config.json';
export type FormState =
@@ -38,7 +38,7 @@ 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 {
const response = await fetch('/api/validation-config');
if (!response.ok) throw new Error('Failed to load config');
@@ -50,15 +50,19 @@ async function loadConfigFromBackend(accountType: 'b2b' | 'b2c'): Promise<any> {
}
}
export async function getSignupFormSchema(accountType: 'b2b' | 'b2c') {
export async function getSignupFormSchema(schemaType?: 'b2b' | 'b2c' | 'resetPassword') {
if (cachedSignupSchema) {
return cachedSignupSchema;
}
if (!schemaPromise) {
schemaPromise = (async () => {
const config = await loadConfigFromBackend(accountType);
cachedSignupSchema = createValidationSchema(config, accountType);
const config = await loadConfigFromBackend();
if (schemaType === 'resetPassword') {
cachedSignupSchema = createValidationSchemaForPssword(config);
} else {
cachedSignupSchema = createValidationSchema(config, schemaType);
}
return cachedSignupSchema;
})();