-
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.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './usuarios.actions'; | ||
export * from './usuario.actions'; | ||
|
||
|
||
|
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,24 @@ | ||
import { Action } from '@ngrx/store'; | ||
import { Usuario } from '../../models/usuario.model'; | ||
|
||
export const CARGAR_USUARIO = '[USUARIO] Cargar usuario'; | ||
export const CARGAR_USUARIO_FAIL = '[USUARIO] Cargar usuario FAIL'; | ||
export const CARGAR_USUARIO_SUCCESS = '[USUARIO] Cargar usuario SUCCESS'; | ||
|
||
export class CargarUsuario implements Action { | ||
readonly type = CARGAR_USUARIO; | ||
constructor(public id: string) { } | ||
} | ||
export class CargarUsuarioFail implements Action { | ||
readonly type = CARGAR_USUARIO_FAIL; | ||
constructor(public payload: any) { } | ||
} | ||
export class CargarUsuarioSuccess implements Action { | ||
readonly type = CARGAR_USUARIO_SUCCESS; | ||
constructor(public usuario: Usuario) { } | ||
} | ||
|
||
export type usuarioAcciones = | ||
CargarUsuario | | ||
CargarUsuarioFail | | ||
CargarUsuarioSuccess; |
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 +1,2 @@ | ||
export * from './usuarios.reducer'; | ||
export * from './usuario.reducer'; |
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,49 @@ | ||
import { Usuario } from '../../models/usuario.model'; | ||
import * as fromUsuario from '../actions'; | ||
|
||
export interface UsuarioState { | ||
user: Usuario; | ||
loaded: boolean; | ||
loading: boolean; | ||
error: any; | ||
} | ||
|
||
const initState: UsuarioState = { | ||
user: null, | ||
loaded: false, | ||
loading: false, | ||
error: null | ||
}; | ||
|
||
export function usuarioReducer(state = initState, action: fromUsuario.usuarioAcciones): UsuarioState { | ||
switch (action.type) { | ||
case fromUsuario.CARGAR_USUARIO: | ||
return { | ||
...state, | ||
loading: true, | ||
error: null | ||
}; | ||
case fromUsuario.CARGAR_USUARIO_SUCCESS: | ||
return { | ||
...state, | ||
loading: false, | ||
loaded: true, | ||
user: {...action.usuario} | ||
}; | ||
case fromUsuario.CARGAR_USUARIO_FAIL: | ||
return { | ||
...state, | ||
loading: false, | ||
loaded: false, | ||
user: null, | ||
error: { | ||
status: action.payload.status, | ||
message: action.payload.error, | ||
url: action.payload.url | ||
} | ||
}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|