Skip to content

Commit

Permalink
refactor(products): remove payload
Browse files Browse the repository at this point in the history
is only for actions
  • Loading branch information
aneurysmjs committed Sep 23, 2019
1 parent 0a6bd20 commit 9c83ac0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/app/pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import './Home.scss';

const Home = () => {
const dispatch = useDispatch();
const { isLoading, payload, error }: ProductsType = useSelector(getProducts);
const { isLoading, products, error }: ProductsType = useSelector(getProducts);

useEffect(() => {
dispatch(fetchProducts(`/products`));
Expand All @@ -26,7 +26,7 @@ const Home = () => {
<div className="row">
{ error ? (<span className="home__loader">{ error.message }</span>) : null}
{ isLoading ? (<span className="home__loader"><Spinner /></span>) : null}
{ !isLoading ? payload.map((product) => (
{ !isLoading ? products.map((product) => (
<div
// eslint-disable-next-line no-underscore-dangle
key={product._id}
Expand Down
4 changes: 2 additions & 2 deletions src/app/store/modules/products/reducers/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
const initialState = {
error: null,
isLoading: false,
payload: [],
products: [],
};

export default createReducer<ProductsType, ProductActionType>(initialState, {
Expand All @@ -31,7 +31,7 @@ export default createReducer<ProductsType, ProductActionType>(initialState, {
return {
...state,
isLoading: false,
payload: [...data],
products: [...data],
};
},
[GET_PRODUCTS_FAILURE](state, action) {
Expand Down
15 changes: 8 additions & 7 deletions src/app/store/types/ProductsType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow strict
import type { Action } from 'redux';

import type { Response, ResponseError, Base } from '@/store/types/CommonType';
import type { Response, ResponseError } from '@/store/types/CommonType';

export type ProductType = {
_id: string,
Expand All @@ -14,12 +14,13 @@ export type ProductType = {
shop: string,
};

export type ProductsType = Base<Array<ProductType>>;
// export type ProductsType = {
// isLoading: boolean,
// payload: Array<ProductType>,
// ...$Exact<ResponseError>,
// };
export type ProductsType = {
isLoading: boolean,
products: Array<ProductType>,
error: ?{
message: string
},
};

export type ProductActionType = {
...$Exact<Action<string>>,
Expand Down

0 comments on commit 9c83ac0

Please sign in to comment.