diff --git a/src/components/Tenant/CreateTenant.jsx b/src/components/Tenant/CreateTenant.jsx index 0391642e..a78a7332 100644 --- a/src/components/Tenant/CreateTenant.jsx +++ b/src/components/Tenant/CreateTenant.jsx @@ -5,6 +5,7 @@ import Breadcrumb from "../common/Breadcrumb"; import { apiTenant } from "./apiTenant"; import { useCreateTenant } from "./useTenants"; import TenantSubscription from "./TenantSubscription"; +import { useQueryClient } from "@tanstack/react-query"; const defaultAvatar = "https://via.placeholder.com/100x100.png?text=Avatar"; const initialData = { @@ -22,18 +23,28 @@ const initialData = { taxId: "", billingAddress: "", onBoardingDate: "", + status: "", }; +// RequiredLabel component remains the same for mandatory fields const RequiredLabel = ({ label, name }) => ( ); +// Regular label for non-mandatory fields +const RegularLabel = ({ label, name }) => ( + +); + const validateForm = (form, step) => { let errors = {}; let fieldsToValidate = []; + // Updated list of mandatory fields for each step if (step === 1) { fieldsToValidate = [ "firstName", @@ -45,11 +56,11 @@ const validateForm = (form, step) => { } else if (step === 2) { fieldsToValidate = [ "organizationName", + "onBoardingDate", "organizationSize", "industryId", "reference", - "domainName", - "onBoardingDate", + "status", ]; } @@ -71,7 +82,9 @@ const CreateTenant = () => { const navigate = useNavigate(); const { state } = useLocation(); const formData = state?.formData || null; - const { createTenant, updateTenant, loading } = useCreateTenant(); + // const { createTenant, updateTenant, loading } = useCreateTenant(); + const { mutate: createTenant, isPending } = useCreateTenant(); + const queryClient = useQueryClient(); const [form, setForm] = useState(initialData); const [formErrors, setFormErrors] = useState({}); @@ -169,7 +182,7 @@ const CreateTenant = () => { } setFormErrors({}); const finalLogoImage = imageFile || (imagePreview === defaultAvatar ? null : imagePreview); - const submissionData = { + const tenantPayload = { ...form, logoImage: finalLogoImage, contactNumber: form.phone, @@ -177,14 +190,15 @@ const CreateTenant = () => { }; let result; if (formData?.id) { - result = await updateTenant(formData.id, submissionData); + // result = await updateTenant(formData.id, tenantPayload); if (result) navigate("/tenant/profile", { state: { newTenant: result } }); } else { - result = await createTenant(submissionData); - if (result) navigate("/tenant/profile/viewtenant", { state: { formData: result } }); + // result = await createTenant(submissionData); + // if (result) navigate("/tenant/profile/viewtenant", { state: { formData: result } }); + createTenant(tenantPayload); } }, - [form, imagePreview, imageFile, formData, navigate, createTenant, updateTenant] + [form, imagePreview, imageFile, formData, navigate, createTenant] ); const renderFormStep = () => { @@ -208,7 +222,7 @@ const CreateTenant = () => { {formErrors?.email && (
{formErrors.email}
)}{formErrors.phone}
)}{form.organizationName}
)} + {formErrors?.organizationName && ({formErrors.organizationName}
)}{formErrors.reference}
)}{formErrors.status}
)}{formErrors.taxId}
)} +{formErrors.domainName}
)}{formErrors.mobile}
)}{formErrors.description}
)}| Organization | Name | - {/*Phone | - {/*Domain | */} -Size | +User | Industry | Actions | {tenant.email} | */}{tenant.contactNumber} | - {/*{tenant.domainName} | */} - {/*- {tenant.domainName ? ( - <> - - {tenant.domainName} - > - ) : ( - -- - )} - | */} - -{tenant.organizationSize} | {tenant.industry?.name} | @@ -172,7 +153,7 @@ const Tenant = () => { onClick={() => handleView(tenant)} > handleEdit(tenant)} > { > | - ); })} diff --git a/src/components/Tenant/TenantSkeleton.jsx b/src/components/Tenant/TenantSkeleton.jsx new file mode 100644 index 00000000..9440a229 --- /dev/null +++ b/src/components/Tenant/TenantSkeleton.jsx @@ -0,0 +1,59 @@ +import React from "react"; + +const SkeletonRow = () => ( +
|---|---|---|---|---|---|---|---|---|
|
+
+
+
+ |
+ ))}
+
+
+ {Array.from({ length: 3 }).map((_, idx) => (
+
+ ))}
+
+ |
+
| Organization | +Name | +Phone | +Size | +Industry | +Actions | +
|---|
Choose your billing cycle:
Loading plans...
} + {error &&{error}
} + + {plans.length > 0 && (Select a plan:
{currentPlan.description}
{currentPlan.subText}
}