3434 connect settingsaccountsemails to the backend (#3584)
* wip * wip * update sync settings * fix key in map * connect email visibility to backend * finished * improve typing
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
|
||||
import { SettingsAccountsInboxSettingsContactAutoCreateSection } from '@/settings/accounts/components/SettingsAccountsInboxSettingsContactAutoCreationSection';
|
||||
import { SettingsAccountsInboxSettingsSynchronizationSection } from '@/settings/accounts/components/SettingsAccountsInboxSettingsSynchronizationSection';
|
||||
import { MessageChannel } from '@/accounts/types/MessageChannel';
|
||||
import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
|
||||
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
|
||||
import {
|
||||
InboxSettingsVisibilityValue,
|
||||
SettingsAccountsInboxSettingsVisibilitySection,
|
||||
@ -12,24 +13,34 @@ import { AppPath } from '@/types/AppPath';
|
||||
import { IconSettings } from '@/ui/display/icon';
|
||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||
import { mockedAccounts } from '~/testing/mock-data/accounts';
|
||||
|
||||
export const SettingsAccountsEmailsInboxSettings = () => {
|
||||
const navigate = useNavigate();
|
||||
const { accountUuid = '' } = useParams();
|
||||
const account = mockedAccounts.find((account) => account.id === accountUuid);
|
||||
const { accountUuid: messageChannelId = '' } = useParams();
|
||||
|
||||
const { record: messageChannel, loading } = useFindOneRecord<MessageChannel>({
|
||||
objectNameSingular: 'messageChannel',
|
||||
objectRecordId: messageChannelId,
|
||||
});
|
||||
|
||||
const { updateOneRecord } = useUpdateOneRecord({
|
||||
objectNameSingular: 'messageChannel',
|
||||
});
|
||||
|
||||
const handleVisibilityChange = (_value: InboxSettingsVisibilityValue) => {
|
||||
updateOneRecord({
|
||||
idToUpdate: messageChannelId,
|
||||
updateOneRecordInput: {
|
||||
visibility: _value,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!account) navigate(AppPath.NotFound);
|
||||
}, [account, navigate]);
|
||||
if (!loading && !messageChannel) navigate(AppPath.NotFound);
|
||||
}, [loading, messageChannel, navigate]);
|
||||
|
||||
if (!account) return null;
|
||||
|
||||
const handleSynchronizationToggle = (_value: boolean) => {};
|
||||
|
||||
const handleContactAutoCreationToggle = (_value: boolean) => {};
|
||||
|
||||
const handleVisibilityChange = (_value: InboxSettingsVisibilityValue) => {};
|
||||
if (!messageChannel) return null;
|
||||
|
||||
return (
|
||||
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
||||
@ -38,21 +49,23 @@ export const SettingsAccountsEmailsInboxSettings = () => {
|
||||
links={[
|
||||
{ children: 'Accounts', href: '/settings/accounts' },
|
||||
{ children: 'Emails', href: '/settings/accounts/emails' },
|
||||
{ children: account?.handle || '' },
|
||||
{ children: messageChannel?.handle || '' },
|
||||
]}
|
||||
/>
|
||||
<SettingsAccountsInboxSettingsSynchronizationSection
|
||||
account={account}
|
||||
{/* TODO : discuss the desired sync behaviour */}
|
||||
{/* <SettingsAccountsInboxSettingsSynchronizationSection
|
||||
messageChannel={messageChannel}
|
||||
onToggle={handleSynchronizationToggle}
|
||||
/>
|
||||
/> */}
|
||||
<SettingsAccountsInboxSettingsVisibilitySection
|
||||
value={account.visibility}
|
||||
value={messageChannel?.visibility}
|
||||
onChange={handleVisibilityChange}
|
||||
/>
|
||||
<SettingsAccountsInboxSettingsContactAutoCreateSection
|
||||
account={account}
|
||||
{/* TODO : Add this section when the backend will be ready to auto create contacts */}
|
||||
{/* <SettingsAccountsInboxSettingsContactAutoCreateSection
|
||||
messageChannel={messageChannel}
|
||||
onToggle={handleContactAutoCreationToggle}
|
||||
/>
|
||||
/> */}
|
||||
</SettingsPageContainer>
|
||||
</SubMenuTopBarContainer>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user