Skip to content

Commit

Permalink
[CHORE] Provide types for react-redux hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
simensma-fresh committed Dec 19, 2024
1 parent 72979bd commit b65262f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import * as incidentActions from "../actions/incidentActions";
import * as API from "@mds/common/constants/API";
import { createRequestHeader } from "../utils/RequestHeaders";
import CustomAxios from "../customAxios";
import { IMineIncident } from "@mds/common/interfaces";
import { AppThunk } from "@mds/common/interfaces/appThunk.type";
import { AxiosResponse } from "axios";


export const createMineIncident = (
mine_guid,
payload,
message = "Successfully created incident."
) => (dispatch) => {
): AppThunk<Promise<AxiosResponse<IMineIncident>>> => (dispatch): Promise<AxiosResponse<IMineIncident>> => {
dispatch(request(NetworkReducerTypes.CREATE_MINE_INCIDENT));
dispatch(showLoading("modal"));
return CustomAxios()
Expand Down
13 changes: 13 additions & 0 deletions services/common/src/redux/rootState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { sharedReducer } from "@mds/common/redux/reducers/rootReducerShared";
import { configureStore } from "@reduxjs/toolkit";
import { loadingBarReducer } from "react-redux-loading-bar";

import type { TypedUseSelectorHook } from 'react-redux'
import { useDispatch, useSelector, useStore } from 'react-redux'

export const getStore = (preloadedState = {}) =>
configureStore({
reducer: {
Expand All @@ -14,6 +17,16 @@ export const getStore = (preloadedState = {}) =>

export const store = getStore();

// Provide typed versions for global redux functions
type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;
export type AppStore = typeof store;

// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch: () => AppDispatch = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
export const useAppStore: () => AppStore = useStore;


export { RootState };
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
fetchMineIncident,
updateMineIncident,
} from "@mds/common/redux/actionCreators/incidentActionCreator";
import { clearMineIncident } from "@mds/common/redux/actions/incidentActions";
import * as Strings from "@mds/common/constants/strings";
import * as FORM from "@/constants/forms";
import IncidentForm from "@/components/Forms/incidents/IncidentForm";
import ScrollSideMenu from "@mds/common/components/common/ScrollSideMenu";
import * as routes from "@/constants/routes";
import { useAppDispatch } from "@mds/common/redux/rootState";

interface IParams {
mineGuid?: string;
Expand All @@ -25,7 +25,7 @@ interface IParams {
}

export const MineIncident = (props) => {
const dispatch = useDispatch();
const dispatch = useAppDispatch();

const { history } = props;
const params = useParams<IParams>();
Expand Down

0 comments on commit b65262f

Please sign in to comment.