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

Prefill workspace invitation email (#7174) #8826

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useAuth } from '@/auth/hooks/useAuth';
import { authProvidersState } from '@/client-config/states/authProvidersState';
import { billingState } from '@/client-config/states/billingState';
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
import { supportChatState } from '@/client-config/states/supportChatState';

import { email, mocks, password, results, token } from '../__mocks__/useAuth';
Expand Down Expand Up @@ -78,7 +78,9 @@ describe('useAuth', () => {
const icons = useRecoilValue(iconsState);
const authProviders = useRecoilValue(authProvidersState);
const billing = useRecoilValue(billingState);
const isSignInPrefilled = useRecoilValue(isSignInPrefilledState);
const isDeveloperDefaultSignInPrefilled = useRecoilValue(
isDeveloperDefaultSignInPrefilledState,
);
Comment on lines +81 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider using object destructuring with useRecoilValue to improve readability and reduce line count

const supportChat = useRecoilValue(supportChatState);
const isDebugMode = useRecoilValue(isDebugModeState);
return {
Expand All @@ -88,7 +90,7 @@ describe('useAuth', () => {
icons,
authProviders,
billing,
isSignInPrefilled,
isDeveloperDefaultSignInPrefilled,
supportChat,
isDebugMode,
},
Expand Down Expand Up @@ -119,7 +121,7 @@ describe('useAuth', () => {
sso: false,
});
expect(state.billing).toBeNull();
expect(state.isSignInPrefilled).toBe(false);
expect(state.isDeveloperDefaultSignInPrefilled).toBe(false);
expect(state.supportChat).toEqual({
supportDriver: 'none',
supportFrontChatId: null,
Expand Down
11 changes: 7 additions & 4 deletions packages/twenty-front/src/modules/auth/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { billingState } from '@/client-config/states/billingState';
import { captchaProviderState } from '@/client-config/states/captchaProviderState';
import { clientConfigApiStatusState } from '@/client-config/states/clientConfigApiStatusState';
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { supportChatState } from '@/client-config/states/supportChatState';
import { ColorScheme } from '@/workspace-member/types/WorkspaceMember';
import { REACT_APP_SERVER_BASE_URL } from '~/config';
Expand All @@ -32,6 +31,7 @@ import {
import { isDefined } from '~/utils/isDefined';

import { currentWorkspaceMembersState } from '@/auth/states/currentWorkspaceMembersStates';
import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
import { DateFormat } from '@/localization/constants/DateFormat';
import { TimeFormat } from '@/localization/constants/TimeFormat';
import { dateTimeFormatState } from '@/localization/states/dateTimeFormatState';
Expand Down Expand Up @@ -78,8 +78,8 @@ export const useAuth = () => {
.getLoadable(authProvidersState)
.getValue();
const billing = snapshot.getLoadable(billingState).getValue();
const isSignInPrefilled = snapshot
.getLoadable(isSignInPrefilledState)
const isDeveloperDefaultSignInPrefilled = snapshot
.getLoadable(isDeveloperDefaultSignInPrefilledState)
.getValue();
const supportChat = snapshot.getLoadable(supportChatState).getValue();
const isDebugMode = snapshot.getLoadable(isDebugModeState).getValue();
Expand All @@ -96,7 +96,10 @@ export const useAuth = () => {
set(iconsState, iconsValue);
set(authProvidersState, authProvidersValue);
set(billingState, billing);
set(isSignInPrefilledState, isSignInPrefilled);
set(
isDeveloperDefaultSignInPrefilledState,
isDeveloperDefaultSignInPrefilled,
);
set(supportChatState, supportChat);
set(isDebugModeState, isDebugMode);
set(captchaProviderState, captchaProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { useRecoilValue } from 'recoil';
import { z } from 'zod';

import { PASSWORD_REGEX } from '@/auth/utils/passwordRegex';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
import { useSearchParams } from 'react-router-dom';
import { isDefined } from '~/utils/isDefined';

export const validationSchema = z
.object({
Expand All @@ -20,7 +22,12 @@ export const validationSchema = z

export type Form = z.infer<typeof validationSchema>;
export const useSignInUpForm = () => {
const isSignInPrefilled = useRecoilValue(isSignInPrefilledState);
const isDeveloperDefaultSignInPrefilled = useRecoilValue(
isDeveloperDefaultSignInPrefilledState,
);
const [searchParams] = useSearchParams();
const invitationPrefilledEmail = searchParams.get('email');

const form = useForm<Form>({
mode: 'onChange',
defaultValues: {
Expand All @@ -33,10 +40,12 @@ export const useSignInUpForm = () => {
});

useEffect(() => {
if (isSignInPrefilled === true) {
if (isDefined(invitationPrefilledEmail)) {
form.setValue('email', invitationPrefilledEmail);
} else if (isDeveloperDefaultSignInPrefilled === true) {
form.setValue('email', '[email protected]');
form.setValue('password', 'Applecar2025');
}
}, [form, isSignInPrefilled]);
}, [form, isDeveloperDefaultSignInPrefilled, invitationPrefilledEmail]);
return { form: form };
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { chromeExtensionIdState } from '@/client-config/states/chromeExtensionId
import { clientConfigApiStatusState } from '@/client-config/states/clientConfigApiStatusState';
import { isAnalyticsEnabledState } from '@/client-config/states/isAnalyticsEnabledState';
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
import { isSignUpDisabledState } from '@/client-config/states/isSignUpDisabledState';
import { sentryConfigState } from '@/client-config/states/sentryConfigState';
import { supportChatState } from '@/client-config/states/supportChatState';
Expand All @@ -20,7 +20,9 @@ export const ClientConfigProviderEffect = () => {
const setIsDebugMode = useSetRecoilState(isDebugModeState);
const setIsAnalyticsEnabled = useSetRecoilState(isAnalyticsEnabledState);

const setIsSignInPrefilled = useSetRecoilState(isSignInPrefilledState);
const setisDeveloperDefaultSignInPrefilled = useSetRecoilState(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const setisDeveloperDefaultSignInPrefilled = useSetRecoilState(
const setIsDeveloperDefaultSignInPrefilled = useSetRecoilState(

isDeveloperDefaultSignInPrefilledState,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: camelCase naming convention not followed for 'setisDeveloperDefaultSignInPrefilled' - first word should be capitalized

);
const setIsSignUpDisabled = useSetRecoilState(isSignUpDisabledState);

const setBilling = useSetRecoilState(billingState);
Expand Down Expand Up @@ -76,7 +78,7 @@ export const ClientConfigProviderEffect = () => {
});
setIsDebugMode(data?.clientConfig.debugMode);
setIsAnalyticsEnabled(data?.clientConfig.analyticsEnabled);
setIsSignInPrefilled(data?.clientConfig.signInPrefilled);
setisDeveloperDefaultSignInPrefilled(data?.clientConfig.signInPrefilled);
FelixMalfait marked this conversation as resolved.
Show resolved Hide resolved
setIsSignUpDisabled(data?.clientConfig.signUpDisabled);

setBilling(data?.clientConfig.billing);
Expand All @@ -99,7 +101,7 @@ export const ClientConfigProviderEffect = () => {
data,
setAuthProviders,
setIsDebugMode,
setIsSignInPrefilled,
setisDeveloperDefaultSignInPrefilled,
setIsSignUpDisabled,
setSupportChat,
setBilling,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createState } from 'twenty-ui';

export const isDeveloperDefaultSignInPrefilledState = createState<boolean>({
key: 'isDeveloperDefaultSignInPrefilledState',
defaultValue: false,
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 { Button, IconSend } from 'twenty-ui';
import { z } from 'zod';

Expand Down Expand Up @@ -105,12 +104,6 @@ export const WorkspaceInviteTeam = () => {
}
});

const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === Key.Enter) {
submit();
}
};

const { isSubmitSuccessful, errors } = formState;

useEffect(() => {
Expand All @@ -133,7 +126,6 @@ export const WorkspaceInviteTeam = () => {
value={value}
onChange={onChange}
error={error?.message}
onKeyDown={handleKeyDown}
fullWidth
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export class WorkspaceInvitationService {

if (invitation.value.isPersonalInvitation) {
link.searchParams.set('inviteToken', invitation.value.appToken.value);
link.searchParams.set('email', invitation.value.email);
}
Comment on lines 231 to 233
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Consider URL encoding the email parameter value to prevent potential URL injection issues

const emailData = {
link: link.toString(),
Expand Down
Loading