mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Centralize all redux types into one place, add overrides for the connect, useSelector and useDispatch functions
This commit is contained in:
@@ -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);
|
||||
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user