mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-23 12:02:10 +03:00
3233 connect connected accounts settings to backend (#3235)
* connect SettingsAccountsConnectedAccountsSection to backend * get current user
This commit is contained in:
parent
4fddafceed
commit
52d4f8e466
@ -1,8 +1,8 @@
|
||||
import { InboxSettingsVisibilityValue } from '@/settings/accounts/components/SettingsAccountsInboxSettingsVisibilitySection';
|
||||
|
||||
export type Account = {
|
||||
email: string;
|
||||
id: string;
|
||||
handle: string;
|
||||
isSynced?: boolean;
|
||||
uuid: string;
|
||||
visibility: InboxSettingsVisibilityValue;
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ export const SettingsAccountsCard = ({
|
||||
<Card>
|
||||
{accounts.map((account, index) => (
|
||||
<SettingsAccountRow
|
||||
key={account.uuid}
|
||||
key={account.id}
|
||||
LeftIcon={IconGoogle}
|
||||
account={account}
|
||||
rightComponent={
|
||||
|
@ -1,19 +1,33 @@
|
||||
import { useState } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { Account } from '@/accounts/types/Account';
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
|
||||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
||||
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
||||
import { Section } from '@/ui/layout/section/components/Section';
|
||||
import { mockedAccounts } from '~/testing/mock-data/accounts';
|
||||
|
||||
import { SettingsAccountsCard } from './SettingsAccountsCard';
|
||||
import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard';
|
||||
|
||||
export const SettingsAccountsConnectedAccountsSection = () => {
|
||||
const [accounts, setAccounts] = useState(mockedAccounts);
|
||||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
||||
|
||||
const handleAccountRemove = (uuid: string) =>
|
||||
setAccounts((previousAccounts) =>
|
||||
previousAccounts.filter((account) => account.uuid !== uuid),
|
||||
);
|
||||
const accounts = useFindManyRecords<Account>({
|
||||
objectNameSingular: 'connectedAccount',
|
||||
filter: {
|
||||
accountOwnerId: {
|
||||
eq: currentWorkspaceMember?.id,
|
||||
},
|
||||
},
|
||||
}).records;
|
||||
|
||||
const { deleteOneRecord } = useDeleteOneRecord({
|
||||
objectNameSingular: 'connectedAccount',
|
||||
});
|
||||
|
||||
const handleAccountRemove = (idToRemove: string) =>
|
||||
deleteOneRecord(idToRemove);
|
||||
|
||||
return (
|
||||
<Section>
|
||||
@ -21,7 +35,7 @@ export const SettingsAccountsConnectedAccountsSection = () => {
|
||||
title="Connected accounts"
|
||||
description="Manage your internet accounts."
|
||||
/>
|
||||
{accounts.length ? (
|
||||
{accounts?.length ? (
|
||||
<SettingsAccountsCard
|
||||
accounts={accounts}
|
||||
onAccountRemove={handleAccountRemove}
|
||||
|
@ -37,7 +37,7 @@ export const SettingsAccountRow = ({
|
||||
return (
|
||||
<StyledRow onClick={onClick} divider={divider}>
|
||||
<LeftIcon size={theme.icon.size.sm} />
|
||||
{account.email}
|
||||
{account.handle}
|
||||
{rightComponent}
|
||||
</StyledRow>
|
||||
);
|
||||
|
@ -21,7 +21,7 @@ export const SettingsAccountsRowDropdownMenu = ({
|
||||
className,
|
||||
onRemove,
|
||||
}: SettingsAccountsRowDropdownMenuProps) => {
|
||||
const dropdownScopeId = `settings-account-row-${account.uuid}`;
|
||||
const dropdownScopeId = `settings-account-row-${account.id}`;
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { closeDropdown } = useDropdown(dropdownScopeId);
|
||||
@ -42,7 +42,7 @@ export const SettingsAccountsRowDropdownMenu = ({
|
||||
LeftIcon={IconMail}
|
||||
text="Emails settings"
|
||||
onClick={() => {
|
||||
navigate(`/settings/accounts/emails/${account.uuid}`);
|
||||
navigate(`/settings/accounts/emails/${account.id}`);
|
||||
closeDropdown();
|
||||
}}
|
||||
/>
|
||||
@ -52,7 +52,7 @@ export const SettingsAccountsRowDropdownMenu = ({
|
||||
LeftIcon={IconTrash}
|
||||
text="Remove account"
|
||||
onClick={() => {
|
||||
onRemove(account.uuid);
|
||||
onRemove(account.id);
|
||||
closeDropdown();
|
||||
}}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user