fix: handle redirect in onboarding (#6324)

This commit is contained in:
Yunus M 2024-10-30 20:30:01 +05:30 committed by GitHub
parent 2fe75e74cd
commit 860145fb1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 3 deletions

View File

@ -37,6 +37,7 @@ import {
UPDATE_ORG_PREFERENCES,
} from 'types/actions/app';
import AppReducer, { User } from 'types/reducer/app';
import { USER_ROLES } from 'types/roles';
import { extractDomain, isCloudUser, isEECloudUser } from 'utils/app';
import PrivateRoute from './Private';
@ -74,7 +75,7 @@ function App(): JSX.Element {
const { data: orgPreferences, isLoading: isLoadingOrgPreferences } = useQuery({
queryFn: () => getAllOrgPreferences(),
queryKey: ['getOrgPreferences'],
enabled: isLoggedInState,
enabled: isLoggedInState && role === USER_ROLES.ADMIN,
});
useEffect(() => {
@ -95,6 +96,17 @@ function App(): JSX.Element {
}
}, [orgPreferences, dispatch, isLoadingOrgPreferences]);
useEffect(() => {
if (isLoggedInState && role !== USER_ROLES.ADMIN) {
dispatch({
type: UPDATE_IS_FETCHING_ORG_PREFERENCES,
payload: {
isFetchingOrgPreferences: false,
},
});
}
}, [isLoggedInState, role, dispatch]);
const featureResponse = useGetFeatureFlag((allFlags) => {
dispatch({
type: UPDATE_FEATURE_FLAG_RESPONSE,

View File

@ -25,6 +25,7 @@ import {
UPDATE_ORG_PREFERENCES,
} from 'types/actions/app';
import AppReducer from 'types/reducer/app';
import { USER_ROLES } from 'types/roles';
import {
AboutSigNozQuestions,
@ -69,7 +70,10 @@ const INITIAL_OPTIMISE_SIGNOZ_DETAILS: OptimiseSignozDetails = {
function OnboardingQuestionaire(): JSX.Element {
const { notifications } = useNotifications();
const { org } = useSelector<AppState, AppReducer>((state) => state.app);
const { org, role, isLoggedIn: isLoggedInState } = useSelector<
AppState,
AppReducer
>((state) => state.app);
const [currentStep, setCurrentStep] = useState<number>(1);
const [orgDetails, setOrgDetails] = useState<OrgDetails>(INITIAL_ORG_DETAILS);
const [signozDetails, setSignozDetails] = useState<SignozDetails>(
@ -103,12 +107,13 @@ function OnboardingQuestionaire(): JSX.Element {
} = useQuery({
queryFn: () => getOrgPreference({ preferenceID: 'ORG_ONBOARDING' }),
queryKey: ['getOrgPreferences', 'ORG_ONBOARDING'],
enabled: role === USER_ROLES.ADMIN,
});
const { data: orgPreferences, isLoading: isLoadingOrgPreferences } = useQuery({
queryFn: () => getAllOrgPreferences(),
queryKey: ['getOrgPreferences'],
enabled: isOnboardingComplete,
enabled: isOnboardingComplete && role === USER_ROLES.ADMIN,
});
useEffect(() => {
@ -129,6 +134,17 @@ function OnboardingQuestionaire(): JSX.Element {
}
}, [orgPreferences, dispatch, isLoadingOrgPreferences]);
useEffect(() => {
if (isLoggedInState && role !== USER_ROLES.ADMIN) {
dispatch({
type: UPDATE_IS_FETCHING_ORG_PREFERENCES,
payload: {
isFetchingOrgPreferences: false,
},
});
}
}, [isLoggedInState, role, dispatch]);
useEffect(() => {
if (
!isLoadingOnboardingPreference &&