mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
cfb1474eb8
* all login methods no longer use redux * removed redux from registration * redirect user from registration * removed redux from sso invite * removed redundant component * refactored user settings page * removed redux from logout * cleaned up unused redux calls * lint fixes * removed test * removed old config interface * fixed registration bug * team permission fix * removed remaining redux references from pages - #4436 * better way to set config
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import React, { createContext, useReducer, ReactNode } from "react";
|
|
|
|
type Props = {
|
|
children: ReactNode;
|
|
};
|
|
|
|
type InitialStateType = {
|
|
redirectLocation: string | null;
|
|
setRedirectLocation: (pathname: string | null) => void;
|
|
};
|
|
|
|
const initialState = {
|
|
redirectLocation: null,
|
|
setRedirectLocation: () => null,
|
|
};
|
|
|
|
const actions = {
|
|
SET_REDIRECT_LOCATION: "SET_REDIRECT_LOCATION",
|
|
};
|
|
|
|
const reducer = (state: any, action: any) => {
|
|
switch (action.type) {
|
|
case actions.SET_REDIRECT_LOCATION:
|
|
return { ...state, redirectLocation: action.pathname };
|
|
default:
|
|
return state;
|
|
}
|
|
};
|
|
|
|
export const RoutingContext = createContext<InitialStateType>(initialState);
|
|
|
|
const RoutingProvider = ({ children }: Props) => {
|
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
|
|
const value = {
|
|
redirectLocation: state.redirectLocation,
|
|
setRedirectLocation: (pathname: string | null) => {
|
|
dispatch({ type: actions.SET_REDIRECT_LOCATION, pathname });
|
|
},
|
|
};
|
|
|
|
return (
|
|
<RoutingContext.Provider value={value}>{children}</RoutingContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default RoutingProvider;
|