mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
fix(guided-tour): wrapped startSection and setCurrentStep with useCallback hooks
This commit is contained in:
parent
466ac108a0
commit
f564420630
@ -1,4 +1,4 @@
|
||||
import React, { useReducer } from 'react';
|
||||
import React, { useCallback, useReducer } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import get from 'lodash/get';
|
||||
import { GuidedTourProvider } from '@strapi/helper-plugin';
|
||||
@ -15,24 +15,27 @@ const GuidedTour = ({ children }) => {
|
||||
init
|
||||
);
|
||||
|
||||
const setCurrentStep = step => {
|
||||
// if step is null it is intentional, we need to dispatch it
|
||||
if (step !== null) {
|
||||
const isStepAlreadyDone = get(guidedTourState, step);
|
||||
const isStepToShow = arePreviousStepsDone(step, guidedTourState);
|
||||
const setCurrentStep = useCallback(
|
||||
step => {
|
||||
// if step is null it is intentional, we need to dispatch it
|
||||
if (step !== null) {
|
||||
const isStepAlreadyDone = get(guidedTourState, step);
|
||||
const isStepToShow = arePreviousStepsDone(step, guidedTourState);
|
||||
|
||||
if (isStepAlreadyDone || isSkipped || !isStepToShow) {
|
||||
return null;
|
||||
if (isStepAlreadyDone || isSkipped || !isStepToShow) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
persistStateToLocaleStorage.addCurrentStep(step);
|
||||
persistStateToLocaleStorage.addCurrentStep(step);
|
||||
|
||||
return dispatch({
|
||||
type: 'SET_CURRENT_STEP',
|
||||
step,
|
||||
});
|
||||
};
|
||||
return dispatch({
|
||||
type: 'SET_CURRENT_STEP',
|
||||
step,
|
||||
});
|
||||
},
|
||||
[guidedTourState, isSkipped]
|
||||
);
|
||||
|
||||
const setGuidedTourVisibility = value => {
|
||||
dispatch({
|
||||
@ -51,21 +54,24 @@ const GuidedTour = ({ children }) => {
|
||||
});
|
||||
};
|
||||
|
||||
const startSection = sectionName => {
|
||||
const sectionSteps = guidedTourState[sectionName];
|
||||
const startSection = useCallback(
|
||||
sectionName => {
|
||||
const sectionSteps = guidedTourState[sectionName];
|
||||
|
||||
if (sectionSteps) {
|
||||
const isSectionToShow = arePreviousSectionsDone(sectionName, guidedTourState);
|
||||
const firstStep = Object.keys(sectionSteps)[0];
|
||||
const isFirstStepDone = sectionSteps[firstStep];
|
||||
if (sectionSteps) {
|
||||
const isSectionToShow = arePreviousSectionsDone(sectionName, guidedTourState);
|
||||
const firstStep = Object.keys(sectionSteps)[0];
|
||||
const isFirstStepDone = sectionSteps[firstStep];
|
||||
|
||||
if (isSectionToShow && !currentStep && !isFirstStepDone) {
|
||||
return setCurrentStep(`${sectionName}.${firstStep}`);
|
||||
if (isSectionToShow && !currentStep && !isFirstStepDone) {
|
||||
return setCurrentStep(`${sectionName}.${firstStep}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
return null;
|
||||
},
|
||||
[currentStep, guidedTourState, setCurrentStep]
|
||||
);
|
||||
|
||||
const setSkipped = value => {
|
||||
persistStateToLocaleStorage.setSkipped(value);
|
||||
|
||||
@ -38,7 +38,7 @@ const ApiTokenListView = () => {
|
||||
|
||||
useEffect(() => {
|
||||
startSection('apiTokens');
|
||||
});
|
||||
}, [startSection]);
|
||||
|
||||
useEffect(() => {
|
||||
push({ search: qs.stringify({ sort: 'name:ASC' }, { encode: false }) });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user