edit registration
This commit is contained in:
@@ -170,6 +170,8 @@ export async function registration(
|
||||
|
||||
const validatedFields = SignupFormSchema.safeParse(dataToValidate);
|
||||
|
||||
console.log(`account-type ${accountType}`)
|
||||
|
||||
if (!validatedFields.success) {
|
||||
const errors: Record<string, string> = {}
|
||||
JSON.parse(validatedFields.error.message).forEach((obj: {
|
||||
@@ -197,6 +199,19 @@ export async function registration(
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
return {
|
||||
previousState: {
|
||||
fullName,
|
||||
email,
|
||||
password,
|
||||
confirm_password,
|
||||
phone,
|
||||
agree,
|
||||
...(accountType === 'b2b' && { companyName })
|
||||
}
|
||||
}; */
|
||||
|
||||
try {
|
||||
const { fullName, email, password, phone } = validatedFields.data;
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||
@@ -228,6 +243,7 @@ export async function registration(
|
||||
|
||||
if (parsed.message_desc === 'Operation successful') {
|
||||
await createSession(parsed.message_body.token, email as string);
|
||||
console.log('succes registration');
|
||||
} else {
|
||||
throw parsed;
|
||||
}
|
||||
|
||||
@@ -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,22 +48,16 @@ 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;
|
||||
|
||||
if (!schemaPromise) {
|
||||
schemaPromise = (async () => {
|
||||
const config = await loadConfigFromBackend();
|
||||
if (schemaType === 'resetPassword') {
|
||||
cachedSignupSchema = createValidationSchemaForPssword(config);
|
||||
} else {
|
||||
cachedSignupSchema = createValidationSchema(config, schemaType);
|
||||
}
|
||||
|
||||
return cachedSignupSchema;
|
||||
})();
|
||||
}
|
||||
schemaPromise = (async () => {
|
||||
const config = await loadConfigFromBackend();
|
||||
if (schemaType === 'resetPassword') {
|
||||
return createValidationSchemaForPssword(config);
|
||||
} else {
|
||||
return createValidationSchema(config, schemaType);
|
||||
}
|
||||
})();
|
||||
|
||||
return await schemaPromise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user