Angular project using NgRx pattern to manage state of a system

users.actions.ts 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { Action } from '@ngrx/store';
  2. import { User } from 'src/app/shared/models/user/user.model';
  3. import { UserActionTypes } from './user.action.types';
  4. /**create actions related to a user*/
  5. // Actios of creating a user form to add user
  6. export class CreateFormUserAddAction implements Action {
  7. type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER;
  8. constructor(public payload: any) {}
  9. }
  10. export class CreateFormUserAddActionSuccess implements Action {
  11. type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER_SUCCESS;
  12. constructor(public payload: any) {}
  13. }
  14. export class CreateFormUserAddActionError implements Action {
  15. type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER_ERROR;
  16. constructor(public payload: string) {}
  17. }
  18. //actions of saving a user form data
  19. export class SaveUserFormAddAction implements Action {
  20. type: UserActionTypes = UserActionTypes.SAVE_USERFORM_ADD;
  21. constructor(public payload: User) {}
  22. }
  23. export class SaveUserFormAddActionSuccess implements Action {
  24. type: UserActionTypes = UserActionTypes.SAVE_USERFORM_ADD_SUCCESS;
  25. constructor(public payload: User) {}
  26. }
  27. export class SaveUserFormAddActionError implements Action {
  28. type: UserActionTypes = UserActionTypes.SAVE_USERFORM_ADD_ERROR;
  29. constructor(public payload: string) {}
  30. }
  31. //get all users actions
  32. export class GetAllUsersAction implements Action {
  33. type: UserActionTypes = UserActionTypes.GET_ALL_USERS;
  34. constructor(public payload: any) {}
  35. }
  36. export class GetAllUsersActionSuccess implements Action {
  37. type: UserActionTypes = UserActionTypes.GET_ALL_USERS_SUCCESS;
  38. constructor(public payload: User[]) {}
  39. }
  40. export class GetAllUsersActionError implements Action {
  41. type: UserActionTypes = UserActionTypes.GET_ALL_USERS_ERROR;
  42. constructor(public payload: string) {}
  43. }
  44. // Actions of creating a user form to edit user
  45. export class CreareFormUserEditAction implements Action {
  46. type: UserActionTypes = UserActionTypes.CREATE_FORM_USER_EDIT;
  47. constructor(public payload: User) {}
  48. }
  49. export class CreareFormUserEditActionSuccess implements Action {
  50. type: UserActionTypes = UserActionTypes.CREATE_FORM_USER_EDIT_SUCCESS;
  51. constructor(public payload: User) {}
  52. }
  53. export class CreareFormUserEditActionActionError implements Action {
  54. type: UserActionTypes = UserActionTypes.CREATE_FORM_USER_EDIT_ERROR;
  55. constructor(public payload: string) {}
  56. }
  57. // action of updating user from user data form
  58. export class UpdateUserFormAction implements Action {
  59. type: UserActionTypes = UserActionTypes.UPDATE_USER_FORM;
  60. constructor(public payload: User) {}
  61. }
  62. export class UpdateUserFormActionSuccess implements Action {
  63. type: UserActionTypes = UserActionTypes.UPDATE_USER_FORM_SUCCESS;
  64. constructor(public payload: User) {}
  65. }
  66. export class UpdateUserFormActionError implements Action {
  67. type: UserActionTypes = UserActionTypes.UPDATE_USER_FORM_ERROR;
  68. constructor(public payload: string) {}
  69. }
  70. // Actions of deleting a user
  71. export class DeleteUsersAction implements Action {
  72. type: UserActionTypes = UserActionTypes.DELETE_A_USER;
  73. constructor(public payload: User) {}
  74. }
  75. export class DeleteUserActionSuccess implements Action {
  76. type: UserActionTypes = UserActionTypes.DELETE_A_USER_SUCCESS;
  77. constructor(public payload: User) {}
  78. }
  79. export class DeleteUserActionError implements Action {
  80. type: UserActionTypes = UserActionTypes.DELETE_A_USER_ERROR;
  81. constructor(public payload: string) {}
  82. }
  83. //Action of loading user's projects
  84. export class GetUser_S_Projects implements Action {
  85. type: UserActionTypes = UserActionTypes.GET_USER_S_PROJECTS;
  86. constructor(public payload: any) {}
  87. }
  88. export class GetUser_S_ProjectsSuccess implements Action {
  89. type: UserActionTypes = UserActionTypes.GET_USER_S_PROJECTS_SUCCESS;
  90. constructor(public payload: any) {}
  91. }
  92. export class GetUser_S_ProjectsError implements Action {
  93. type: UserActionTypes = UserActionTypes.GET_USER_S_PROJECTS_ERROR;
  94. constructor(public payload: string) {}
  95. }
  96. //action of navigating to another component
  97. export class NavigateActionSuccess implements Action {
  98. type: UserActionTypes =
  99. UserActionTypes.NAVIGATE_TO_USER_S_PROJECTS_COMPONENT_SUCCESS;
  100. constructor(public payload: any) {}
  101. }
  102. export type UserActionUnion =
  103. | CreateFormUserAddAction
  104. | CreateFormUserAddActionSuccess
  105. | CreateFormUserAddActionError
  106. | SaveUserFormAddAction
  107. | SaveUserFormAddActionSuccess
  108. | SaveUserFormAddActionError
  109. | GetAllUsersAction
  110. | GetAllUsersActionSuccess
  111. | GetAllUsersActionError
  112. | CreareFormUserEditAction
  113. | CreareFormUserEditActionSuccess
  114. | CreareFormUserEditActionActionError
  115. | UpdateUserFormAction
  116. | UpdateUserFormActionSuccess
  117. | UpdateUserFormActionError
  118. | DeleteUsersAction
  119. | DeleteUserActionSuccess
  120. | DeleteUserActionError
  121. | GetUser_S_Projects
  122. | GetUser_S_ProjectsSuccess
  123. | GetUser_S_ProjectsError
  124. | NavigateActionSuccess;

Powered by TurnKey Linux.