edit registration

This commit is contained in:
smanylov
2026-02-03 15:25:11 +07:00
parent 2adf66baa2
commit 1e199de7b2
6 changed files with 52 additions and 23 deletions
+16
View File
@@ -170,6 +170,8 @@ export async function registration(
const validatedFields = SignupFormSchema.safeParse(dataToValidate); const validatedFields = SignupFormSchema.safeParse(dataToValidate);
console.log(`account-type ${accountType}`)
if (!validatedFields.success) { if (!validatedFields.success) {
const errors: Record<string, string> = {} const errors: Record<string, string> = {}
JSON.parse(validatedFields.error.message).forEach((obj: { 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 { try {
const { fullName, email, password, phone } = validatedFields.data; const { fullName, email, password, phone } = validatedFields.data;
const response = await fetch(`${API_BASE_URL}/api/v1/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') { if (parsed.message_desc === 'Operation successful') {
await createSession(parsed.message_body.token, email as string); await createSession(parsed.message_body.token, email as string);
console.log('succes registration');
} else { } else {
throw parsed; throw parsed;
} }
+3 -12
View File
@@ -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,22 +48,16 @@ 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;
}
if (!schemaPromise) {
schemaPromise = (async () => { schemaPromise = (async () => {
const config = await loadConfigFromBackend(); const config = await loadConfigFromBackend();
if (schemaType === 'resetPassword') { if (schemaType === 'resetPassword') {
cachedSignupSchema = createValidationSchemaForPssword(config); return createValidationSchemaForPssword(config);
} else { } else {
cachedSignupSchema = createValidationSchema(config, schemaType); return createValidationSchema(config, schemaType);
} }
return cachedSignupSchema;
})(); })();
}
return await schemaPromise; return await schemaPromise;
} }
+2 -2
View File
@@ -38,8 +38,8 @@ export function createValidationSchema(config: ValidationConfig, accountType?: '
.trim(); .trim();
} }
// fullName // companyName
if (config.companyName && accountType !== 'b2c') { if (config.companyName && accountType === 'b2b') {
schema.companyName = z schema.companyName = z
.string() .string()
.trim() .trim()
+1 -1
View File
@@ -84,7 +84,7 @@ export default function RegisterForm() {
if (fieldName === 'phone') { if (fieldName === 'phone') {
return schema.safeParse(value.replace(/[-\(\)\s]/g, '')); return schema.safeParse(value.replace(/[-\(\)\s]/g, ''));
} }
if (fieldName === 'companyName' && accountType === 'b2c') { if (fieldName === 'companyName') {
return { success: true, data: value }; return { success: true, data: value };
} }
return schema.safeParse(value); return schema.safeParse(value);
+1 -2
View File
@@ -22,8 +22,7 @@ export default function UserMenuButton() {
queryFn: () => { queryFn: () => {
return getUserData(); return getUserData();
} }
}) });
useClickOutside( useClickOutside(
menuRef, menuRef,
@@ -1,4 +1,27 @@
'use client'
import { useEffect } from 'react';
import { getUserData } from '@/app/actions/action';
import { useQuery } from '@tanstack/react-query';
export default function PaymentTabTariffs() { export default function PaymentTabTariffs() {
const {
data: userData,
isLoading,
isError,
error
} = useQuery({
queryKey: ['userData'],
queryFn: () => {
return getUserData();
}
});
useEffect(() => {
console.log('show => userData');
console.log(userData);
}, [])
return ( return (
<div className="tab-content"> <div className="tab-content">
<div className="billing-toggle"> <div className="billing-toggle">