diff --git a/src/components/Tenanat/EditProfile.jsx b/src/components/Tenanat/EditProfile.jsx
new file mode 100644
index 00000000..98af6f45
--- /dev/null
+++ b/src/components/Tenanat/EditProfile.jsx
@@ -0,0 +1,184 @@
+import React, { useEffect, useState } from 'react';
+import Label from '../common/Label';
+import { useFormContext,useForm,FormProvider } from 'react-hook-form';
+import { useIndustries, useTenantDetails, useUpdateTenantDetails } from '../../hooks/useTenant';
+import { orgSize, reference } from '../../utils/constants';
+import { LogoUpload } from './LogoUpload';
+import showToast from '../../services/toastService';
+
+const EditProfile = ({ TenantId,onClose }) => {
+ const { data, isLoading, isError, error } = useTenantDetails(TenantId);
+ const [logoPreview, setLogoPreview] = useState(null);
+ const [logoName, setLogoName] = useState("");
+ const { data: Industries, isLoading: industryLoading, isError: industryError } = useIndustries();
+ const {mutate:UpdateTenant,isPending,} = useUpdateTenantDetails(()=>{
+ showToast("Tenant Details Updated Successfully","success")
+ onClose()
+
+ })
+ const methods = useForm({
+ defaultValues: {
+ firstName: "",
+ lastName: "",
+ email: "",
+ contactNumber: "",
+ description: "",
+ domainName: "",
+ billingAddress: "",
+ taxId: "",
+ logoImage: "",
+ officeNumber: "",
+ organizationSize: "",
+ industryId: "",
+ reference: "",
+ }
+ });
+
+ const { register, reset, handleSubmit, formState: { errors } } = methods;
+
+ const onSubmit = (formData) => {
+ const tenantPayload = {...formData,contactName:`${formData.firstName} ${formData.lastName}`,id:data.id,}
+ UpdateTenant({id:data.id,tenantPayload})
+ };
+
+ useEffect(() => {
+ if (data && Industries) {
+ const [first = "", last = ""] = (data.contactName ?? "").split(" ");
+ reset({
+ firstName: first,
+ lastName: last,
+ contactNumber: data.contactNumber ?? "",
+ description: data.description ?? "",
+ domainName: data.domainName ?? "",
+ billingAddress: data.billingAddress ?? "",
+ taxId: data.taxId ?? "",
+ logoImage: data.logoImage ?? "",
+ officeNumber: data.officeNumber ?? "",
+ organizationSize: data.organizationSize ?? "",
+ industryId: data.industry?.id ?? "",
+ reference: data.reference ?? "",
+ });
+ setLogoPreview(data.logoImage)
+ }
+ }, [data, Industries, reset]);
+
+ if (isLoading) return
Loading...
;
+ if (isError) return {error?.message}
;
+
+
+ return (
+
+
+
+ );
+};
+
+export default EditProfile;
diff --git a/src/components/Tenanat/Profile.jsx b/src/components/Tenanat/Profile.jsx
index 0f96a5ac..1a96d308 100644
--- a/src/components/Tenanat/Profile.jsx
+++ b/src/components/Tenanat/Profile.jsx
@@ -1,158 +1,170 @@
-import React from "react";
+import React, { useState } from "react";
import { formatUTCToLocalTime } from "../../utils/dateUtils";
+import EditProfile from "./EditProfile";
+import GlobalModel from "../common/GlobalModel";
+import { useTenantContext } from "../../pages/Tenant/TenantPage";
+import { useTenantDetailsContext } from "../../pages/Tenant/TenantDetails";
const Profile = ({ data }) => {
- // const {logoImage,name,domainName,contactName,contactNumber,officeNumber} = data;
+ const {setEditTenant} = useTenantDetailsContext()
return (
-
-
-
-
-
-

-
-
-
{data.name}
-
-
-
{data?.domainName}
+ <>
+
+
+
+
+
+
+
-
- {data?.tenantStatus?.name}
-
+
+
{data.name}
+
+
+ {data?.domainName}
+
+
setEditTenant(true)}
+ >
+
+
+
+
+
+
+ {data?.description && (
+
+ )}
+
+
+
+
+ Contact Person:
+ {data.contactName}
+
+
+
+
+ Email:
+ {data.email}
+
+
+
+ Contact Number:
+ {data.contactNumber}
+
+
+
+
+ Address:
+ {data.billingAddress}
- {data?.description && (
-
- )}
-
+
+
+ Industry:
+ {data.industry.name}
+
+ {data.taxId && (
+
+
+ Tax Id:
+ {data.taxId}
+
+ )}
+
+
+ Organization Size:
+ {data.organizationSize}
+
-
- Contact Person:
- {data.contactName}
+
+ On-Boarding Date:
+
+ {formatUTCToLocalTime(data.onBoardingDate)}
+
+
+
+
+
+
+ |
+ Status
+ |
+
+ Active
+ |
+
+ In-Progress
+ |
+
+ On Hold
+ |
+
+ In-Active
+ |
+
+ Completed
+ |
+
+
+ |
+ Projects
+ |
+
+ {data?.activeProjects}
+ |
+
+ {data?.inProgressProjects}
+ |
+
+ {data?.onHoldProjects}
+ |
+
+ {data?.inActiveProjects}
+ |
+
+ {data?.completedProjects}
+ |
+
+
+
+
+
+
+
+ Activite Employees:
+ {data.activeEmployees}
-
- Email:
- {data.email}
-
-
-
- Contact Number:
- {data.contactNumber}
-
-
-
-
- Address:
- {data.billingAddress}
+
+ In-Active Employee:
+ {data.inActiveEmployees}
-
-
-
-
- Industry:
- {data.industry.name}
-
-
- {data.taxId && (
-
-
- Tax Id:
- {data.taxId}
-
- )}
-
-
- Organization Size:
- {data.organizationSize}
-
-
-
- On-Boarding Date:
-
- {formatUTCToLocalTime(data.onBoardingDate)}
-
-
-
-
-
-
- |
- Status
- |
-
- Active
- |
-
- In-Progress
- |
-
- On Hold
- |
-
- In-Active
- |
-
- Completed
- |
-
-
- |
- Projects
- |
-
- {data?.activeProjects}
- |
-
- {data?.inProgressProjects}
- |
-
- {data?.onHoldProjects}
- |
-
- {data?.inActiveProjects}
- |
-
- {data?.completedProjects}
- |
-
-
-
-
-
-
-
- Activite Employees:
- {data.activeEmployees}
-
-
-
-
- In-Active Employee:
- {data.inActiveEmployees}
-
-
-
+ >
);
};
export default Profile;
+//
+// {data?.tenantStatus?.name}
+//
diff --git a/src/components/Tenanat/TenantSchema.js b/src/components/Tenanat/TenantSchema.js
index f888e195..9303b01e 100644
--- a/src/components/Tenanat/TenantSchema.js
+++ b/src/components/Tenanat/TenantSchema.js
@@ -115,3 +115,20 @@ export const getStepFields = (stepIndex) => {
return stepFieldMap[stepIndex] || [];
};
+
+export const EditTenant = z.object({
+ firstName: z.string().min(1, { message: "First Name is required!" }),
+ lastName: z.string().min(1, { message: "Last Name is required!" }),
+ description: z.string().optional(),
+ domainName: z.string().min(1, { message: "Domain Name is required!" }),
+ billingAddress: z.string().min(1, { message: "Billing Address is required!" }),
+ taxId: z.string().min(1, { message: "Tax ID is required!" }),
+ logoImage: z.string().optional(),
+ officeNumber: z.string().min(1, { message: "Office Number is required!" }),
+ contactNumber: z
+ .string()
+ .min(10, { message: "Contact Number must be at least 10 digits!" }),
+ organizationSize: z.string().min(1, { message: "Organization Size is required!" }),
+ industryId: z.string().min(1,{ message: "Invalid Industry ID!" }),
+ reference: z.string().optional(),
+});
diff --git a/src/hooks/useTenant.js b/src/hooks/useTenant.js
index 1142cc3a..cce4064f 100644
--- a/src/hooks/useTenant.js
+++ b/src/hooks/useTenant.js
@@ -72,6 +72,7 @@ export const useSubscriptionPlan=(freq)=>{
return useQuery({
queryKey:['SubscriptionPlan',freq],
queryFn:async()=>{
+ console.log("call")
const res = await TenantRepository.getSubscriptionPlan(freq);
return res.data;
}
@@ -98,6 +99,22 @@ export const useCreateTenant = (onSuccessCallback)=>{
})
}
+export const useUpdateTenantDetails = (onSuccessCallback)=>{
+ const queryClient = useQueryClient();
+
+ return useMutation({
+ mutationFn:async({id,tenantPayload})=> TenantRepository.updateTenantDetails(id,tenantPayload),
+ onSuccess:(_,variables)=>{
+ const {id} = variables.tenantPayload;
+ queryClient.invalidateQueries({queryKey:["Tenant",id]})
+ queryClient.invalidateQueries({queryKey:["Tenants"]})
+ if(onSuccessCallback) onSuccessCallback()
+ },
+ onError:(error)=>{
+ showToast(error.response.message || error.message || `Something went wrong`,"error")
+ }
+ })
+}
export const useAddSubscription =(onSuccessCallback)=>{
const queryClient = useQueryClient()
diff --git a/src/pages/Tenant/TenantDetails.jsx b/src/pages/Tenant/TenantDetails.jsx
index 311f3fd0..997143c2 100644
--- a/src/pages/Tenant/TenantDetails.jsx
+++ b/src/pages/Tenant/TenantDetails.jsx
@@ -1,14 +1,25 @@
-import React from "react";
+import React, { createContext, useContext,useState } from "react";
import { useParams } from "react-router-dom";
import Breadcrumb from "../../components/common/Breadcrumb";
import Profile from "../../components/Tenanat/profile";
import { useTenantDetails } from "../../hooks/useTenant";
import Organization from "../../components/Tenanat/Organization";
import { ComingSoonPage } from "../Misc/ComingSoonPage";
+import GlobalModel from "../../components/common/GlobalModel";
+import EditProfile from "../../components/Tenanat/EditProfile";
+
+const TenantDetailsContext = createContext();
+export const useTenantDetailsContext = () => useContext(TenantDetailsContext);
+
const TenantDetails = () => {
const { tenantId } = useParams();
const { data, isLoading, isError, error } = useTenantDetails(tenantId);
+ const [editTenant, setEditTenant] = useState(false);
+ const contextValues ={
+ setEditTenant,editTenant
+ }
+
const tabs = [
{
@@ -43,10 +54,13 @@ const TenantDetails = () => {
),
},
];
+
if (isLoading) return
Loading...
;
if (isError) return
{error.message}
;
return (
-
+
+
+ {editTenant && (
+
setEditTenant(false)}>
+ setEditTenant(false)}/>
+
+ )}
+ >
);
};
diff --git a/src/repositories/TenantRepository.jsx b/src/repositories/TenantRepository.jsx
index 2631764a..82ce5c0b 100644
--- a/src/repositories/TenantRepository.jsx
+++ b/src/repositories/TenantRepository.jsx
@@ -13,6 +13,7 @@ export const TenantRepository = {
api.get(`/api/Tenant/list/subscription-plan?frequency=${freq}`),
createTenant: (data) => api.post("/api/Tenant/create", data),
+ updateTenantDetails :(id,data)=> api.put(`/api/Tenant/edit/${id}`,data),
addSubscription: (data) => api.post("/api/Tenant/add-subscription", data),
};