This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user reducer): add getProfile action
- Loading branch information
1 parent
25f6a39
commit fda0b1a
Showing
7 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Currency } from '@shared/enum/Currency' | ||
|
||
export interface UserProfile { | ||
name: string | ||
defaultCurrency: Currency | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { fetchOrFail } from '@front/domain/store' | ||
|
||
import { getUserProfileRequest } from '../api/getUserProfileRequest' | ||
import { actions as userActions } from '../reducer/user' | ||
|
||
const { getProfile } = userActions.data | ||
|
||
export const getUserProfile = () => { | ||
return fetchOrFail(userActions.fetching, async (dispatch, getApi) => { | ||
const profile = await getUserProfileRequest(getApi())() | ||
dispatch(getProfile(profile)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Api } from '@front/domain/api' | ||
import { UserProfile } from '../actions/UserProfile' | ||
|
||
export const getUserProfileRequest = (api: Api) => (): Promise<UserProfile> => | ||
api.client.get(`user/profile/`).then(response => response.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { State } from '@front/domain/store' | ||
|
||
export const getCurrency = (state: State) => state.user.user.defaultCurrency | ||
export const getCurrency = (state: State) => | ||
state.user.user.profile.defaultCurrency |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters