diff --git a/src/components/Tenanat/ContactInfro.jsx b/src/components/Tenanat/ContactInfro.jsx index 34da10c3..d0b2c3c3 100644 --- a/src/components/Tenanat/ContactInfro.jsx +++ b/src/components/Tenanat/ContactInfro.jsx @@ -96,7 +96,7 @@ const ContactInfro = ({ onNext }) => { )}
-
diff --git a/src/components/Tenanat/LogoUpload.jsx b/src/components/Tenanat/LogoUpload.jsx new file mode 100644 index 00000000..7c30d80f --- /dev/null +++ b/src/components/Tenanat/LogoUpload.jsx @@ -0,0 +1,85 @@ +import React from "react"; +import { useFormContext } from "react-hook-form"; + +const toBase64 = (file) => + new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result); + reader.onerror = reject; + reader.readAsDataURL(file); + }); + +export const LogoUpload = ({ preview, setPreview, fileName, setFileName }) => { + const { + register, + setValue, + formState: { errors }, + } = useFormContext(); + + const handleUpload = async (e) => { + const file = e.target.files?.[0]; + if (!file) return; + + if (file.size > 5 * 1024 * 1024) { + alert("File exceeds 5MB limit"); + return; + } + + const base64 = await toBase64(file); + setValue("logoImage", base64, { shouldValidate: true }); + setFileName(file.name); + setPreview(URL.createObjectURL(file)); + e.target.value = ""; + }; + + const handleClear = () => { + setValue("logoImage", "", { shouldValidate: true }); + setPreview(null); + setFileName(""); + }; + + return ( +
+
document.getElementById("logoImageInput")?.click()} + > + + Click or browse to upload + + +
+ + {errors.logoImage && ( + {errors.logoImage.message} + )} + + {preview && ( +
+ Preview +
+ {fileName} + +
+
+ )} +
+ ); +}; diff --git a/src/components/Tenanat/OrganizationInfo.jsx b/src/components/Tenanat/OrganizationInfo.jsx index b332d3a0..59401538 100644 --- a/src/components/Tenanat/OrganizationInfo.jsx +++ b/src/components/Tenanat/OrganizationInfo.jsx @@ -1,34 +1,61 @@ -import React from "react"; +import React, { useState } from "react"; import { useFormContext, Controller } from "react-hook-form"; import Label from "../common/Label"; import DatePicker from "../common/DatePicker"; +import { useIndustries } from "../../hooks/useTenant"; +import { LogoUpload } from "./LogoUpload"; -const OrganizationInfo = ({ onNext, onPrev }) => { +const OrganizationInfo = ({ onNext, onPrev,onSubmitTenant }) => { + const { data, isError, isLoading: industryLoading } = useIndustries(); + const [logoPreview, setLogoPreview] = useState(null); + const [logoName, setLogoName] = useState(""); const { register, control, + setValue, + getValues, trigger, formState: { errors }, } = useFormContext(); const handleNext = async () => { - const valid = await trigger([ - "organizationName", - "officeNumber", - "domainName", - "description", - "onBoardingDate", - "organizationSize", - "taxId", - "industryId", - "reference", - "logoImage", - ]); - if (valid) onNext(); - }; + const valid = await trigger([ + "organizationName", + "officeNumber", + "domainName", + "description", + "onBoardingDate", + "organizationSize", + "taxId", + "industryId", + "reference", + "logoImage", + ]); + + if (valid) { + const data = getValues(); + onSubmitTenant(data); + onNext(); + } +}; + + + const Reference = [ + { val: "google", name: "Google" }, + { val: "frined", name: "Friend" }, + { val: "advertisement", name: "Advertisement" }, + { val: "root tenant", name: "Root Tenant" }, + ]; + const orgSize = [ + { val: "50", name: "1-50" }, + { val: "100", name: "51-100" }, + { val: "500", name: "101-500" }, + { val: "600", name: "500+" }, + ]; + return ( -
+