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

feat: add Synchronization calendar settings #4111

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -6,7 +6,7 @@ export enum CoreObjectNameSingular {
Blocklist = 'blocklist',
Comment = 'comment',
Company = 'company',
ConenctedAccount = 'conenctedAccount',
ConnectedAccount = 'connectedAccount',
Favorite = 'favorite',
Message = 'message',
MessageChannel = 'messageChannel',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useRecoilValue } from 'recoil';

import { ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { SettingsAccountsListEmptyStateCard } from '@/settings/accounts/components/SettingsAccountsListEmptyStateCard';
import { SettingsAccountsListSkeletonCard } from '@/settings/accounts/components/SettingsAccountsListSkeletonCard';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section';

export const SettingsAccountsCalendarSettingsSection = () => {
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);

const { records: accounts, loading } = useFindManyRecords<ConnectedAccount>({
objectNameSingular: CoreObjectNameSingular.ConnectedAccount,
filter: {
accountOwnerId: {
eq: currentWorkspaceMember?.id,
},
},
});

return (
<Section>
<H2Title
title="Calendar settings"
description="Sync your calendars and set your preferences"
/>

{loading ? (
<SettingsAccountsListSkeletonCard />
) : !accounts.length ? (
<SettingsAccountsListEmptyStateCard />
) : null}
</Section>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ const StyledCardMedia = styled.div`
width: ${({ theme }) => theme.spacing(6)};
`;

export { StyledCardMedia as SettingsAccountsInboxSettingsCardMedia };
export { StyledCardMedia as SettingsAccountsCardMedia };
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section';

import { SettingsAccountsCard } from './SettingsAccountsCard';
import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard';
import { SettingsAccountsListEmptyStateCard } from './SettingsAccountsListEmptyStateCard';

export const SettingsAccountsConnectedAccountsSection = ({
accounts,
Expand All @@ -30,7 +30,7 @@ export const SettingsAccountsConnectedAccountsSection = ({
onAccountRemove={handleAccountRemove}
/>
) : (
<SettingsAccountsEmptyStateCard />
<SettingsAccountsListEmptyStateCard />
)}
</Section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { useRecoilValue } from 'recoil';
import { ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { MessageChannel } from '@/accounts/types/MessageChannel';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { SettingsAccountEmailsSkeletonCard } from '@/settings/accounts/components/SettingsAccountEmailsSkeletonCard';
import { SettingsAccountsEmailsCard } from '@/settings/accounts/components/SettingsAccountsEmailsCard';
import { SettingsAccountsListEmptyStateCard } from '@/settings/accounts/components/SettingsAccountsListEmptyStateCard';
import { SettingsAccountsListSkeletonCard } from '@/settings/accounts/components/SettingsAccountsListSkeletonCard';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section';

import { SettingsAccountsEmailsCard } from './SettingsAccountsEmailsCard';
import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard';

export const SettingsAccountsEmailsSyncSection = () => {
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);

const { records: accounts, loading: accountsLoading } =
useFindManyRecords<ConnectedAccount>({
objectNameSingular: 'connectedAccount',
objectNameSingular: CoreObjectNameSingular.ConnectedAccount,
filter: {
accountOwnerId: {
eq: currentWorkspaceMember?.id,
Expand Down Expand Up @@ -51,13 +51,13 @@ export const SettingsAccountsEmailsSyncSection = () => {
/>

{loading ? (
<SettingsAccountEmailsSkeletonCard />
<SettingsAccountsListSkeletonCard />
) : accounts.length ? (
<SettingsAccountsEmailsCard
messageChannels={messageChannelsWithSyncedEmails}
/>
) : (
<SettingsAccountsEmptyStateCard />
<SettingsAccountsListEmptyStateCard />
)}
</Section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';

import { MessageChannel } from '@/accounts/types/MessageChannel';
import { SettingsAccountsInboxSettingsCardMedia } from '@/settings/accounts/components/SettingsAccountsInboxSettingsCardMedia';
import { SettingsAccountsCardMedia } from '@/settings/accounts/components/SettingsAccountsCardMedia';
import { IconUser } from '@/ui/display/icon';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Toggle } from '@/ui/input/components/Toggle';
Expand Down Expand Up @@ -42,9 +42,9 @@ export const SettingsAccountsInboxSettingsContactAutoCreateSection = ({
/>
<Card>
<StyledCardContent>
<SettingsAccountsInboxSettingsCardMedia>
<SettingsAccountsCardMedia>
<IconUser size={theme.icon.size.sm} stroke={theme.icon.stroke.lg} />
</SettingsAccountsInboxSettingsCardMedia>
</SettingsAccountsCardMedia>
<StyledTitle>Auto-creation</StyledTitle>
<Toggle
value={messageChannel.isContactAutoCreationEnabled}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled';

import { SettingsAccountsInboxSettingsCardMedia } from '@/settings/accounts/components/SettingsAccountsInboxSettingsCardMedia';
import { SettingsAccountsCardMedia } from '@/settings/accounts/components/SettingsAccountsCardMedia';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Radio } from '@/ui/input/components/Radio';
import { Card } from '@/ui/layout/card/components/Card';
Expand Down Expand Up @@ -29,7 +29,7 @@ const StyledCardContent = styled(CardContent)`
}
`;

const StyledCardMedia = styled(SettingsAccountsInboxSettingsCardMedia)`
const StyledCardMedia = styled(SettingsAccountsCardMedia)`
align-items: stretch;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const StyledBody = styled(CardContent)`
justify-content: center;
`;

type SettingsAccountsEmptyStateCardProps = {
type SettingsAccountsListEmptyStateCardProps = {
label?: string;
};

export const SettingsAccountsEmptyStateCard = ({
export const SettingsAccountsListEmptyStateCard = ({
label,
}: SettingsAccountsEmptyStateCardProps) => {
}: SettingsAccountsListEmptyStateCardProps) => {
const [generateTransientToken] = useGenerateTransientTokenMutation();

const handleGmailLogin = useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const StyledCard = styled(Card)`
height: 40px;
`;

export const SettingsAccountEmailsSkeletonCard = () => <StyledCard />;
export { StyledCard as SettingsAccountsListSkeletonCard };
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';

import { MessageChannel } from '@/accounts/types/MessageChannel';
import { SettingsAccountsInboxSettingsCardMedia } from '@/settings/accounts/components/SettingsAccountsInboxSettingsCardMedia';
import { SettingsAccountsCardMedia } from '@/settings/accounts/components/SettingsAccountsCardMedia';
import { IconRefresh } from '@/ui/display/icon';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Toggle } from '@/ui/input/components/Toggle';
Expand All @@ -23,33 +22,34 @@ const StyledTitle = styled.span`
margin-right: auto;
`;

type SettingsAccountsInboxSettingsSynchronizationSectionProps = {
messageChannel: MessageChannel;
type SettingsAccountsSynchronizationSectionProps = {
cardTitle: string;
description: string;
isSynced: boolean;
onToggle: (value: boolean) => void;
};

export const SettingsAccountsInboxSettingsSynchronizationSection = ({
messageChannel,
export const SettingsAccountsSynchronizationSection = ({
cardTitle,
description,
isSynced,
onToggle,
}: SettingsAccountsInboxSettingsSynchronizationSectionProps) => {
}: SettingsAccountsSynchronizationSectionProps) => {
const theme = useTheme();

return (
<Section>
<H2Title
title="Synchronization"
description="Past and future emails will automatically be synced to this workspace"
/>
<H2Title title="Synchronization" description={description} />
<Card>
<StyledCardContent>
<SettingsAccountsInboxSettingsCardMedia>
<SettingsAccountsCardMedia>
<IconRefresh
size={theme.icon.size.sm}
stroke={theme.icon.stroke.lg}
/>
</SettingsAccountsInboxSettingsCardMedia>
<StyledTitle>Sync emails</StyledTitle>
<Toggle value={messageChannel.isSynced} onChange={onToggle} />
</SettingsAccountsCardMedia>
<StyledTitle>{cardTitle}</StyledTitle>
<Toggle value={isSynced} onChange={onToggle} />
</StyledCardContent>
</Card>
</Section>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { SettingsAccountsListEmptyStateCard } from '@/settings/accounts/components/SettingsAccountsListEmptyStateCard';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section';

import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard';

export const SettingsNewAccountSection = () => {
return (
<Section>
<H2Title
title="New account"
description="Connect a new account to your workspace"
/>
<SettingsAccountsEmptyStateCard label="Connect a Google account" />
<SettingsAccountsListEmptyStateCard label="Connect a Google account" />
</Section>
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SettingsAccountsCalendarSettingsSection } from '@/settings/accounts/components/SettingsAccountsCalendarSettingsSection';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
import { SettingsPath } from '@/types/SettingsPath';
Expand All @@ -17,6 +18,7 @@ export const SettingsAccountsCalendars = () => (
{ children: 'Calendars' },
]}
/>
<SettingsAccountsCalendarSettingsSection />
</SettingsPageContainer>
</SubMenuTopBarContainer>
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useParams } from 'react-router-dom';

import { SettingsAccountsSynchronizationSection } from '@/settings/accounts/components/SettingsAccountsSynchronizationSection';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
import { SettingsPath } from '@/types/SettingsPath';
Expand Down Expand Up @@ -30,6 +31,12 @@ export const SettingsAccountsCalendarsSettings = () => {
{ children: connectedAccount?.handle || '' },
]}
/>
<SettingsAccountsSynchronizationSection
description="Past and future calendar events will automatically be synced to this workspace"
cardTitle="Sync events"
isSynced={false}
onToggle={() => {}}
/>
</SettingsPageContainer>
</SubMenuTopBarContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ export const SettingsAccountsEmailsInboxSettings = () => {
]}
/>
{/* TODO : discuss the desired sync behaviour */}
{/* <SettingsAccountsInboxSettingsSynchronizationSection
messageChannel={messageChannel}
{/* <SettingsAccountsSynchronizationSection
description="Past and future emails will automatically be synced to this workspace"
cardTitle="Sync emails"
isSynced={!!messageChannel?.isSynced}
onToggle={handleSynchronizationToggle}
/> */}
<SettingsAccountsInboxSettingsVisibilitySection
Expand Down
Loading