3233 connect connected accounts settings to backend (#3235)

* connect SettingsAccountsConnectedAccountsSection to backend

* get current user
This commit is contained in:
bosiraphael 2024-01-04 15:26:55 +01:00 committed by GitHub
parent 4fddafceed
commit 52d4f8e466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 15 deletions

View File

@ -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;
};

View File

@ -46,7 +46,7 @@ export const SettingsAccountsCard = ({
<Card>
{accounts.map((account, index) => (
<SettingsAccountRow
key={account.uuid}
key={account.id}
LeftIcon={IconGoogle}
account={account}
rightComponent={

View File

@ -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}

View File

@ -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>
);

View File

@ -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();
}}
/>