89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
"use client";
|
|
|
|
import { MedReportTitle } from "@/components/MedReportTitle";
|
|
import React from "react";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import Image from "next/image";
|
|
import medReportBigLogo from "@/assets/medReportBigLogo.png";
|
|
import { SubmitButton } from "@/components/submit-button";
|
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
import { useForm } from "react-hook-form";
|
|
import { companySchema } from "@/lib/validations/companySchema";
|
|
import { CompanySubmitData } from "@/lib/types/company";
|
|
import { submitCompanyRegistration } from "@/lib/services/register-company.service";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
export default function RegisterCompany() {
|
|
const router = useRouter();
|
|
const {
|
|
register,
|
|
handleSubmit,
|
|
formState: { errors, isValid, isSubmitting },
|
|
} = useForm({
|
|
resolver: yupResolver(companySchema),
|
|
mode: "onChange",
|
|
});
|
|
|
|
async function onSubmit(data: CompanySubmitData) {
|
|
const formData = new FormData();
|
|
Object.entries(data).forEach(([key, value]) => {
|
|
if (value !== undefined) formData.append(key, value);
|
|
});
|
|
|
|
try {
|
|
await submitCompanyRegistration(formData);
|
|
router.push("/register-company/success");
|
|
} catch (err: any) {
|
|
alert("Server validation error: " + err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-row border rounded-3xl border-border">
|
|
<div className="flex flex-col text-center py-14 px-12 w-1/2">
|
|
<MedReportTitle />
|
|
<h1 className="pt-8">Ettevõtte andmed</h1>
|
|
<p className="pt-2">
|
|
Pakkumise saamiseks palun sisesta ettevõtte andmed millega MedReport
|
|
kasutada kavatsed.
|
|
</p>
|
|
<form
|
|
onSubmit={handleSubmit(onSubmit)}
|
|
noValidate
|
|
className="flex gap-4 flex-col text-left pt-8 px-6"
|
|
>
|
|
<div>
|
|
<Label>Ettevõtte nimi</Label>
|
|
<Input {...register("companyName")} />
|
|
</div>
|
|
<div>
|
|
<Label>Kontaktisik</Label>
|
|
<Input {...register("contactPerson")} />
|
|
</div>
|
|
<div>
|
|
<Label>E-mail</Label>
|
|
<Input type="email" {...register("email")}></Input>
|
|
</div>
|
|
<div>
|
|
<Label>Telefon</Label>
|
|
<Input type="tel" {...register("phone")} />
|
|
</div>
|
|
<SubmitButton
|
|
disabled={!isValid || isSubmitting}
|
|
pendingText="Saatmine..."
|
|
type="submit"
|
|
formAction={submitCompanyRegistration}
|
|
className="mt-4 hover:bg-primary/90"
|
|
>
|
|
Küsi pakkumist
|
|
</SubmitButton>
|
|
</form>
|
|
</div>
|
|
<div className="w-1/2">
|
|
<Image src={medReportBigLogo} alt="MedReport" priority />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|