fleet/frontend/context/routing.tsx
Martavis Parker cfb1474eb8
Auth Redux Removal (#4924)
* 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
2022-04-07 09:08:00 -07:00

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;