fix: teams can now be created

This commit is contained in:
Jordan Knott 2021-11-01 20:58:42 -05:00
parent cea99397db
commit 3afd860534
2 changed files with 18 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import NOOP from 'shared/utils/noop';
import theme from 'App/ThemeStyles'; import theme from 'App/ThemeStyles';
import polling from 'shared/utils/polling'; import polling from 'shared/utils/polling';
import { mixin } from '../shared/utils/styles'; import { mixin } from '../shared/utils/styles';
import FormInput from 'shared/components/FormInput';
type CreateTeamData = { name: string }; type CreateTeamData = { name: string };
@ -52,7 +53,7 @@ const CreateTeamForm: React.FC<CreateTeamFormProps> = ({ onCreateTeam }) => {
return ( return (
<CreateTeamFormContainer onSubmit={handleSubmit(createTeam)}> <CreateTeamFormContainer onSubmit={handleSubmit(createTeam)}>
{errors.name && <ErrorText>{errors.name.message}</ErrorText>} {errors.name && <ErrorText>{errors.name.message}</ErrorText>}
<ControlledInput width="100%" label="Team name" variant="alternate" {...register('name')} /> <FormInput width="100%" label="Team name" variant="alternate" {...register('name')} />
<CreateTeamButton type="submit">Create</CreateTeamButton> <CreateTeamButton type="submit">Create</CreateTeamButton>
</CreateTeamFormContainer> </CreateTeamFormContainer>
); );

View File

@ -118,7 +118,22 @@ func (r *mutationResolver) CreateTeam(ctx context.Context, input NewTeam) (*db.T
} }
createdAt := time.Now().UTC() createdAt := time.Now().UTC()
team, err := r.Repository.CreateTeam(ctx, db.CreateTeamParams{OrganizationID: input.OrganizationID, CreatedAt: createdAt, Name: input.Name}) team, err := r.Repository.CreateTeam(ctx, db.CreateTeamParams{OrganizationID: input.OrganizationID, CreatedAt: createdAt, Name: input.Name})
return &team, err if err != nil {
log.WithError(err).Error("while creating team")
return &db.Team{}, nil
}
_, err = r.Repository.CreateTeamMember(ctx, db.CreateTeamMemberParams{
UserID: userID,
TeamID: team.TeamID,
Addeddate: createdAt,
RoleCode: "admin",
})
if err != nil {
log.WithError(err).Error("error while creating team member")
return &db.Team{}, nil
}
return &team, nil
} }
func (r *teamResolver) ID(ctx context.Context, obj *db.Team) (uuid.UUID, error) { func (r *teamResolver) ID(ctx context.Context, obj *db.Team) (uuid.UUID, error) {