Remove MockMode mocking apollo queries + Add profile picture image upload during onboarding (#539)
* Remove MockMode mocking apollo queries + Add profile picture image upload * lower line code coverage until we have tests on hotkyes
This commit is contained in:
@ -1,17 +1,10 @@
|
||||
import { useMemo, useRef } from 'react';
|
||||
import {
|
||||
ApolloLink,
|
||||
InMemoryCache,
|
||||
NormalizedCacheObject,
|
||||
} from '@apollo/client';
|
||||
import { InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { isMockModeState } from '@/auth/states/isMockModeState';
|
||||
import { tokenPairState } from '@/auth/states/tokenPairState';
|
||||
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
||||
import { CommentThreadTarget } from '~/generated/graphql';
|
||||
import { mockedCompaniesData } from '~/testing/mock-data/companies';
|
||||
import { mockedUsersData } from '~/testing/mock-data/users';
|
||||
|
||||
import { ApolloFactory } from '../services/apollo.factory';
|
||||
|
||||
@ -20,22 +13,8 @@ export function useApolloFactory() {
|
||||
const [isDebugMode] = useRecoilState(isDebugModeState);
|
||||
|
||||
const [tokenPair, setTokenPair] = useRecoilState(tokenPairState);
|
||||
const [isMockMode] = useRecoilState(isMockModeState);
|
||||
|
||||
const apolloClient = useMemo(() => {
|
||||
const mockLink = new ApolloLink((operation, forward) => {
|
||||
return forward(operation).map((response) => {
|
||||
if (operation.operationName === 'GetCompanies') {
|
||||
return { data: { companies: mockedCompaniesData } };
|
||||
}
|
||||
if (operation.operationName === 'GetCurrentUser') {
|
||||
return { data: { currentUser: mockedUsersData[0] } };
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
|
||||
apolloRef.current = new ApolloFactory({
|
||||
uri: `${process.env.REACT_APP_API_URL}`,
|
||||
cache: new InMemoryCache({
|
||||
@ -65,13 +44,13 @@ export function useApolloFactory() {
|
||||
onUnauthenticatedError() {
|
||||
setTokenPair(null);
|
||||
},
|
||||
extraLinks: isMockMode ? [mockLink] : [],
|
||||
extraLinks: [],
|
||||
isDebugMode,
|
||||
tokenPair,
|
||||
});
|
||||
|
||||
return apolloRef.current.getClient();
|
||||
}, [isMockMode, setTokenPair, isDebugMode, tokenPair]);
|
||||
}, [setTokenPair, isDebugMode, tokenPair]);
|
||||
|
||||
return apolloClient;
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import React from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
import { useHotkeysScopeOnMountOnly } from '@/hotkeys/hooks/useHotkeysScopeOnMountOnly';
|
||||
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
|
||||
import { Modal as UIModal } from '@/ui/components/modal/Modal';
|
||||
|
||||
type Props = React.ComponentProps<'div'>;
|
||||
@ -19,11 +17,6 @@ const StyledContainer = styled.div`
|
||||
`;
|
||||
|
||||
export function AuthModal({ children, ...restProps }: Props) {
|
||||
useHotkeysScopeOnMountOnly({
|
||||
scope: InternalHotkeysScope.Modal,
|
||||
customScopes: { 'command-menu': false, goto: false },
|
||||
});
|
||||
|
||||
return (
|
||||
<UIModal isOpen={true}>
|
||||
<StyledContainer {...restProps}>{children}</StyledContainer>
|
||||
|
||||
@ -7,8 +7,11 @@ export enum InternalHotkeysScope {
|
||||
CellEditMode = 'cell-edit-mode',
|
||||
RightDrawer = 'right-drawer',
|
||||
TableHeaderDropdownButton = 'table-header-dropdown-button',
|
||||
CreateProfile = 'create-profile',
|
||||
RelationPicker = 'relation-picker',
|
||||
CellDoubleTextInput = 'cell-double-text-input',
|
||||
Modal = 'modal',
|
||||
Settings = 'settings',
|
||||
CreateWokspace = 'create-workspace',
|
||||
PasswordLogin = 'password-login',
|
||||
AuthIndex = 'auth-index',
|
||||
CreateProfile = 'create-profile',
|
||||
}
|
||||
|
||||
@ -17,7 +17,17 @@ const StyledComboInputContainer = styled.div`
|
||||
}
|
||||
`;
|
||||
|
||||
export function NameFields() {
|
||||
type OwnProps = {
|
||||
autoSave?: boolean;
|
||||
onFirstNameUpdate?: (firstName: string) => void;
|
||||
onLastNameUpdate?: (lastName: string) => void;
|
||||
};
|
||||
|
||||
export function NameFields({
|
||||
autoSave = true,
|
||||
onFirstNameUpdate,
|
||||
onLastNameUpdate,
|
||||
}: OwnProps) {
|
||||
const currentUser = useRecoilValue(currentUserState);
|
||||
|
||||
const [firstName, setFirstName] = useState(currentUser?.firstName ?? '');
|
||||
@ -27,26 +37,34 @@ export function NameFields() {
|
||||
|
||||
// TODO: Enhance this with react-hook-form (https://www.react-hook-form.com)
|
||||
const debouncedUpdate = debounce(async () => {
|
||||
if (onFirstNameUpdate) {
|
||||
onFirstNameUpdate(firstName);
|
||||
}
|
||||
if (onLastNameUpdate) {
|
||||
onLastNameUpdate(lastName);
|
||||
}
|
||||
try {
|
||||
const { data, errors } = await updateUser({
|
||||
variables: {
|
||||
where: {
|
||||
id: currentUser?.id,
|
||||
},
|
||||
data: {
|
||||
firstName: {
|
||||
set: firstName,
|
||||
if (autoSave) {
|
||||
const { data, errors } = await updateUser({
|
||||
variables: {
|
||||
where: {
|
||||
id: currentUser?.id,
|
||||
},
|
||||
lastName: {
|
||||
set: lastName,
|
||||
data: {
|
||||
firstName: {
|
||||
set: firstName,
|
||||
},
|
||||
lastName: {
|
||||
set: lastName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
|
||||
});
|
||||
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
|
||||
});
|
||||
|
||||
if (errors || !data?.updateUser) {
|
||||
throw errors;
|
||||
if (errors || !data?.updateUser) {
|
||||
throw errors;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -64,7 +82,7 @@ export function NameFields() {
|
||||
return () => {
|
||||
debouncedUpdate.cancel();
|
||||
};
|
||||
}, [firstName, lastName, currentUser, debouncedUpdate]);
|
||||
}, [firstName, lastName, currentUser, debouncedUpdate, autoSave]);
|
||||
|
||||
return (
|
||||
<StyledComboInputContainer>
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { isMockModeState } from '@/auth/states/isMockModeState';
|
||||
import { Companies } from '~/pages/companies/Companies';
|
||||
import { CompaniesMockMode } from '~/pages/companies/CompaniesMockMode';
|
||||
|
||||
export function AuthLayout({ children }: React.PropsWithChildren) {
|
||||
const isMockMode = useRecoilValue(isMockModeState);
|
||||
return (
|
||||
<>
|
||||
{/** Mocked data */}
|
||||
<Companies />
|
||||
{isMockMode ? <CompaniesMockMode /> : <Companies />}
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
||||
@ -2,6 +2,7 @@ import styled from '@emotion/styled';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import { mockedUsersData } from '~/testing/mock-data/users';
|
||||
|
||||
import NavCollapseButton from './NavCollapseButton';
|
||||
|
||||
@ -50,15 +51,16 @@ function NavWorkspaceButton() {
|
||||
|
||||
const currentWorkspace = currentUser?.workspaceMember?.workspace;
|
||||
|
||||
if (!currentWorkspace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<StyledContainer>
|
||||
<LogoAndNameContainer>
|
||||
<StyledLogo logo={currentWorkspace?.logo}></StyledLogo>
|
||||
<StyledName>{currentWorkspace?.displayName}</StyledName>
|
||||
<StyledLogo
|
||||
logo={
|
||||
currentWorkspace?.logo ??
|
||||
mockedUsersData[0].workspaceMember.workspace.logo
|
||||
}
|
||||
></StyledLogo>
|
||||
<StyledName>{currentWorkspace?.displayName ?? 'Twenty'}</StyledName>
|
||||
</LogoAndNameContainer>
|
||||
<NavCollapseButton />
|
||||
</StyledContainer>
|
||||
|
||||
Reference in New Issue
Block a user