refactor: refactor create team modal to new system

This commit is contained in:
Andrew Bastin
2021-10-01 22:41:30 +05:30
parent 23de147ca1
commit a628420adb
4 changed files with 100 additions and 55 deletions

View File

@@ -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>(

View File

@@ -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"
)