Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an InviteTeam onboarding step #5623

Closed
martmull opened this issue May 27, 2024 · 1 comment · Fixed by #5769
Closed

Add an InviteTeam onboarding step #5623

martmull opened this issue May 27, 2024 · 1 comment · Fixed by #5769
Assignees
Labels
🎈master issue master issue

Comments

@martmull
Copy link
Contributor

martmull commented May 27, 2024

@martmull martmull self-assigned this May 27, 2024
Copy link

greptile-apps bot commented May 27, 2024

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:

  1. Update GraphQL Schema: Add a new mutation for inviting a team.
// 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;
}
  1. Create InviteTeam Mutation:
// 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);
  }
}
  1. Implement InviteTeam Service:
// 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;
  }
}
  1. Update Frontend to Handle InviteTeam Step:
// 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
      />
    </>
  );
};
  1. Add GraphQL Mutation:
// 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)
  }
`;
  1. Update GraphQL Codegen:
// 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.

References

/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

Ask Greptile

@martmull martmull added the 🎈master issue master issue label May 28, 2024
@martmull martmull linked a pull request Jun 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎈master issue master issue
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant