diff --git a/apps/web/app/(auth)/signup/(components)/SignupFullForm.tsx b/apps/web/app/(auth)/signup/(components)/SignupFullForm.tsx index 9db76a1b..b84259d4 100644 --- a/apps/web/app/(auth)/signup/(components)/SignupFullForm.tsx +++ b/apps/web/app/(auth)/signup/(components)/SignupFullForm.tsx @@ -2,7 +2,7 @@ import { InputElement, SelectElement } from '@/components/forms'; import { Button } from '@/components/globalComponents'; -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { greaterThan8, validateEmail, validateLowercase, validateName, validateNumber, validatePhoneNumber, validateSymbol, validateUppercase @@ -39,7 +39,7 @@ const SignupFullForm = () => { const [companyTypes, setCompanyTypes] = useState(null); - const fetchSettings = async () => { + const fetchSettings = useCallback(async () => { const result = await clientAxiosRequest({ headers: {}, apiEndpoint: API.getAgreements(), @@ -48,9 +48,9 @@ const SignupFullForm = () => { noToast: true }) setAgreements(result?.data); - } + }, []); - const fetchTypes = async () => { + const fetchTypes = useCallback(async () => { const result = await clientAxiosRequest({ headers: {}, apiEndpoint: API.getCompanyTypes(), @@ -59,9 +59,9 @@ const SignupFullForm = () => { noToast: true }) setCompanyTypes(result?.data); - } + }, []); - const fetchRequiredFields = async () => { + const fetchRequiredFields = useCallback(async () => { const result = await clientAxiosRequest({ headers: {}, apiEndpoint: API.getCompanyRequiredFields({ @@ -72,16 +72,16 @@ const SignupFullForm = () => { noToast: true }) setRequiredFields(result?.data); - } + }, [userType]); useEffect(() => { fetchTypes(); - }, []); + }, [fetchTypes]); useEffect(() => { fetchSettings(); userType && fetchRequiredFields(); - }, [userType]); + }, [fetchRequiredFields, fetchSettings, userType]); const upperAndLowerCase = validateUppercase(password) && validateLowercase(password); const number = validateNumber(password); diff --git a/apps/web/app/(webapp)/(components)/AppLeftSideBar.tsx b/apps/web/app/(webapp)/(components)/AppLeftSideBar.tsx index 4bb374cd..abea2ba4 100644 --- a/apps/web/app/(webapp)/(components)/AppLeftSideBar.tsx +++ b/apps/web/app/(webapp)/(components)/AppLeftSideBar.tsx @@ -3,62 +3,27 @@ import { LEFT_SIDE_BAR_BOTTOM_DATA, LEFT_SIDE_BAR_TOP_DATA } from '@/data/leftSideBarData' import Link from 'next/link' import { usePathname } from 'next/navigation' -import React, { useEffect, useState } from 'react' +import React from 'react' import { motion } from 'framer-motion' -import clientAxiosRequest from '@/hooks/clientAxiosRequest' -import * as API from '@/config/endpoints'; import { findPermissionSlug } from '@/utils/findPermissionSlug' import { truncateString } from '@/utils/truncateString' +import { useUserStore } from '@/stores' const AppLeftSideBar = ({ bannerExist }: { bannerExist: boolean }) => { const pathname = usePathname(); - const [profile, setProfile] = useState(); - const [businessDetails, setBusinessDetails] = useState(null); - let userPermissions = profile?.user?.role?.permissions - - async function fetchProfile() { - const result: any = await clientAxiosRequest({ - headers: {}, - apiEndpoint: API.getProfile(), - method: 'GET', - data: null, - noToast: true - }); - - setProfile(result?.data); - // setJsCookies('aperta-user-profile', JSON.stringify({ - // name: `${result?.data?.firstName} ${result?.data?.lastName}`, - // companyRole: result?.data?.companyRole?.toLowerCase()?.replace(/_/g, ' '), - // userType: result?.data?.user?.role?.parent?.slug - // })) - } - - const fetchDetails = async () => { - const result : any = await clientAxiosRequest({ - headers: {}, - apiEndpoint: API.getCompanyDetails(), - method: 'GET', - data: null, - noToast: true - }); - - setBusinessDetails(result?.data); - } - - useEffect(() => { - fetchProfile(); - fetchDetails(); - }, []); + + // Get data from Zustand store instead of fetching + const profile = useUserStore((state) => state.profile); + const companyDetails = useUserStore((state) => state.companyDetails); + const getAvatarAlt = useUserStore((state) => state.getAvatarAlt); + + const userPermissions = profile?.user?.role?.permissions; + const firstName = profile?.firstName; + const avatarAlt = getAvatarAlt(); const isActive = (path: string): boolean => { return pathname?.includes(path); - } - - let firstName = profile?.firstName; - let lastName = profile?.lastName; - let avatarAlt = (firstName || lastName) ? - `${firstName ? firstName[0] : ''}${lastName ? lastName[0] : ''}` : - businessDetails?.name ? businessDetails?.name[0] : ''; + }; return (