B2B-29: Create register-company form
This commit is contained in:
31
lib/services/register-company.service.ts
Normal file
31
lib/services/register-company.service.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
"use server";
|
||||
|
||||
import * as yup from "yup";
|
||||
import { companySchema } from "@/lib/validations/companySchema";
|
||||
|
||||
export async function submitCompanyRegistration(formData: FormData) {
|
||||
const data = {
|
||||
companyName: formData.get("companyName")?.toString() || "",
|
||||
contactPerson: formData.get("contactPerson")?.toString() || "",
|
||||
email: formData.get("email")?.toString() || "",
|
||||
phone: formData.get("phone")?.toString() || "",
|
||||
};
|
||||
|
||||
try {
|
||||
await companySchema.validate(data, { abortEarly: false });
|
||||
|
||||
console.log("Valid data:", data);
|
||||
} catch (validationError) {
|
||||
if (validationError instanceof yup.ValidationError) {
|
||||
const errors = validationError.inner.map((err) => ({
|
||||
path: err.path,
|
||||
message: err.message,
|
||||
}));
|
||||
throw new Error(
|
||||
"Validation failed: " +
|
||||
errors.map((e) => `${e.path}: ${e.message}`).join(", ")
|
||||
);
|
||||
}
|
||||
throw validationError;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user