You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
850 B
25 lines
850 B
import { apiFetch } from 'src/api'
|
|
import { setEntities } from 'src/actions/entities'
|
|
import { startRequest, finishRequest } from 'src/actions/requests'
|
|
import { AppThunkAction, Entity, RequestKey, EntityType } from 'src/types'
|
|
import { normalize } from 'src/utils/normalization'
|
|
|
|
export const fetchUser = (id: string): AppThunkAction => {
|
|
return async dispatch => {
|
|
dispatch(startRequest(RequestKey.FetchUser))
|
|
|
|
try {
|
|
const user = await apiFetch<Entity>({
|
|
path: `/api/user/${id}`
|
|
})
|
|
|
|
const users = normalize([user], EntityType.User)
|
|
|
|
dispatch(setEntities(users.entities))
|
|
dispatch(finishRequest(RequestKey.FetchUser, true))
|
|
} catch (err) {
|
|
dispatch(finishRequest(RequestKey.FetchUser, false))
|
|
throw err
|
|
}
|
|
}
|
|
}
|