123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { pipe } from "fp-ts/function"
- import * as TE from "fp-ts/TaskEither"
- import { runMutation } from "../GQLClient"
- import { TeamName } from "../types/TeamName"
- import {
- CreateTeamDocument,
- CreateTeamMutation,
- CreateTeamMutationVariables,
- DeleteTeamDocument,
- DeleteTeamMutation,
- DeleteTeamMutationVariables,
- LeaveTeamDocument,
- LeaveTeamMutation,
- LeaveTeamMutationVariables,
- RemoveTeamMemberDocument,
- RemoveTeamMemberMutation,
- RemoveTeamMemberMutationVariables,
- RenameTeamDocument,
- RenameTeamMutation,
- RenameTeamMutationVariables,
- TeamMemberRole,
- UpdateTeamMemberRoleDocument,
- UpdateTeamMemberRoleMutation,
- UpdateTeamMemberRoleMutationVariables,
- } from "../graphql"
- type DeleteTeamErrors =
- | "team/not_required_role"
- | "team/invalid_id"
- | "team/member_not_found"
- | "ea/not_invite_or_admin"
- type LeaveTeamErrors =
- | "team/invalid_id"
- | "team/member_not_found"
- | "ea/not_invite_or_admin"
- type CreateTeamErrors = "team/name_invalid" | "ea/not_invite_or_admin"
- type RenameTeamErrors =
- | "ea/not_invite_or_admin"
- | "team/invalid_id"
- | "team/not_required_role"
- type UpdateTeamMemberRoleErrors =
- | "ea/not_invite_or_admin"
- | "team/invalid_id"
- | "team/not_required_role"
- type RemoveTeamMemberErrors =
- | "ea/not_invite_or_admin"
- | "team/invalid_id"
- | "team/not_required_role"
- export const createTeam = (name: TeamName) =>
- pipe(
- runMutation<
- CreateTeamMutation,
- CreateTeamMutationVariables,
- CreateTeamErrors
- >(CreateTeamDocument, {
- name,
- }),
- TE.map(({ createTeam }) => createTeam)
- )
- export const deleteTeam = (teamID: string) =>
- runMutation<
- DeleteTeamMutation,
- DeleteTeamMutationVariables,
- DeleteTeamErrors
- >(
- DeleteTeamDocument,
- {
- teamID,
- },
- {
- additionalTypenames: ["Team"],
- }
- )
- export const leaveTeam = (teamID: string) =>
- runMutation<LeaveTeamMutation, LeaveTeamMutationVariables, LeaveTeamErrors>(
- LeaveTeamDocument,
- {
- teamID,
- },
- {
- additionalTypenames: ["Team"],
- }
- )
- export const renameTeam = (teamID: string, newName: TeamName) =>
- pipe(
- runMutation<
- RenameTeamMutation,
- RenameTeamMutationVariables,
- RenameTeamErrors
- >(RenameTeamDocument, {
- newName,
- teamID,
- }),
- TE.map(({ renameTeam }) => renameTeam)
- )
- export const updateTeamMemberRole = (
- userUid: string,
- teamID: string,
- newRole: TeamMemberRole
- ) =>
- pipe(
- runMutation<
- UpdateTeamMemberRoleMutation,
- UpdateTeamMemberRoleMutationVariables,
- UpdateTeamMemberRoleErrors
- >(UpdateTeamMemberRoleDocument, {
- newRole,
- userUid,
- teamID,
- }),
- TE.map(({ updateTeamMemberRole }) => updateTeamMemberRole)
- )
- export const removeTeamMember = (userUid: string, teamID: string) =>
- runMutation<
- RemoveTeamMemberMutation,
- RemoveTeamMemberMutationVariables,
- RemoveTeamMemberErrors
- >(RemoveTeamMemberDocument, {
- userUid,
- teamID,
- })
|