updates
This commit is contained in:
parent
e534802abb
commit
9ff4ece541
@ -1,5 +1,6 @@
|
|||||||
import React, { useState, createContext, useContext, useEffect, useCallback } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
import { ShepherdJourneyProvider, useShepherd } from 'react-shepherd';
|
import { ShepherdJourneyProvider, useShepherd } from 'react-shepherd';
|
||||||
|
import { StepOptions, TourOptions } from 'shepherd.js';
|
||||||
import 'shepherd.js/dist/css/shepherd.css';
|
import 'shepherd.js/dist/css/shepherd.css';
|
||||||
|
|
||||||
const OnboardingProviderContext = createContext(null);
|
const OnboardingProviderContext = createContext(null);
|
||||||
@ -7,53 +8,30 @@ const { Provider } = OnboardingProviderContext;
|
|||||||
|
|
||||||
export const useOnboardingProvider = () => useContext(OnboardingProviderContext);
|
export const useOnboardingProvider = () => useContext(OnboardingProviderContext);
|
||||||
|
|
||||||
const ShepherdController = () => {
|
const ShepherdController = ({
|
||||||
|
tours,
|
||||||
|
}: {
|
||||||
|
tours: Array<{
|
||||||
|
tourOptions: TourOptions;
|
||||||
|
steps: StepOptions[];
|
||||||
|
route: string;
|
||||||
|
id: string;
|
||||||
|
}>;
|
||||||
|
}) => {
|
||||||
const Shepherd = useShepherd();
|
const Shepherd = useShepherd();
|
||||||
const [tour, setTour] = useState(null);
|
|
||||||
|
|
||||||
const initializeTour = useCallback(
|
|
||||||
(steps, tourOptions = {}) => {
|
|
||||||
const newTour = new Shepherd.Tour({
|
|
||||||
steps,
|
|
||||||
...tourOptions,
|
|
||||||
});
|
|
||||||
setTour(newTour);
|
|
||||||
},
|
|
||||||
[Shepherd]
|
|
||||||
);
|
|
||||||
|
|
||||||
const startTour = useCallback(() => {
|
|
||||||
if (tour) {
|
|
||||||
tour.start();
|
|
||||||
}
|
|
||||||
}, [tour]);
|
|
||||||
|
|
||||||
const exitTour = useCallback(() => {
|
|
||||||
if (tour) {
|
|
||||||
tour.cancel();
|
|
||||||
}
|
|
||||||
}, [tour]);
|
|
||||||
|
|
||||||
const nextStep = useCallback(() => {
|
|
||||||
if (tour) {
|
|
||||||
tour.next();
|
|
||||||
}
|
|
||||||
}, [tour]);
|
|
||||||
|
|
||||||
const previousStep = useCallback(() => {
|
|
||||||
if (tour) {
|
|
||||||
tour.back();
|
|
||||||
}
|
|
||||||
}, [tour]);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const OnboardingProvider = ({ children }: { children: React.ReactNode }) => {
|
const OnboardingProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
const tours = window?.config?.tours;
|
||||||
|
if (!tours) {
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<ShepherdJourneyProvider>
|
<ShepherdJourneyProvider>
|
||||||
<Provider value={{}}>
|
<Provider value={{}}>
|
||||||
<ShepherdController />
|
<ShepherdController tours={tours} />
|
||||||
{children}
|
{children}
|
||||||
</Provider>
|
</Provider>
|
||||||
</ShepherdJourneyProvider>
|
</ShepherdJourneyProvider>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user