Centralize all redux types into one place, add overrides for the connect, useSelector and useDispatch functions

This commit is contained in:
ErickSkrauch
2020-07-22 13:01:12 +03:00
parent 96e74cf9bb
commit 5a9c54002d
44 changed files with 199 additions and 141 deletions

View File

@@ -1,10 +1,11 @@
import { Dispatch, Action as ReduxAction } from 'redux';
import { OauthAppResponse } from 'app/services/api/oauth';
import oauth from 'app/services/api/oauth';
import { User } from 'app/components/user';
import { ThunkAction } from 'app/reducers';
import { Action as AppAction } from 'app/types';
import { Apps } from './reducer';
import { State } from './reducer';
interface SetAvailableAction extends ReduxAction {
type: 'apps:setAvailable';
@@ -18,11 +19,11 @@ export function setAppsList(apps: Array<OauthAppResponse>): SetAvailableAction {
};
}
export function getApp(state: { apps: Apps }, clientId: string): OauthAppResponse | null {
export function getApp(state: { apps: State }, clientId: string): OauthAppResponse | null {
return state.apps.available.find((app) => app.clientId === clientId) || null;
}
export function fetchApp(clientId: string): ThunkAction<Promise<void>> {
export function fetchApp(clientId: string): AppAction<Promise<void>> {
return async (dispatch) => {
const app = await oauth.getApp(clientId);
@@ -78,7 +79,7 @@ function createDeleteAppAction(clientId: string): DeleteAppAction {
};
}
export function resetApp(clientId: string, resetSecret: boolean): ThunkAction<Promise<void>> {
export function resetApp(clientId: string, resetSecret: boolean): AppAction<Promise<void>> {
return async (dispatch) => {
const { data: app } = await oauth.reset(clientId, resetSecret);

View File

@@ -2,15 +2,15 @@ import { OauthAppResponse } from 'app/services/api/oauth';
import { Action } from './actions';
export interface Apps {
export interface State {
available: Array<OauthAppResponse>;
}
const defaults: Apps = {
const defaults: State = {
available: [],
};
export default function apps(state: Apps = defaults, action: Action): Apps {
export default function apps(state: State = defaults, action: Action): State {
switch (action.type) {
case 'apps:setAvailable':
return {