Compare commits

..

No commits in common. "0fec257354f80ed3f66bacad05fa4324f7ebb682" and "7872e21477ca9e5a4ca41da7e44986a370527203" have entirely different histories.

9 changed files with 46 additions and 63 deletions

View File

@ -327,7 +327,6 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
control={control} control={control}
name="paidById" name="paidById"
projectId={null} projectId={null}
forAll={expenseToEdit ? true : false}
/> />
</div> </div>
</div> </div>

View File

@ -23,7 +23,7 @@ const OrganizationsList = ({searchText}) => {
label: "Organization Name", label: "Organization Name",
getValue: (org) => ( getValue: (org) => (
<div className="d-flex gap-2 py-1 "> <div className="d-flex gap-2 py-1 ">
<i className="bx bx-buildings"></i> <i class="bx bx-buildings"></i>
<span <span
className="text-truncate d-inline-block " className="text-truncate d-inline-block "
style={{ maxWidth: "150px" }} style={{ maxWidth: "150px" }}

View File

@ -4,13 +4,10 @@ import { useDebounce } from "../../utils/appUtils";
import { useController } from "react-hook-form"; import { useController } from "react-hook-form";
import Avatar from "./Avatar"; import Avatar from "./Avatar";
const EmployeeSearchInput = ({
control,
name,
projectId, const EmployeeSearchInput = ({ control, name, projectId,placeholder }) => {
placeholder,
forAll,
}) => {
const { const {
field: { onChange, value, ref }, field: { onChange, value, ref },
fieldState: { error }, fieldState: { error },
@ -20,20 +17,17 @@ const EmployeeSearchInput = ({
const [showDropdown, setShowDropdown] = useState(false); const [showDropdown, setShowDropdown] = useState(false);
const debouncedSearch = useDebounce(search, 500); const debouncedSearch = useDebounce(search, 500);
const { data: employees, isLoading } = useEmployeesName( const {
projectId, data: employees,
debouncedSearch, isLoading,
forAll } = useEmployeesName(projectId, debouncedSearch);
);
useEffect(() => { useEffect(() => {
if (value && employees?.data) { if (value && !search) {
const found = employees.data.find((emp) => emp.id === value); const found = employees?.data?.find((emp) => emp.id === value);
if (found && forAll) { if (found) setSearch(found.firstName + " " + found.lastName);
setSearch(found.firstName + " " + found.lastName);
}
} }
}, [value, employees?.data]); }, [value, employees]);
const handleSelect = (employee) => { const handleSelect = (employee) => {
onChange(employee.id); onChange(employee.id);
@ -67,27 +61,28 @@ const EmployeeSearchInput = ({
{isLoading ? ( {isLoading ? (
<li className="list-group-item"> <li className="list-group-item">
<a>Searching...</a> <a>Searching...</a>
</li> </li>
) : ( ) : (
employees?.data?.map((emp) => ( employees?.data?.map((emp) => (
<li <li
key={emp.id} key={emp.id}
className="list-group-item list-group-item-action py-1 px-1" className="list-group-item list-group-item-action py-1 px-1"
style={{ cursor: "pointer" }} style={{ cursor: "pointer" }}
onClick={() => handleSelect(emp)} onClick={() => handleSelect(emp)}
> >
<div className="d-flex align-items-center px-0"> <div className="d-flex align-items-center px-0">
<Avatar <Avatar
size="xs" size="xs"
classAvatar="m-0 me-2" classAvatar="m-0 me-2"
firstName={emp.firstName} firstName={emp.firstName}
lastName={emp.lastName} lastName={emp.lastName}
/> />
<span className="text-muted"> <span className="text-muted">
{`${emp?.firstName} ${emp?.lastName}`.trim()} {`${emp?.firstName} ${emp?.lastName}`.trim()}
</span> </span>
</div> </div>
</li> </li>
)) ))
)} )}
</ul> </ul>

View File

@ -184,11 +184,11 @@ export const useEmployeeProfile = (employeeId) => {
}; };
}; };
export const useEmployeesName = (projectId, search,allEmployee) => { export const useEmployeesName = (projectId, search) => {
return useQuery({ return useQuery({
queryKey: ["employees", projectId, search,allEmployee], queryKey: ["employees", projectId, search],
queryFn: async () => queryFn: async () =>
await EmployeeRepository.getEmployeeName(projectId, search,allEmployee), await EmployeeRepository.getEmployeeName(projectId, search),
staleTime: 5 * 60 * 1000, // Optional: cache for 5 minutes staleTime: 5 * 60 * 1000, // Optional: cache for 5 minutes
}); });

View File

@ -6,7 +6,6 @@ import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod"; import { z } from "zod";
import { AuthWrapper } from "./AuthWrapper"; import { AuthWrapper } from "./AuthWrapper";
import { removeSession } from "../../utils/authUtils";
const LoginPage = () => { const LoginPage = () => {
const navigate = useNavigate(); const navigate = useNavigate();
@ -45,11 +44,9 @@ const LoginPage = () => {
if (data.rememberMe) { if (data.rememberMe) {
localStorage.setItem("jwtToken", response.data.token); localStorage.setItem("jwtToken", response.data.token);
localStorage.setItem("refreshToken", response.data.refreshToken); localStorage.setItem("refreshToken", response.data.refreshToken);
removeSession("session")
} else { } else {
sessionStorage.setItem("jwtToken", response.data.token); sessionStorage.setItem("jwtToken", response.data.token);
sessionStorage.setItem("refreshToken", response.data.refreshToken); sessionStorage.setItem("refreshToken", response.data.refreshToken);
removeSession("local")
} }
setLoading(false); setLoading(false);
navigate("/auth/switch/org"); navigate("/auth/switch/org");

View File

@ -86,7 +86,7 @@ const SwitchTenant = () => {
<button <button
className={` ${currentTenant === tenant.id ? "badge bg-label-primary w-50" :"btn btn-primary btn-sm mt-2 align-self-start" }`} className={` ${currentTenant === tenant.id ? "badge bg-label-primary w-50" :"btn btn-primary btn-sm mt-2 align-self-start" }`}
onClick={() => handleTenantselection(tenant?.id)} onClick={() => handleTenantselection(tenant?.id)}
disabled={isPending && pendingTenant === tenant.id || currentTenant === tenant.id || isPending} disabled={isPending && pendingTenant === tenant.id || currentTenant === tenant.id }
> >
{currentTenant === tenant.id ? "Active Tenant" :isPending && pendingTenant === tenant.id {currentTenant === tenant.id ? "Active Tenant" :isPending && pendingTenant === tenant.id
? "Please Wait.." ? "Please Wait.."

View File

@ -11,12 +11,11 @@ const EmployeeRepository = {
// deleteEmployee: ( id ) => api.delete( `/users/${ id }` ), // deleteEmployee: ( id ) => api.delete( `/users/${ id }` ),
getEmployeeProfile: (id) => api.get(`/api/employee/profile/get/${id}`), getEmployeeProfile: (id) => api.get(`/api/employee/profile/get/${id}`),
deleteEmployee: (id,active) => api.delete(`/api/employee/${id}?active=${active}`), deleteEmployee: (id,active) => api.delete(`/api/employee/${id}?active=${active}`),
getEmployeeName: (projectId, search,allEmployee) => { getEmployeeName: (projectId, search) => {
const params = new URLSearchParams(); const params = new URLSearchParams();
if (projectId) params.append("projectId", projectId); if (projectId) params.append("projectId", projectId);
if (search) params.append("searchString", search); if (search) params.append("searchString", search);
if(allEmployee) params.append("allEmployee",allEmployee)
const query = params.toString(); const query = params.toString();
return api.get(`/api/Employee/basic${query ? `?${query}` : ""}`); return api.get(`/api/Employee/basic${query ? `?${query}` : ""}`);

View File

@ -59,7 +59,7 @@ const attemptTokenRefresh = async (storedRefreshToken) => {
return true; return true;
} catch (error) { } catch (error) {
removeSession() console.error("Token refresh failed:", error);
return false; return false;
} }
}; };

View File

@ -1,14 +1,7 @@
export const removeSession = (target = "all") => { export const removeSession = () => {
const keys = ["jwtToken", "refreshToken", "ctnt"]; localStorage.removeItem("jwtToken");
localStorage.removeItem("refreshToken");
if (target === "local") { sessionStorage.removeItem("jwtToken");
keys.forEach((key) => localStorage.removeItem(key)); sessionStorage.removeItem("refreshToken");
} else if (target === "session") { localStorage.removeItem("ctnt");
keys.forEach((key) => sessionStorage.removeItem(key));
} else if (target === "all") {
keys.forEach((key) => {
localStorage.removeItem(key);
sessionStorage.removeItem(key);
});
}
}; };