TeamInvitation.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { pipe } from "fp-ts/function"
  2. import * as TE from "fp-ts/TaskEither"
  3. import { runMutation } from "../GQLClient"
  4. import {
  5. AcceptTeamInvitationDocument,
  6. AcceptTeamInvitationMutation,
  7. AcceptTeamInvitationMutationVariables,
  8. CreateTeamInvitationDocument,
  9. CreateTeamInvitationMutation,
  10. CreateTeamInvitationMutationVariables,
  11. RevokeTeamInvitationDocument,
  12. RevokeTeamInvitationMutation,
  13. RevokeTeamInvitationMutationVariables,
  14. TeamMemberRole,
  15. } from "../graphql"
  16. import { Email } from "../types/Email"
  17. export type CreateTeamInvitationErrors =
  18. | "invalid/email"
  19. | "team/invalid_id"
  20. | "team/member_not_found"
  21. | "team_invite/already_member"
  22. | "team_invite/member_has_invite"
  23. type RevokeTeamInvitationErrors =
  24. | "team/not_required_role"
  25. | "team_invite/no_invite_found"
  26. type AcceptTeamInvitationErrors =
  27. | "team_invite/no_invite_found"
  28. | "team_invite/already_member"
  29. | "team_invite/email_do_not_match"
  30. export const createTeamInvitation = (
  31. inviteeEmail: Email,
  32. inviteeRole: TeamMemberRole,
  33. teamID: string
  34. ) =>
  35. pipe(
  36. runMutation<
  37. CreateTeamInvitationMutation,
  38. CreateTeamInvitationMutationVariables,
  39. CreateTeamInvitationErrors
  40. >(CreateTeamInvitationDocument, {
  41. inviteeEmail,
  42. inviteeRole,
  43. teamID,
  44. }),
  45. TE.map((x) => x.createTeamInvitation)
  46. )
  47. export const revokeTeamInvitation = (inviteID: string) =>
  48. runMutation<
  49. RevokeTeamInvitationMutation,
  50. RevokeTeamInvitationMutationVariables,
  51. RevokeTeamInvitationErrors
  52. >(RevokeTeamInvitationDocument, {
  53. inviteID,
  54. })
  55. export const acceptTeamInvitation = (inviteID: string) =>
  56. runMutation<
  57. AcceptTeamInvitationMutation,
  58. AcceptTeamInvitationMutationVariables,
  59. AcceptTeamInvitationErrors
  60. >(AcceptTeamInvitationDocument, {
  61. inviteID,
  62. })