Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

フロントエンドエラー周り修正 #299

Merged
merged 8 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions webapp/frontend/src/actions/actionTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Action } from 'redux';
import { AuthActions } from './authenticationActions';
import { BuyActions } from './buyAction';
import { ErrorActions } from './errorAction';
import { FetchTimelineActions } from './fetchTimelineAction';
import { FetchTransactionActions } from './fetchTransactionsAction';
import { FetchUserItemsActions } from './fetchUserItemsAction';
import { LocationChangeActions } from './locationChangeAction';
import { PostBumpActions } from './postBumpAction';
import { FetchUserPageDataActions } from './fetchUserPageDataAction';
import { PostCompleteActions } from './postCompleteAction';
import { PostItemEditActions } from './postItemEditAction';
import { PostShippedActions } from './postShippedAction';
import { PostShippedDoneActions } from './postShippedDoneAction';
import { RegisterActions } from './registerAction';
import { SellingItemActions } from './sellingItemAction';
import { SettingsActions } from './settingsAction';
import { FetchItemActions } from './fetchItemAction';
import { RouterAction } from 'connected-react-router';
import { SnackBarActions } from './snackBarAction';

type LibraryActions = RouterAction;

export type ActionTypes =
| LibraryActions
| AuthActions
| BuyActions
| ErrorActions
| FetchItemActions
| FetchTimelineActions
| FetchTransactionActions
| FetchUserItemsActions
| FetchUserPageDataActions
| LocationChangeActions
| PostBumpActions
| PostCompleteActions
| PostItemEditActions
| PostShippedActions
| PostShippedDoneActions
| RegisterActions
| SellingItemActions
| SettingsActions
| SnackBarActions;

export interface SnackBarAction<T> extends Action<T> {
snackBarMessage: string;
}
12 changes: 8 additions & 4 deletions webapp/frontend/src/actions/authenticationActions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import AppClient from '../httpClients/appClient';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import { FormErrorState } from '../reducers/formErrorReducer';
import { push } from 'connected-react-router';
import { AnyAction } from 'redux';
import { CallHistoryMethodAction, push } from 'connected-react-router';
import { routes } from '../routes/Route';
import { AppState } from '../index';
import { ErrorRes, LoginRes } from '../types/appApiTypes';
Expand All @@ -11,13 +10,18 @@ import { AppResponseError } from '../errors/AppResponseError';
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAIL = 'LOGIN_FAIL';

type ThunkResult<R> = ThunkAction<R, AppState, undefined, AnyAction>;
export type AuthActions =
| LoginSuccessAction
| LoginFailAction
| CallHistoryMethodAction;

type ThunkResult<R> = ThunkAction<R, AppState, undefined, AuthActions>;

export function postLoginAction(
accountName: string,
password: string,
): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, AnyAction>) => {
return (dispatch: ThunkDispatch<AppState, any, AuthActions>) => {
AppClient.post('/login', {
account_name: accountName,
password: password,
Expand Down
17 changes: 12 additions & 5 deletions webapp/frontend/src/actions/buyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@ import AppClient from '../httpClients/appClient';
import PaymentClient from '../httpClients/paymentClient';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import { FormErrorState } from '../reducers/formErrorReducer';
import { push } from 'connected-react-router';
import { Action, AnyAction } from 'redux';
import { CallHistoryMethodAction, push } from 'connected-react-router';
import { Action } from 'redux';
import { BuyReq, ErrorRes } from '../types/appApiTypes';
import { routes } from '../routes/Route';
import { CardReq, CardRes } from '../types/paymentApiTypes';
import { PaymentResponseError } from '../errors/PaymentResponseError';
import { AppResponseError } from '../errors/AppResponseError';
import { ResponseError } from '../errors/ResponseError';
import { AppState } from '../index';

export const BUY_START = 'BUY_START';
export const BUY_SUCCESS = 'BUY_SUCCESS';
export const BUY_FAIL = 'BUY_FAIL';
export const USING_CARD_FAIL = 'USING_CARD_FAIL';

type State = void;
type ThunkResult<R> = ThunkAction<R, State, undefined, AnyAction>;
export type BuyActions =
| BuyStartAction
| BuySuccessAction
| BuyFailAction
| UsingCardFailAction
| CallHistoryMethodAction;

type ThunkResult<R> = ThunkAction<R, AppState, undefined, BuyActions>;

export function buyItemAction(
itemId: number,
cardNumber: string,
): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, AnyAction>) => {
return (dispatch: ThunkDispatch<AppState, any, BuyActions>) => {
Promise.resolve(() => {
dispatch(buyStartAction());
})
Expand Down
2 changes: 2 additions & 0 deletions webapp/frontend/src/actions/errorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Action } from 'redux';
export const NOT_FOUND_ERROR = 'NOT_FOUND_ERROR';
export const INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR';

export type ErrorActions = NotFoundErrorAction | InternalServerErrorAction;

export interface NotFoundErrorAction extends Action<typeof NOT_FOUND_ERROR> {}

export function notFoundError(): NotFoundErrorAction {
Expand Down
12 changes: 9 additions & 3 deletions webapp/frontend/src/actions/fetchItemAction.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import AppClient from '../httpClients/appClient';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import { Action, AnyAction } from 'redux';
import { Action } from 'redux';
import { ErrorRes, GetItemRes } from '../types/appApiTypes';
import { AppResponseError } from '../errors/AppResponseError';
import { ItemData } from '../dataObjects/item';
import { NotFoundError } from '../errors/NotFoundError';
import { FormErrorState } from '../reducers/formErrorReducer';
import { AppState } from '../index';

export const FETCH_ITEM_START = 'FETCH_ITEM_START';
export const FETCH_ITEM_SUCCESS = 'FETCH_ITEM_SUCCESS';
export const FETCH_ITEM_FAIL = 'FETCH_ITEM_FAIL';

type ThunkResult<R> = ThunkAction<R, void, undefined, AnyAction>;
export type FetchItemActions =
| FetchItemStartAction
| FetchItemSuccessAction
| FetchItemFailAction;

type ThunkResult<R> = ThunkAction<R, AppState, undefined, FetchItemActions>;

export function fetchItemAction(itemId: string): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, AnyAction>) => {
return (dispatch: ThunkDispatch<AppState, any, FetchItemActions>) => {
Promise.resolve()
.then(() => {
dispatch(fetchItemStartAction());
Expand Down
7 changes: 4 additions & 3 deletions webapp/frontend/src/actions/fetchTimelineAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ import { AppResponseError } from '../errors/AppResponseError';
import { TimelineItem } from '../dataObjects/item';
import { NotFoundError } from '../errors/NotFoundError';
import { FormErrorState } from '../reducers/formErrorReducer';
import { AppState } from '../index';

export const FETCH_TIMELINE_START = 'FETCH_TIMELINE_START';
export const FETCH_TIMELINE_SUCCESS = 'FETCH_TIMELINE_SUCCESS';
export const FETCH_TIMELINE_FAIL = 'FETCH_TIMELINE_FAIL';

type Actions =
export type FetchTimelineActions =
| FetchTimelineStartAction
| FetchTimelineSuccessAction
| FetchTimelineFailAction;
type ThunkResult<R> = ThunkAction<R, void, undefined, Actions>;
type ThunkResult<R> = ThunkAction<R, AppState, undefined, FetchTimelineActions>;

export function fetchTimelineAction(
createdAt?: number,
itemId?: number,
categoryId?: number,
): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, Actions>) => {
return (dispatch: ThunkDispatch<AppState, any, FetchTimelineActions>) => {
Promise.resolve()
.then(() => {
dispatch(fetchTimelineStartAction());
Expand Down
12 changes: 9 additions & 3 deletions webapp/frontend/src/actions/fetchTransactionsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@ import { NotFoundError } from '../errors/NotFoundError';
import { TransactionStatus } from '../dataObjects/transaction';
import { ShippingStatus } from '../dataObjects/shipping';
import { FormErrorState } from '../reducers/formErrorReducer';
import { AppState } from '../index';

export const FETCH_TRANSACTIONS_START = 'FETCH_TRANSACTIONS_START';
export const FETCH_TRANSACTIONS_SUCCESS = 'FETCH_TRANSACTIONS_SUCCESS';
export const FETCH_TRANSACTIONS_FAIL = 'FETCH_TRANSACTIONS_FAIL';

type Actions =
export type FetchTransactionActions =
| FetchTransactionsStartAction
| FetchTransactionsSuccessAction
| FetchTransactionsFailAction;
type ThunkResult<R> = ThunkAction<R, void, undefined, Actions>;
type ThunkResult<R> = ThunkAction<
R,
AppState,
undefined,
FetchTransactionActions
>;

export function fetchTransactionsAction(
itemId?: number,
createdAt?: number,
): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, Actions>) => {
return (dispatch: ThunkDispatch<AppState, any, FetchTransactionActions>) => {
Promise.resolve()
.then(() => {
dispatch(fetchTransactionsStartAction());
Expand Down
12 changes: 9 additions & 3 deletions webapp/frontend/src/actions/fetchUserItemsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ import { AppResponseError } from '../errors/AppResponseError';
import { TimelineItem } from '../dataObjects/item';
import { NotFoundError } from '../errors/NotFoundError';
import { FormErrorState } from '../reducers/formErrorReducer';
import { AppState } from '../index';

export const FETCH_USER_ITEMS_START = 'FETCH_USER_ITEMS_START';
export const FETCH_USER_ITEMS_SUCCESS = 'FETCH_USER_ITEMS_SUCCESS';
export const FETCH_USER_ITEMS_FAIL = 'FETCH_USER_ITEMS_FAIL';

type Actions =
export type FetchUserItemsActions =
| FetchUserItemsStartAction
| FetchUserItemsSuccessAction
| FetchUserItemsFailAction;
type ThunkResult<R> = ThunkAction<R, void, undefined, Actions>;
type ThunkResult<R> = ThunkAction<
R,
AppState,
undefined,
FetchUserItemsActions
>;

export function fetchUserItemsAction(
userId: number,
itemId?: number,
createdAt?: number,
): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, Actions>) => {
return (dispatch: ThunkDispatch<AppState, any, FetchUserItemsActions>) => {
Promise.resolve()
.then(() => {
dispatch(fetchUserItemsStartAction());
Expand Down
12 changes: 9 additions & 3 deletions webapp/frontend/src/actions/fetchUserPageDataAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ import { UserData } from '../dataObjects/user';
import { ShippingStatus } from '../dataObjects/shipping';
import { TransactionStatus } from '../dataObjects/transaction';
import { FormErrorState } from '../reducers/formErrorReducer';
import { AppState } from '../index';

export const FETCH_USER_PAGE_DATA_START = 'FETCH_USER_PAGE_DATA_START';
export const FETCH_USER_PAGE_DATA_SUCCESS = 'FETCH_USER_PAGE_DATA_SUCCESS';
export const FETCH_USER_PAGE_DATA_FAIL = 'FETCH_USER_PAGE_DATA_FAIL';

export type Actions =
export type FetchUserPageDataActions =
| FetchUserPageDataStartAction
| FetchUserPageDataSuccessAction
| FetchUserPageDataFailAction;
type ThunkResult<R> = ThunkAction<R, void, undefined, Actions>;
type ThunkResult<R> = ThunkAction<
R,
AppState,
undefined,
FetchUserPageDataActions
>;

async function fetchUserPageData(
userId: number,
Expand Down Expand Up @@ -60,7 +66,7 @@ export function fetchUserPageDataAction(
userId: number,
isMyPage: boolean,
): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, Actions>) => {
return (dispatch: ThunkDispatch<AppState, any, FetchUserPageDataActions>) => {
Promise.resolve()
.then(() => {
dispatch(fetchUserPageDataStartAction());
Expand Down
2 changes: 2 additions & 0 deletions webapp/frontend/src/actions/locationChangeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Action } from 'redux';

export const PATH_NAME_CHANGE = 'PATH_NAME_CHANGE';

export type LocationChangeActions = PathNameChangeAction;

export interface PathNameChangeAction extends Action<typeof PATH_NAME_CHANGE> {}

export const pathNameChangeAction = (): PathNameChangeAction => ({
Expand Down
12 changes: 9 additions & 3 deletions webapp/frontend/src/actions/postBumpAction.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import AppClient from '../httpClients/appClient';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import { FormErrorState } from '../reducers/formErrorReducer';
import { Action, AnyAction } from 'redux';
import { Action } from 'redux';
import { ErrorRes, BumpReq, BumpRes } from '../types/appApiTypes';
import { AppResponseError } from '../errors/AppResponseError';
import { AppState } from '../index';

export const POST_BUMP_START = 'POST_BUMP_START';
export const POST_BUMP_SUCCESS = 'POST_BUMP_SUCCESS';
export const POST_BUMP_FAIL = 'POST_BUMP_FAIL';

type ThunkResult<R> = ThunkAction<R, void, undefined, AnyAction>;
export type PostBumpActions =
| PostBumpStartAction
| PostBumpSuccessAction
| PostBumpFailAction;

type ThunkResult<R> = ThunkAction<R, AppState, undefined, PostBumpActions>;

export function postBumpAction(itemId: number): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, AnyAction>) => {
return (dispatch: ThunkDispatch<AppState, any, PostBumpActions>) => {
Promise.resolve()
.then(() => {
dispatch(postBumpStartAction());
Expand Down
29 changes: 13 additions & 16 deletions webapp/frontend/src/actions/postCompleteAction.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import AppClient from '../httpClients/appClient';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import { FormErrorState } from '../reducers/formErrorReducer';
import { Action, AnyAction } from 'redux';
import { Action } from 'redux';
import { CompleteReq, CompleteRes, ErrorRes } from '../types/appApiTypes';
import { fetchItemAction } from './fetchItemAction';
import { AppResponseError } from '../errors/AppResponseError';
import { AppState } from '../index';
import { SnackBarAction } from './actionTypes';

export const POST_COMPLETE_START = 'POST_COMPLETE_START';
export const POST_COMPLETE_SUCCESS = 'POST_COMPLETE_SUCCESS';
export const POST_COMPLETE_FAIL = 'POST_COMPLETE_FAIL';

type ThunkResult<R> = ThunkAction<R, void, undefined, AnyAction>;
export type PostCompleteActions =
| PostCompleteStartAction
| PostCompleteSuccessAction
| PostCompleteFailAction;
type ThunkResult<R> = ThunkAction<R, AppState, undefined, PostCompleteActions>;

export function postCompleteAction(itemId: number): ThunkResult<void> {
return (dispatch: ThunkDispatch<any, any, AnyAction>) => {
return (dispatch: ThunkDispatch<AppState, any, PostCompleteActions>) => {
Promise.resolve()
.then(() => {
dispatch(postCompleteStartAction());
Expand All @@ -38,11 +43,7 @@ export function postCompleteAction(itemId: number): ThunkResult<void> {
dispatch(fetchItemAction(itemId.toString())); // FIXME: 異常系のハンドリングが取引ページ向けでない
})
.catch((err: Error) => {
dispatch(
postCompleteFailAction({
error: err.message,
}),
);
dispatch(postCompleteFailAction(err.message));
});
};
}
Expand All @@ -66,15 +67,11 @@ export function postCompleteSuccessAction(): PostCompleteSuccessAction {
}

export interface PostCompleteFailAction
extends Action<typeof POST_COMPLETE_FAIL> {
payload: FormErrorState;
}
extends SnackBarAction<typeof POST_COMPLETE_FAIL> {}

export function postCompleteFailAction(
newErrors: FormErrorState,
): PostCompleteFailAction {
export function postCompleteFailAction(error: string): PostCompleteFailAction {
return {
type: POST_COMPLETE_FAIL,
payload: newErrors,
snackBarMessage: error,
};
}
Loading