Skip to content

Commit

Permalink
feat: add Display calendar settings
Browse files Browse the repository at this point in the history
Closes #4068
  • Loading branch information
thaisguigon committed Feb 23, 2024
1 parent 099177e commit b5bb76e
Show file tree
Hide file tree
Showing 16 changed files with 926 additions and 82 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"danger-plugin-todos": "^1.3.1",
"dataloader": "^2.2.2",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
"debounce": "^2.0.0",
"deep-equal": "^2.2.2",
"docusaurus-node-polyfills": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { SettingsAccountsListCard } from '@/settings/accounts/components/Setting
import { SettingsAccountsSynchronizationStatus } from '@/settings/accounts/components/SettingsAccountsSynchronizationStatus';
import { IconChevronRight } from '@/ui/display/icon';
import { IconGoogleCalendar } from '@/ui/display/icon/components/IconGoogleCalendar';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Section } from '@/ui/layout/section/components/Section';
import { mockedConnectedAccounts } from '~/testing/mock-data/accounts';

const StyledRowRightContainer = styled.div`
Expand All @@ -21,7 +19,7 @@ const StyledRowRightContainer = styled.div`
gap: ${({ theme }) => theme.spacing(1)};
`;

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

Expand All @@ -35,25 +33,19 @@ export const SettingsAccountsCalendarSettingsSection = () => {
});

return (
<Section>
<H2Title
title="Calendar settings"
description="Sync your calendars and set your preferences"
/>
<SettingsAccountsListCard
accounts={mockedConnectedAccounts}
isLoading={loading}
onRowClick={(account) =>
navigate(`/settings/accounts/calendars/${account.id}`)
}
RowIcon={IconGoogleCalendar}
RowRightComponent={({ account: _account }) => (
<StyledRowRightContainer>
<SettingsAccountsSynchronizationStatus synced />
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRowRightContainer>
)}
/>
</Section>
<SettingsAccountsListCard
accounts={mockedConnectedAccounts}
isLoading={loading}
onRowClick={(account) =>
navigate(`/settings/accounts/calendars/${account.id}`)
}
RowIcon={IconGoogleCalendar}
RowRightComponent={({ account: _account }) => (
<StyledRowRightContainer>
<SettingsAccountsSynchronizationStatus synced />
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRowRightContainer>
)}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useState } from 'react';
import styled from '@emotion/styled';
import { formatInTimeZone } from 'date-fns-tz';

import { SettingsAccountsCalendarTimeZoneSelect } from '@/settings/accounts/components/SettingsAccountsCalendarTimeZoneSelect';
import { detectTimeZone } from '@/settings/accounts/utils/detectTimeZone';
import { Select } from '@/ui/input/components/Select';

const StyledContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(4)};
`;

export const SettingsAccountsCalendarDisplaySettings = () => {
// TODO: use the user's saved time zone. If undefined, default it with the user's detected time zone.
const [timeZone, setTimeZone] = useState(detectTimeZone());

// TODO: use the user's saved time format.
const [timeFormat, setTimeFormat] = useState<12 | 24>(24);

return (
<StyledContainer>
<SettingsAccountsCalendarTimeZoneSelect
value={timeZone}
onChange={setTimeZone}
/>
<Select
dropdownId="settings-accounts-calendar-time-format"
label="Format"
fullWidth
value={timeFormat}
options={[
{
label: formatInTimeZone(Date.now(), timeZone, 'HH:mm'),
value: 24,
},
{
label: formatInTimeZone(Date.now(), timeZone, 'h:mm aa'),
value: 12,
},
]}
onChange={setTimeFormat}
/>
</StyledContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { availableTimeZoneOptions } from '@/settings/accounts/constants/timeZoneSelectOptions';
import { detectTimeZone } from '@/settings/accounts/utils/detectTimeZone';
import { findAvailableTimeZoneOption } from '@/settings/accounts/utils/findAvailableTimeZoneOption';
import { Select } from '@/ui/input/components/Select';

type SettingsAccountsCalendarTimeZoneSelectProps = {
value?: string;
onChange: (nextValue: string) => void;
};

export const SettingsAccountsCalendarTimeZoneSelect = ({
value = detectTimeZone(),
onChange,
}: SettingsAccountsCalendarTimeZoneSelectProps) => (
<Select
dropdownId="settings-accounts-calendar-time-zone"
dropdownWidth={416}
label="Time zone"
fullWidth
value={findAvailableTimeZoneOption(value)?.value}
options={availableTimeZoneOptions}
onChange={onChange}
withSearchInput
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import { SettingsAccountsListCard } from '@/settings/accounts/components/Setting
import { SettingsAccountsSynchronizationStatus } from '@/settings/accounts/components/SettingsAccountsSynchronizationStatus';
import { IconChevronRight } from '@/ui/display/icon';
import { IconGmail } from '@/ui/display/icon/components/IconGmail';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section';

const StyledRowRightContainer = styled.div`
align-items: center;
display: flex;
gap: ${({ theme }) => theme.spacing(1)};
`;

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

Expand Down Expand Up @@ -53,27 +51,21 @@ export const SettingsAccountsEmailsSyncSection = () => {
);

return (
<Section>
<H2Title
title="Emails sync"
description="Sync your inboxes and set your privacy settings"
/>
<SettingsAccountsListCard
accounts={messageChannelsWithSyncedEmails}
isLoading={accountsLoading || messageChannelsLoading}
onRowClick={(messageChannel) =>
navigate(`/settings/accounts/emails/${messageChannel.id}`)
}
RowIcon={IconGmail}
RowRightComponent={({ account: messageChannel }) => (
<StyledRowRightContainer>
<SettingsAccountsSynchronizationStatus
synced={messageChannel.isSynced}
/>
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRowRightContainer>
)}
/>
</Section>
<SettingsAccountsListCard
accounts={messageChannelsWithSyncedEmails}
isLoading={accountsLoading || messageChannelsLoading}
onRowClick={(messageChannel) =>
navigate(`/settings/accounts/emails/${messageChannel.id}`)
}
RowIcon={IconGmail}
RowRightComponent={({ account: messageChannel }) => (
<StyledRowRightContainer>
<SettingsAccountsSynchronizationStatus
synced={messageChannel.isSynced}
/>
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRowRightContainer>
)}
/>
);
};
Loading

0 comments on commit b5bb76e

Please sign in to comment.