From 92c38efe2e759074df4e8aa2e104c8382e9ae68e Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Wed, 18 Sep 2024 22:49:15 +0200 Subject: [PATCH] Minor fixes post review --- .gitignore | 1 - .../hooks/useCreateWorkspaceInvitation.ts | 6 ++-- .../hooks/useDeleteWorkspaceInvitation.ts | 4 +-- .../hooks/useResendWorkspaceInvitation.ts | 6 ++-- .../components/WorkspaceInviteTeam.tsx | 8 +++--- ...graphql-query-find-one-resolver.service.ts | 11 ++++++-- .../services/workspace-invitation.service.ts | 28 ++++++------------- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 6411125875a7..f8b0d9f6cdb0 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,3 @@ storybook-static .nyc_output test-results/ -graphql.config.yml diff --git a/packages/twenty-front/src/modules/workspace-invitation/hooks/useCreateWorkspaceInvitation.ts b/packages/twenty-front/src/modules/workspace-invitation/hooks/useCreateWorkspaceInvitation.ts index 31aa2ee6afa1..6894f9b700e4 100644 --- a/packages/twenty-front/src/modules/workspace-invitation/hooks/useCreateWorkspaceInvitation.ts +++ b/packages/twenty-front/src/modules/workspace-invitation/hooks/useCreateWorkspaceInvitation.ts @@ -1,12 +1,12 @@ +import { useSetRecoilState } from 'recoil'; import { useSendInvitationsMutation } from '~/generated/graphql'; -import { useRecoilState } from 'recoil'; -import { workspaceInvitationsState } from '../states/workspaceInvitationsStates'; import { SendInvitationsMutationVariables } from '../../../generated/graphql'; +import { workspaceInvitationsState } from '../states/workspaceInvitationsStates'; export const useCreateWorkspaceInvitation = () => { const [sendInvitationsMutation] = useSendInvitationsMutation(); - const [, setWorkspaceInvitations] = useRecoilState(workspaceInvitationsState); + const setWorkspaceInvitations = useSetRecoilState(workspaceInvitationsState); const sendInvitation = async (emails: SendInvitationsMutationVariables) => { return await sendInvitationsMutation({ diff --git a/packages/twenty-front/src/modules/workspace-invitation/hooks/useDeleteWorkspaceInvitation.ts b/packages/twenty-front/src/modules/workspace-invitation/hooks/useDeleteWorkspaceInvitation.ts index 5df145ff9a21..5731548c1db8 100644 --- a/packages/twenty-front/src/modules/workspace-invitation/hooks/useDeleteWorkspaceInvitation.ts +++ b/packages/twenty-front/src/modules/workspace-invitation/hooks/useDeleteWorkspaceInvitation.ts @@ -1,15 +1,15 @@ +import { useSetRecoilState } from 'recoil'; import { DeleteWorkspaceInvitationMutationVariables, useDeleteWorkspaceInvitationMutation, } from '~/generated/graphql'; -import { useRecoilState } from 'recoil'; import { workspaceInvitationsState } from '../states/workspaceInvitationsStates'; export const useDeleteWorkspaceInvitation = () => { const [deleteWorkspaceInvitationMutation] = useDeleteWorkspaceInvitationMutation(); - const [, setWorkspaceInvitations] = useRecoilState(workspaceInvitationsState); + const setWorkspaceInvitations = useSetRecoilState(workspaceInvitationsState); const deleteWorkspaceInvitation = async ({ appTokenId, diff --git a/packages/twenty-front/src/modules/workspace-invitation/hooks/useResendWorkspaceInvitation.ts b/packages/twenty-front/src/modules/workspace-invitation/hooks/useResendWorkspaceInvitation.ts index 723ec1363410..acda3cffd662 100644 --- a/packages/twenty-front/src/modules/workspace-invitation/hooks/useResendWorkspaceInvitation.ts +++ b/packages/twenty-front/src/modules/workspace-invitation/hooks/useResendWorkspaceInvitation.ts @@ -1,15 +1,15 @@ +import { useSetRecoilState } from 'recoil'; import { - useResendWorkspaceInvitationMutation, ResendWorkspaceInvitationMutationVariables, + useResendWorkspaceInvitationMutation, } from '~/generated/graphql'; -import { useRecoilState } from 'recoil'; import { workspaceInvitationsState } from '../states/workspaceInvitationsStates'; export const useResendWorkspaceInvitation = () => { const [resendWorkspaceInvitationMutation] = useResendWorkspaceInvitationMutation(); - const [, setWorkspaceInvitations] = useRecoilState(workspaceInvitationsState); + const setWorkspaceInvitations = useSetRecoilState(workspaceInvitationsState); const resendInvitation = async ({ appTokenId, diff --git a/packages/twenty-front/src/modules/workspace/components/WorkspaceInviteTeam.tsx b/packages/twenty-front/src/modules/workspace/components/WorkspaceInviteTeam.tsx index b715bdd55017..1f5b277abecc 100644 --- a/packages/twenty-front/src/modules/workspace/components/WorkspaceInviteTeam.tsx +++ b/packages/twenty-front/src/modules/workspace/components/WorkspaceInviteTeam.tsx @@ -1,7 +1,7 @@ -import { useEffect } from 'react'; -import { Controller, useForm } from 'react-hook-form'; import styled from '@emotion/styled'; import { zodResolver } from '@hookform/resolvers/zod'; +import { useEffect } from 'react'; +import { Controller, useForm } from 'react-hook-form'; import { Key } from 'ts-key-enum'; import { IconSend } from 'twenty-ui'; import { z } from 'zod'; @@ -11,13 +11,13 @@ import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; import { Button } from '@/ui/input/button/components/Button'; import { TextInput } from '@/ui/input/components/TextInput'; import { sanitizeEmailList } from '@/workspace/utils/sanitizeEmailList'; -import { useCreateWorkspaceInvitation } from '../../workspace-invitation/hooks/useCreateWorkspaceInvitation'; import { isDefined } from '~/utils/isDefined'; +import { useCreateWorkspaceInvitation } from '../../workspace-invitation/hooks/useCreateWorkspaceInvitation'; const StyledContainer = styled.div` display: flex; flex-direction: row; - padding-bottom: 12px; + padding-bottom: ${({ theme }) => theme.spacing(3)}; `; const StyledLinkContainer = styled.div` diff --git a/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-find-one-resolver.service.ts b/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-find-one-resolver.service.ts index f7bba35bb5d4..4f478565eb7c 100644 --- a/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-find-one-resolver.service.ts +++ b/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-find-one-resolver.service.ts @@ -35,11 +35,15 @@ export class GraphqlQueryFindOneResolverService { ): Promise { const { authContext, objectMetadataItem, info, objectMetadataCollection } = options; - const repository = - await this.twentyORMGlobalManager.getRepositoryForWorkspace( + const dataSource = + await this.twentyORMGlobalManager.getDataSourceForWorkspace( authContext.workspace.id, - objectMetadataItem.nameSingular, ); + + const repository = await dataSource.getRepository( + objectMetadataItem.nameSingular, + ); + const objectMetadataMap = generateObjectMetadataMap( objectMetadataCollection, ); @@ -89,6 +93,7 @@ export class GraphqlQueryFindOneResolverService { relations, limit, authContext, + dataSource, ); } diff --git a/packages/twenty-server/src/engine/core-modules/workspace-invitation/services/workspace-invitation.service.ts b/packages/twenty-server/src/engine/core-modules/workspace-invitation/services/workspace-invitation.service.ts index 9724d0632e6c..7b2cc87c2954 100644 --- a/packages/twenty-server/src/engine/core-modules/workspace-invitation/services/workspace-invitation.service.ts +++ b/packages/twenty-server/src/engine/core-modules/workspace-invitation/services/workspace-invitation.service.ts @@ -1,27 +1,28 @@ +import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { ModuleRef } from '@nestjs/core'; -import { Repository, IsNull } from 'typeorm'; -import { SendInviteLinkEmail } from 'twenty-emails'; import { render } from '@react-email/render'; +import { SendInviteLinkEmail } from 'twenty-emails'; +import { IsNull, Repository } from 'typeorm'; -import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; -import { TokenService } from 'src/engine/core-modules/auth/services/token.service'; import { AppToken, AppTokenType, } from 'src/engine/core-modules/app-token/app-token.entity'; +import { TokenService } from 'src/engine/core-modules/auth/services/token.service'; +import { EmailService } from 'src/engine/core-modules/email/email.service'; +import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service'; +import { OnboardingService } from 'src/engine/core-modules/onboarding/onboarding.service'; import { UserWorkspaceService } from 'src/engine/core-modules/user-workspace/user-workspace.service'; import { User } from 'src/engine/core-modules/user/user.entity'; import { SendInvitationsOutput } from 'src/engine/core-modules/workspace-invitation/dtos/send-invitations.output'; -import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service'; -import { EmailService } from 'src/engine/core-modules/email/email.service'; -import { OnboardingService } from 'src/engine/core-modules/onboarding/onboarding.service'; import { WorkspaceInvitationException, WorkspaceInvitationExceptionCode, } from 'src/engine/core-modules/workspace-invitation/workspace-invitation.exception'; +import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; +@Injectable() // eslint-disable-next-line @nx/workspace-inject-workspace-repository export class WorkspaceInvitationService { private tokenService: TokenService; @@ -32,19 +33,8 @@ export class WorkspaceInvitationService { private readonly appTokenRepository: Repository, private readonly environmentService: EnvironmentService, private readonly emailService: EmailService, - private moduleRef: ModuleRef, ) {} - onModuleInit() { - this.tokenService = this.moduleRef.get(TokenService, { strict: false }); - this.userWorkspaceService = this.moduleRef.get(UserWorkspaceService, { - strict: false, - }); - this.onboardingService = this.moduleRef.get(OnboardingService, { - strict: false, - }); - } - private async getOneWorkspaceInvitation(workspaceId: string, email: string) { return await this.appTokenRepository .createQueryBuilder('appToken')