refactor: refactor create team modal to new system
This commit is contained in:
committed by
liyasthomas
parent
079083d0f2
commit
7ab1bbaf62
@@ -1,12 +1,47 @@
|
||||
import gql from "graphql-tag"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { runMutation } from "../GQLClient"
|
||||
import { TeamName } from "../types/TeamName"
|
||||
|
||||
type DeleteTeamErrors =
|
||||
| "team/not_required_role"
|
||||
| "team/invalid_id"
|
||||
| "team/member_not_found"
|
||||
| "ea/not_invite_or_admin"
|
||||
|
||||
type ExitTeamErrors = "team/invalid_id" | "team/member_not_found"
|
||||
type ExitTeamErrors =
|
||||
| "team/invalid_id"
|
||||
| "team/member_not_found"
|
||||
| "ea/not_invite_or_admin"
|
||||
|
||||
type CreateTeamErrors = "team/name_invalid" | "ea/not_invite_or_admin"
|
||||
|
||||
export const createTeam = (name: TeamName) =>
|
||||
pipe(
|
||||
runMutation<
|
||||
{
|
||||
createTeam: {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
},
|
||||
CreateTeamErrors
|
||||
>(
|
||||
gql`
|
||||
mutation CreateTeam($name: String!) {
|
||||
createTeam(name: $name) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
name,
|
||||
}
|
||||
),
|
||||
TE.map(({ createTeam }) => createTeam)
|
||||
)
|
||||
|
||||
export const deleteTeam = (teamID: string) =>
|
||||
runMutation<void, DeleteTeamErrors>(
|
||||
|
||||
@@ -6,7 +6,7 @@ interface TeamNameBrand {
|
||||
|
||||
export const TeamNameCodec = t.brand(
|
||||
t.string,
|
||||
(x): x is t.Branded<string, TeamNameBrand> => x.length > 6,
|
||||
(x): x is t.Branded<string, TeamNameBrand> => x.trim().length > 6,
|
||||
"TeamName"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user