edit company-user registration
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
'use server'
|
||||
|
||||
import { API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions';
|
||||
import { createSession } from '@/app/actions/session';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getSessionData } from '@/app/actions/session';
|
||||
|
||||
export type CompanyUserRegistrationFormState = {
|
||||
previousState: {
|
||||
@@ -12,6 +11,7 @@ export type CompanyUserRegistrationFormState = {
|
||||
confirm_password: string;
|
||||
phone: string;
|
||||
},
|
||||
createdUser: string | null
|
||||
error: Record<string, string> | null
|
||||
} | undefined;
|
||||
|
||||
@@ -19,6 +19,11 @@ export async function companyUserRegistration(
|
||||
state: CompanyUserRegistrationFormState | undefined,
|
||||
formData: FormData,
|
||||
): Promise<CompanyUserRegistrationFormState> {
|
||||
const token = await getSessionData('token');
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fullName = formData.get('fullName') as string || '';
|
||||
const email = formData.get('email') as string || '';
|
||||
const password = formData.get('password') as string || '';
|
||||
@@ -53,6 +58,7 @@ export async function companyUserRegistration(
|
||||
}
|
||||
});
|
||||
|
||||
console.log('registration error');
|
||||
console.log(errors);
|
||||
|
||||
return {
|
||||
@@ -63,21 +69,11 @@ export async function companyUserRegistration(
|
||||
confirm_password,
|
||||
phone
|
||||
},
|
||||
createdUser: null,
|
||||
error: errors
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
previousState: {
|
||||
fullName,
|
||||
email,
|
||||
password,
|
||||
confirm_password,
|
||||
phone
|
||||
},
|
||||
error: null
|
||||
};
|
||||
|
||||
try {
|
||||
const { fullName, email, password, phone } = validatedFields.data;
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||
@@ -89,7 +85,10 @@ export async function companyUserRegistration(
|
||||
fullName: fullName,
|
||||
email,
|
||||
phone: phone,
|
||||
password
|
||||
password,
|
||||
accountType: 'b2b',
|
||||
authToken: token,
|
||||
companyName: ''
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
@@ -104,6 +103,14 @@ export async function companyUserRegistration(
|
||||
message_body: { token: string },
|
||||
message_code: number
|
||||
};
|
||||
console.log({
|
||||
fullName: fullName,
|
||||
email,
|
||||
phone: phone,
|
||||
password,
|
||||
accountType: 'b2b',
|
||||
authToken: token
|
||||
});
|
||||
|
||||
if (parsed.message_code === 0) {
|
||||
console.log(`registration - ${email}`);
|
||||
@@ -113,7 +120,18 @@ export async function companyUserRegistration(
|
||||
phone: phone,
|
||||
password
|
||||
});
|
||||
await createSession(parsed.message_body.token, email as string);
|
||||
|
||||
return {
|
||||
previousState: {
|
||||
fullName: '',
|
||||
email: '',
|
||||
password: '',
|
||||
confirm_password: '',
|
||||
phone: ''
|
||||
},
|
||||
createdUser: fullName,
|
||||
error: null
|
||||
}
|
||||
} else {
|
||||
throw parsed;
|
||||
}
|
||||
@@ -162,6 +180,7 @@ export async function companyUserRegistration(
|
||||
confirm_password,
|
||||
phone
|
||||
},
|
||||
createdUser: null,
|
||||
error: errors
|
||||
};
|
||||
}
|
||||
@@ -174,6 +193,7 @@ export async function companyUserRegistration(
|
||||
confirm_password,
|
||||
phone
|
||||
},
|
||||
createdUser: null,
|
||||
error: errors
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user