feat: add Settings/Accounts/Emails Emails Sync section accounts list (#2957)

Closes #2888

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Thaïs 2023-12-13 17:37:12 +01:00 committed by GitHub
parent 9eddaffac4
commit 856b78abc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 191 additions and 70 deletions

View file

@ -1 +1 @@
export type Account = { email: string; uuid: string };
export type Account = { email: string; isSynced?: boolean; uuid: string };

View file

@ -2,8 +2,10 @@ import { useNavigate } from 'react-router-dom';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Account } from '@/accounts/types/Account';
import { Account } from '@/accounts/types/account';
import { SettingsAccountsRowDropdownMenu } from '@/settings/accounts/components/SettingsAccountsRowDropdownMenu';
import { IconAt, IconPlus } from '@/ui/display/icon';
import { IconGoogle } from '@/ui/display/icon/components/IconGoogle';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Card } from '@/ui/layout/card/components/Card';
import { CardFooter } from '@/ui/layout/card/components/CardFooter';
@ -24,6 +26,10 @@ const StyledIconButton = styled(LightIconButton)`
margin-left: auto;
`;
const StyledDropdown = styled(SettingsAccountsRowDropdownMenu)`
margin-left: auto;
`;
type SettingsAccountsCardProps = {
accounts: Account[];
onAccountRemove?: (uuid: string) => void;
@ -41,9 +47,12 @@ export const SettingsAccountsCard = ({
{accounts.map((account, index) => (
<SettingsAccountRow
key={account.uuid}
LeftIcon={IconGoogle}
account={account}
rightComponent={
<StyledDropdown account={account} onRemove={onAccountRemove} />
}
divider={index < accounts.length - 1}
onRemove={onAccountRemove}
/>
))}
<StyledFooter>

View file

@ -0,0 +1,52 @@
import { useNavigate } from 'react-router-dom';
import styled from '@emotion/styled';
import { Account } from '@/accounts/types/account';
import { IconChevronRight } from '@/ui/display/icon';
import { IconGmail } from '@/ui/display/icon/components/IconGmail';
import { Status } from '@/ui/display/status/components/Status';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Card } from '@/ui/layout/card/components/Card';
import { SettingsAccountRow } from './SettingsAccountsRow';
const StyledRightContainer = styled.div`
align-items: center;
display: flex;
gap: ${({ theme }) => theme.spacing(1)};
margin-left: auto;
`;
type SettingsAccountsEmailsCardProps = {
accounts: Account[];
};
export const SettingsAccountsEmailsCard = ({
accounts,
}: SettingsAccountsEmailsCardProps) => {
const navigate = useNavigate();
return (
<Card>
{accounts.map((account, index) => (
<SettingsAccountRow
key={account.uuid}
LeftIcon={IconGmail}
account={account}
rightComponent={
<StyledRightContainer>
{account.isSynced ? (
<Status color="green" text="Synced" weight="medium" />
) : (
<Status color="gray" text="Not Synced" weight="medium" />
)}
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRightContainer>
}
onClick={() => navigate(`/settings/accounts/emails/${account.uuid}`)}
divider={index < accounts.length - 1}
/>
))}
</Card>
);
};

View file

@ -1,6 +1,8 @@
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section';
import { mockedAccounts as accounts } from '~/testing/mock-data/accounts';
import { SettingsAccountsEmailsCard } from './SettingsAccountsEmailsCard';
import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard';
export const SettingsAccountsEmailsSyncSection = () => (
@ -9,6 +11,10 @@ export const SettingsAccountsEmailsSyncSection = () => (
title="Emails sync"
description="Sync your inboxes and set your privacy settings"
/>
<SettingsAccountsEmptyStateCard />
{accounts.length ? (
<SettingsAccountsEmailsCard accounts={accounts} />
) : (
<SettingsAccountsEmptyStateCard />
)}
</Section>
);

View file

@ -1,21 +1,14 @@
import { useNavigate } from 'react-router-dom';
import { ReactNode } from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Account } from '@/accounts/types/Account';
import { IconDotsVertical, IconMail, IconTrash } from '@/ui/display/icon';
import { IconGoogle } from '@/ui/display/icon/components/IconGoogle';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Account } from '@/accounts/types/account';
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { CardContent } from '@/ui/layout/card/components/CardContent';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
const StyledRow = styled(CardContent)`
align-items: center;
cursor: ${({ onClick }) => (onClick ? 'pointer' : 'default')};
display: flex;
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
@ -24,65 +17,28 @@ const StyledRow = styled(CardContent)`
padding-left: ${({ theme }) => theme.spacing(4)};
`;
const StyledDropdown = styled(Dropdown)`
margin-left: auto;
`;
type SettingsAccountRowProps = {
account: Account;
divider?: boolean;
onRemove?: (uuid: string) => void;
LeftIcon: IconComponent;
onClick?: () => void;
rightComponent: ReactNode;
};
export const SettingsAccountRow = ({
account,
divider,
onRemove,
LeftIcon,
onClick,
rightComponent,
}: SettingsAccountRowProps) => {
const dropdownScopeId = `settings-account-row-${account.uuid}`;
const theme = useTheme();
const navigate = useNavigate();
const { closeDropdown } = useDropdown({ dropdownScopeId });
return (
<StyledRow divider={divider}>
<IconGoogle size={theme.icon.size.sm} />
<StyledRow onClick={onClick} divider={divider}>
<LeftIcon size={theme.icon.size.sm} />
{account.email}
<DropdownScope dropdownScopeId={dropdownScopeId}>
<StyledDropdown
dropdownPlacement="right-start"
dropdownHotkeyScope={{ scope: dropdownScopeId }}
clickableComponent={
<LightIconButton Icon={IconDotsVertical} accent="tertiary" />
}
dropdownComponents={
<DropdownMenu>
<DropdownMenuItemsContainer>
<MenuItem
LeftIcon={IconMail}
text="Emails settings"
onClick={() => {
navigate(`/settings/accounts/emails/${account.uuid}`);
closeDropdown();
}}
/>
{!!onRemove && (
<MenuItem
accent="danger"
LeftIcon={IconTrash}
text="Remove account"
onClick={() => {
onRemove(account.uuid);
closeDropdown();
}}
/>
)}
</DropdownMenuItemsContainer>
</DropdownMenu>
}
/>
</DropdownScope>
{rightComponent}
</StyledRow>
);
};

View file

@ -0,0 +1,66 @@
import { useNavigate } from 'react-router-dom';
import { Account } from '@/accounts/types/account';
import { IconDotsVertical, IconMail, IconTrash } from '@/ui/display/icon';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
type SettingsAccountsRowDropdownMenuProps = {
account: Account;
className?: string;
onRemove?: (uuid: string) => void;
};
export const SettingsAccountsRowDropdownMenu = ({
account,
className,
onRemove,
}: SettingsAccountsRowDropdownMenuProps) => {
const dropdownScopeId = `settings-account-row-${account.uuid}`;
const navigate = useNavigate();
const { closeDropdown } = useDropdown({ dropdownScopeId });
return (
<DropdownScope dropdownScopeId={dropdownScopeId}>
<Dropdown
className={className}
dropdownPlacement="right-start"
dropdownHotkeyScope={{ scope: dropdownScopeId }}
clickableComponent={
<LightIconButton Icon={IconDotsVertical} accent="tertiary" />
}
dropdownComponents={
<DropdownMenu>
<DropdownMenuItemsContainer>
<MenuItem
LeftIcon={IconMail}
text="Emails settings"
onClick={() => {
navigate(`/settings/accounts/emails/${account.uuid}`);
closeDropdown();
}}
/>
{!!onRemove && (
<MenuItem
accent="danger"
LeftIcon={IconTrash}
text="Remove account"
onClick={() => {
onRemove(account.uuid);
closeDropdown();
}}
/>
)}
</DropdownMenuItemsContainer>
</DropdownMenu>
}
/>
</DropdownScope>
);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 956 B

View file

@ -0,0 +1,14 @@
import { useTheme } from '@emotion/react';
import IconGmailRaw from '../assets/gmail.svg?react';
interface IconGmailProps {
size?: number;
}
export const IconGmail = (props: IconGmailProps) => {
const theme = useTheme();
const size = props.size ?? theme.icon.size.lg;
return <IconGmailRaw height={size} width={size} />;
};

View file

@ -1,12 +1,12 @@
import { useTheme } from '@emotion/react';
import IconGoogleRaw from '../assets/google-icon.svg?react';
import IconGoogleRaw from '../assets/google.svg?react';
interface IconGoogleProps {
size?: number;
}
export const IconGoogle = (props: IconGoogleProps): JSX.Element => {
export const IconGoogle = (props: IconGoogleProps) => {
const theme = useTheme();
const size = props.size ?? theme.icon.size.lg;

View file

@ -5,6 +5,7 @@ import { themeColorSchema } from '@/ui/theme/utils/themeColorSchema';
const StyledStatus = styled.h3<{
color: ThemeColor;
weight: 'regular' | 'medium';
}>`
align-items: center;
background: ${({ color, theme }) => theme.tag.background[color]};
@ -13,7 +14,7 @@ const StyledStatus = styled.h3<{
display: inline-flex;
font-size: ${({ theme }) => theme.font.size.md};
font-style: normal;
font-weight: ${({ theme }) => theme.font.weight.regular};
font-weight: ${({ theme, weight }) => theme.font.weight[weight]};
gap: ${({ theme }) => theme.spacing(1)};
height: ${({ theme }) => theme.spacing(5)};
margin: 0;
@ -42,13 +43,21 @@ type StatusProps = {
color: ThemeColor;
text: string;
onClick?: () => void;
weight?: 'regular' | 'medium';
};
export const Status = ({ className, color, text, onClick }: StatusProps) => (
export const Status = ({
className,
color,
text,
onClick,
weight = 'regular',
}: StatusProps) => (
<StyledStatus
className={className}
color={themeColorSchema.catch('gray').parse(color)}
onClick={onClick}
weight={weight}
>
<StyledContent>{text}</StyledContent>
</StyledStatus>

View file

@ -11,8 +11,9 @@ const meta: Meta<typeof Card> = {
title: 'UI/Layout/Card/Card',
component: Card,
decorators: [ComponentDecorator],
render: () => (
<Card>
render: (args) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<Card {...args}>
<CardHeader>Lorem ipsum</CardHeader>
<CardContent>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id massa

View file

@ -1,6 +1,14 @@
import { Account } from '@/accounts/types/Account';
import { Account } from '@/accounts/types/account';
export const mockedAccounts: Account[] = [
{ email: 'thomas@twenty.com', uuid: '0794b782-f52e-48c3-977e-b0f57f90de24' },
{ email: 'thomas@twenty.dev', uuid: 'dc66a7ec-56b2-425b-a8e8-26ff0396c3aa' },
{
email: 'thomas@twenty.com',
isSynced: true,
uuid: '0794b782-f52e-48c3-977e-b0f57f90de24',
},
{
email: 'thomas@twenty.dev',
isSynced: false,
uuid: 'dc66a7ec-56b2-425b-a8e8-26ff0396c3aa',
},
];