Skip to content

Commit

Permalink
moved onboarding availability flag to context
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrubin committed Jul 27, 2023
1 parent 8be8060 commit f1b6d5f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/app/components/OnboardingButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Button, Tooltip } from "antd";
import { BookOpen } from "phosphor-react";
import React, { useContext } from "react";
import { useSelector } from "react-redux";
import { RootState } from "../store/store";
import { BackendStatus } from "../types/mainSlice.types";
import { useOnBoardingRef } from "../../features/onboarding/utils/useOnboardingRef";
import { OnbrdStep } from "../../features/onboarding/types/constants";
import { OnboardingPopup } from "../../features/onboarding/components/OnboardingPopup";
Expand All @@ -13,10 +10,7 @@ import { OnboardingContext } from "../../features/onboarding/OnboardingProvider"
export const OnboardingButton = () => {
const [isTooltipVisible, setIsTooltipVisible] = React.useState(false);

const isOnboardingAvailable =
useSelector<RootState>((_state) => _state.main.backendAvailable) === BackendStatus.Accessed;

const { isOpen: isOnboardingOpen } = useContext(OnboardingContext);
const { isOnboardingAvailable } = useContext(OnboardingContext);

const onbrdRef = useOnBoardingRef(OnbrdStep.Onboarding);

Expand All @@ -29,7 +23,7 @@ export const OnboardingButton = () => {
title={componentsTexts.OnboardingButtonTitle}
>
<Button
disabled={!isOnboardingAvailable || isOnboardingOpen}
disabled={!isOnboardingAvailable}
ref={onbrdRef}
type="link"
icon={<BookOpen size={14} color="#8C8C8C" />}
Expand Down
2 changes: 2 additions & 0 deletions src/features/onboarding/OnboardingProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const OnboardingProvider: FC<Props> = ({ children }) => {
const isBackendAvailable = useSelector((state: RootState) => state.main.backendAvailable) === BackendStatus.Accessed;
const isDefaultState = useSelector<RootState>(selectIsDefaultState);
const isSessionUnique = useSelector((state: RootState) => state.main.isSessionUnique);
const isOnboardingAvailable = isBackendAvailable && !isOnbrdOpen;

const dispatch = useDispatch();

Expand Down Expand Up @@ -131,6 +132,7 @@ export const OnboardingProvider: FC<Props> = ({ children }) => {
value={{
defaultStep,
isOpen: isOnbrdOpen,
isOnboardingAvailable,
tourSteps,
isCustomLocatorFlow,
addRef,
Expand Down
6 changes: 1 addition & 5 deletions src/features/onboarding/components/OnboardingPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Popconfirm } from "antd";
import { RootState } from "../../../app/store/store";
import { selectIsDefaultState } from "../../../app/main.selectors";
import { OnboardingContext } from "../OnboardingProvider";
import { BackendStatus } from "../../../app/types/mainSlice.types";
import { OnboardingPopupText, OnboardingPopupButtons } from "../types/constants";

interface Props {
Expand All @@ -14,10 +13,7 @@ interface Props {
export const OnboardingPopup: FC<Props> = ({ children }) => {
const { openOnboarding } = useContext(OnboardingContext);
const isDefaultState = useSelector<RootState>(selectIsDefaultState);
const { isOpen: isOnboardingOpen } = useContext(OnboardingContext);

const isOnboardingAvailable =
useSelector<RootState>((_state) => _state.main.backendAvailable) === BackendStatus.Accessed && !isOnboardingOpen;
const { isOnboardingAvailable } = useContext(OnboardingContext);

return (
<Popconfirm
Expand Down
1 change: 1 addition & 0 deletions src/features/onboarding/types/context.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface OnboardingContext {
defaultStep?: number;
isCustomLocatorFlow: boolean;
isOpen: boolean;
isOnboardingAvailable: boolean;
tourSteps: TourProps["steps"];
addRef: (
name: OnbrdStep,
Expand Down

0 comments on commit f1b6d5f

Please sign in to comment.