action-creators.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. Actions,
  3. ActionSetData,
  4. ActionSetLoading,
  5. ActionMakePrimary,
  6. ActionDeleteEmail,
  7. ActionSetEmailAffiliationBeingEdited,
  8. ActionUpdateAffiliation,
  9. } from '../context/user-email-context'
  10. import { UserEmailData } from '../../../../../types/user-email'
  11. import { Nullable } from '../../../../../types/utils'
  12. import { Affiliation } from '../../../../../types/affiliation'
  13. export const setData = (data: UserEmailData[]): ActionSetData => ({
  14. type: Actions.SET_DATA,
  15. payload: data,
  16. })
  17. export const setLoading = (flag: boolean): ActionSetLoading => ({
  18. type: Actions.SET_LOADING_STATE,
  19. payload: flag,
  20. })
  21. export const makePrimary = (
  22. email: UserEmailData['email']
  23. ): ActionMakePrimary => ({
  24. type: Actions.MAKE_PRIMARY,
  25. payload: email,
  26. })
  27. export const deleteEmail = (
  28. email: UserEmailData['email']
  29. ): ActionDeleteEmail => ({
  30. type: Actions.DELETE_EMAIL,
  31. payload: email,
  32. })
  33. export const setEmailAffiliationBeingEdited = (
  34. email: Nullable<UserEmailData['email']>
  35. ): ActionSetEmailAffiliationBeingEdited => ({
  36. type: Actions.SET_EMAIL_AFFILIATION_BEING_EDITED,
  37. payload: email,
  38. })
  39. export const updateAffiliation = (
  40. email: UserEmailData['email'],
  41. role: Affiliation['role'],
  42. department: Affiliation['department']
  43. ): ActionUpdateAffiliation => ({
  44. type: Actions.UPDATE_AFFILIATION,
  45. payload: { email, role, department },
  46. })