Closed martmull closed 5 months ago
Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).
To add an InviteTeam onboarding step:
// Path: /packages/twenty-server/src/core/auth/dto/sign-up.input.ts
import { Field, InputType } from '@nestjs/graphql';
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
@InputType()
export class InviteTeamInput {
@Field()
@IsEmail()
@IsNotEmpty()
email: string;
@Field()
@IsString()
@IsNotEmpty()
teamName: string;
@Field({ nullable: true })
@IsOptional()
@IsString()
workspaceInviteHash?: string;
}
// Path: /packages/twenty-server/src/core/auth/resolvers/auth.resolver.ts
import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { InviteTeamInput } from '../dto/invite-team.input';
import { AuthService } from '../services/auth.service';
@Resolver()
export class AuthResolver {
constructor(private readonly authService: AuthService) {}
@Mutation(() => Boolean)
async inviteTeam(@Args('inviteTeamInput') inviteTeamInput: InviteTeamInput): Promise<boolean> {
return this.authService.inviteTeam(inviteTeamInput);
}
}
// Path: /packages/twenty-server/src/core/auth/services/auth.service.ts
import { Injectable } from '@nestjs/common';
import { InviteTeamInput } from '../dto/invite-team.input';
@Injectable()
export class AuthService {
async inviteTeam(inviteTeamInput: InviteTeamInput): Promise<boolean> {
// Logic to invite team
return true;
}
}
// Path: /packages/twenty-front/src/pages/auth/Invite.tsx
import { useInviteTeamMutation } from '~/generated/graphql';
const Invite = () => {
const [inviteTeam] = useInviteTeamMutation();
const handleInviteTeam = async () => {
await inviteTeam({ variables: { inviteTeamInput: { email: 'team@example.com', teamName: 'TeamName' } } });
};
return (
<>
{/* Existing code */}
<MainButton
variant="secondary"
title="Invite Team"
type="button"
onClick={handleInviteTeam}
fullWidth
/>
</>
);
};
// Path: /packages/twenty-front/src/modules/workspace-member/graphql/mutations/inviteTeam.ts
import { gql } from '@apollo/client';
export const INVITE_TEAM = gql`
mutation InviteTeam($inviteTeamInput: InviteTeamInput!) {
inviteTeam(inviteTeamInput: $inviteTeamInput)
}
`;
// Path: /packages/twenty-front/codegen.yml
schema: "http://localhost:4000/graphql"
documents: "src/**/*.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
Run graphql-codegen
to generate the new hooks.
/packages/twenty-front/src/pages/auth/Invite.tsx /packages/twenty-front/src/modules/workspace-member/grapqhql/mutations/addUserToWorkspace.ts /packages/twenty-front/src/modules/workspace/graphql/queries/getWorkspaceFromInviteHash.ts /packages/twenty-front/src/modules/auth/hooks/useAuth.ts /packages/twenty-front/src/effect-components/PageChangeEffect.tsx /packages/twenty-server/src/core/auth/dto/sign-up.input.ts /packages/twenty-server/src/core/auth/strategies/google.auth.strategy.ts