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:
Charles Bochet
2023-07-08 15:13:14 -07:00
committed by GitHub
parent 9cd5f7c057
commit b3d0061e0d
16 changed files with 204 additions and 93 deletions

View File

@ -9,12 +9,14 @@ import { SubTitle } from '@/auth/components/ui/SubTitle';
import { Title } from '@/auth/components/ui/Title';
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus';
import { currentUserState } from '@/auth/states/currentUserState';
import { isMockModeState } from '@/auth/states/isMockModeState';
import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus';
import { useHotkeysScopeOnMountOnly } from '@/hotkeys/hooks/useHotkeysScopeOnMountOnly';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { NameFields } from '@/settings/profile/components/NameFields';
import { PictureUploader } from '@/settings/profile/components/PictureUploader';
import { MainButton } from '@/ui/components/buttons/MainButton';
import { ImageInput } from '@/ui/components/inputs/ImageInput';
import { TextInput } from '@/ui/components/inputs/TextInput';
import { SubSectionTitle } from '@/ui/components/section-titles/SubSectionTitle';
import { GET_CURRENT_USER } from '@/users/queries';
import { useUpdateUserMutation } from '~/generated/graphql';
@ -36,16 +38,13 @@ const StyledButtonContainer = styled.div`
width: 200px;
`;
const StyledComboInputContainer = styled.div`
display: flex;
flex-direction: row;
> * + * {
margin-left: ${({ theme }) => theme.spacing(4)};
}
`;
export function CreateProfile() {
useHotkeysScopeOnMountOnly({
scope: InternalHotkeysScope.CreateProfile,
customScopes: { 'command-menu': false, goto: false },
});
const navigate = useNavigate();
const [, setMockMode] = useRecoilState(isMockModeState);
const onboardingStatus = useOnboardingStatus();
const [currentUser] = useRecoilState(currentUserState);
@ -94,15 +93,16 @@ export function CreateProfile() {
() => {
handleCreate();
},
InternalHotkeysScope.Modal,
InternalHotkeysScope.CreateProfile,
[handleCreate],
);
useEffect(() => {
setMockMode(true);
if (onboardingStatus !== OnboardingStatus.OngoingProfileCreation) {
navigate('/');
}
}, [onboardingStatus, navigate]);
}, [onboardingStatus, navigate, setMockMode]);
return (
<>
@ -111,29 +111,18 @@ export function CreateProfile() {
<StyledContentContainer>
<StyledSectionContainer>
<SubSectionTitle title="Picture" />
<ImageInput picture={null} disabled />
<PictureUploader />
</StyledSectionContainer>
<StyledSectionContainer>
<SubSectionTitle
title="Name"
description="Your name as it will be displayed on the app"
/>
<StyledComboInputContainer>
<TextInput
label="First Name"
value={firstName}
placeholder="Tim"
onChange={setFirstName}
fullWidth
/>
<TextInput
label="Last Name"
value={lastName}
placeholder="Cook"
onChange={setLastName}
fullWidth
/>
</StyledComboInputContainer>
<NameFields
autoSave={false}
onFirstNameUpdate={setFirstName}
onLastNameUpdate={setLastName}
/>
</StyledSectionContainer>
</StyledContentContainer>
<StyledButtonContainer>

View File

@ -2,11 +2,14 @@ import { useCallback, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { getOperationName } from '@apollo/client/utilities';
import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
import { SubTitle } from '@/auth/components/ui/SubTitle';
import { Title } from '@/auth/components/ui/Title';
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus';
import { isMockModeState } from '@/auth/states/isMockModeState';
import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus';
import { useHotkeysScopeOnMountOnly } from '@/hotkeys/hooks/useHotkeysScopeOnMountOnly';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { MainButton } from '@/ui/components/buttons/MainButton';
@ -34,6 +37,11 @@ const StyledButtonContainer = styled.div`
`;
export function CreateWorkspace() {
useHotkeysScopeOnMountOnly({
scope: InternalHotkeysScope.CreateWokspace,
customScopes: { 'command-menu': false, goto: false },
});
const [, setMockMode] = useRecoilState(isMockModeState);
const navigate = useNavigate();
const onboardingStatus = useOnboardingStatus();
@ -74,15 +82,16 @@ export function CreateWorkspace() {
() => {
handleCreate();
},
InternalHotkeysScope.Modal,
InternalHotkeysScope.CreateWokspace,
[handleCreate],
);
useEffect(() => {
setMockMode(true);
if (onboardingStatus !== OnboardingStatus.OngoingWorkspaceCreation) {
navigate('/auth/create/profile');
}
}, [onboardingStatus, navigate]);
}, [onboardingStatus, navigate, setMockMode]);
return (
<>

View File

@ -13,6 +13,7 @@ import { authFlowUserEmailState } from '@/auth/states/authFlowUserEmailState';
import { isMockModeState } from '@/auth/states/isMockModeState';
import { authProvidersState } from '@/client-config/states/authProvidersState';
import { isDemoModeState } from '@/client-config/states/isDemoModeState';
import { useHotkeysScopeOnMountOnly } from '@/hotkeys/hooks/useHotkeysScopeOnMountOnly';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { MainButton } from '@/ui/components/buttons/MainButton';
@ -32,6 +33,10 @@ const StyledFooterNote = styled(FooterNote)`
`;
export function Index() {
useHotkeysScopeOnMountOnly({
scope: InternalHotkeysScope.AuthIndex,
customScopes: { 'command-menu': false, goto: false },
});
const navigate = useNavigate();
const theme = useTheme();
const [, setMockMode] = useRecoilState(isMockModeState);
@ -62,7 +67,7 @@ export function Index() {
() => {
onPasswordLoginClick();
},
InternalHotkeysScope.Modal,
InternalHotkeysScope.AuthIndex,
[onPasswordLoginClick],
);

View File

@ -11,6 +11,7 @@ import { useAuth } from '@/auth/hooks/useAuth';
import { authFlowUserEmailState } from '@/auth/states/authFlowUserEmailState';
import { isMockModeState } from '@/auth/states/isMockModeState';
import { isDemoModeState } from '@/client-config/states/isDemoModeState';
import { useHotkeysScopeOnMountOnly } from '@/hotkeys/hooks/useHotkeysScopeOnMountOnly';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { MainButton } from '@/ui/components/buttons/MainButton';
@ -50,6 +51,10 @@ const StyledErrorContainer = styled.div`
`;
export function PasswordLogin() {
useHotkeysScopeOnMountOnly({
scope: InternalHotkeysScope.PasswordLogin,
customScopes: { 'command-menu': false, goto: false },
});
const navigate = useNavigate();
const [isDemoMode] = useRecoilState(isDemoModeState);
@ -81,7 +86,7 @@ export function PasswordLogin() {
() => {
handleLogin();
},
InternalHotkeysScope.Modal,
InternalHotkeysScope.PasswordLogin,
[handleLogin],
);

View File

@ -0,0 +1,40 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { RecoilScope } from '@/recoil-scope/components/RecoilScope';
import { EntityTableActionBar } from '@/ui/components/table/action-bar/EntityTableActionBar';
import { IconBuildingSkyscraper } from '@/ui/icons/index';
import { WithTopBarContainer } from '@/ui/layout/containers/WithTopBarContainer';
import { TableContext } from '@/ui/tables/states/TableContext';
import { TableActionBarButtonCreateCommentThreadCompany } from './table/TableActionBarButtonCreateCommentThreadCompany';
import { TableActionBarButtonDeleteCompanies } from './table/TableActionBarButtonDeleteCompanies';
import { CompanyTableMockMode } from './CompanyTableMockMode';
const StyledTableContainer = styled.div`
display: flex;
width: 100%;
`;
export function CompaniesMockMode() {
const theme = useTheme();
return (
<>
<WithTopBarContainer
title="Companies"
icon={<IconBuildingSkyscraper size={theme.icon.size.md} />}
>
<RecoilScope SpecificContext={TableContext}>
<StyledTableContainer>
<CompanyTableMockMode />
</StyledTableContainer>
<EntityTableActionBar>
<TableActionBarButtonCreateCommentThreadCompany />
<TableActionBarButtonDeleteCompanies />
</EntityTableActionBar>
</RecoilScope>
</WithTopBarContainer>
</>
);
}

View File

@ -0,0 +1,32 @@
import { IconList } from '@tabler/icons-react';
import { EntityTable } from '@/ui/components/table/EntityTable';
import { HooksEntityTable } from '@/ui/components/table/HooksEntityTable';
import { mockedCompaniesData } from '~/testing/mock-data/companies';
import { useCompaniesColumns } from './companies-columns';
import { companiesFilters } from './companies-filters';
import { availableSorts } from './companies-sorts';
export function CompanyTableMockMode() {
const companiesColumns = useCompaniesColumns();
const companies = mockedCompaniesData;
return (
<>
<HooksEntityTable
numberOfColumns={companiesColumns.length}
numberOfRows={companies.length}
availableTableFilters={companiesFilters}
/>
<EntityTable
data={companies}
columns={companiesColumns}
viewName="All Companies"
viewIcon={<IconList size={16} />}
availableSorts={availableSorts}
/>
</>
);
}

View File

@ -1,5 +1,7 @@
import styled from '@emotion/styled';
import { useHotkeysScopeOnMountOnly } from '@/hotkeys/hooks/useHotkeysScopeOnMountOnly';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { EmailField } from '@/settings/profile/components/EmailField';
import { NameFields } from '@/settings/profile/components/NameFields';
import { PictureUploader } from '@/settings/profile/components/PictureUploader';
@ -24,6 +26,11 @@ const StyledSectionContainer = styled.div`
`;
export function SettingsProfile() {
useHotkeysScopeOnMountOnly({
scope: InternalHotkeysScope.Settings,
customScopes: { 'command-menu': true, goto: false },
});
return (
<NoTopBarContainer>
<StyledContainer>

View File

@ -0,0 +1,25 @@
import type { Meta, StoryObj } from '@storybook/react';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { getRenderWrapperForPage } from '~/testing/renderWrappers';
import { SettingsWorkspaceMembers } from '../SettingsWorkspaceMembers';
const meta: Meta<typeof SettingsWorkspaceMembers> = {
title: 'Pages/Settings/SettingsWorkspaceMembers',
component: SettingsWorkspaceMembers,
};
export default meta;
export type Story = StoryObj<typeof SettingsWorkspaceMembers>;
export const Default: Story = {
render: getRenderWrapperForPage(
<SettingsWorkspaceMembers />,
'/settings/workspace-members',
),
parameters: {
msw: graphqlMocks,
},
};