Closes https://github.com/twentyhq/core-team-issues/issues/584 This PR: - Migrates the component state `activeTabIdComponentState` from the deprecated V1 version to V2. - Allows the active tab state to be preserved during navigation inside the side panel and reset when the side panel is closed. - Allows the active tab state to be preserved when we open a record in full page from the side panel https://github.com/user-attachments/assets/f2329d7a-ea15-4bd8-81dc-e98ce11edbd0 https://github.com/user-attachments/assets/474bffd5-29e0-40ba-97f4-fa5e9be34dc2
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import styled from '@emotion/styled';
|
|
import { useRecoilValue } from 'recoil';
|
|
|
|
import { ConnectedAccount } from '@/accounts/types/ConnectedAccount';
|
|
import { MessageChannel } from '@/accounts/types/MessageChannel';
|
|
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
|
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
|
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
|
import { SettingsAccountsMessageChannelDetails } from '@/settings/accounts/components/SettingsAccountsMessageChannelDetails';
|
|
import { SettingsNewAccountSection } from '@/settings/accounts/components/SettingsNewAccountSection';
|
|
import { SETTINGS_ACCOUNT_MESSAGE_CHANNELS_TAB_LIST_COMPONENT_ID } from '@/settings/accounts/constants/SettingsAccountMessageChannelsTabListComponentId';
|
|
import { TabList } from '@/ui/layout/tab/components/TabList';
|
|
import { activeTabIdComponentState } from '@/ui/layout/tab/states/activeTabIdComponentState';
|
|
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
|
import React from 'react';
|
|
|
|
const StyledMessageContainer = styled.div`
|
|
padding-bottom: ${({ theme }) => theme.spacing(6)};
|
|
`;
|
|
|
|
export const SettingsAccountsMessageChannelsContainer = () => {
|
|
const activeTabId = useRecoilComponentValueV2(
|
|
activeTabIdComponentState,
|
|
SETTINGS_ACCOUNT_MESSAGE_CHANNELS_TAB_LIST_COMPONENT_ID,
|
|
);
|
|
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
|
|
|
const { records: accounts } = useFindManyRecords<ConnectedAccount>({
|
|
objectNameSingular: CoreObjectNameSingular.ConnectedAccount,
|
|
filter: {
|
|
accountOwnerId: {
|
|
eq: currentWorkspaceMember?.id,
|
|
},
|
|
},
|
|
});
|
|
|
|
const { records: messageChannels } = useFindManyRecords<
|
|
MessageChannel & {
|
|
connectedAccount: ConnectedAccount;
|
|
}
|
|
>({
|
|
objectNameSingular: CoreObjectNameSingular.MessageChannel,
|
|
filter: {
|
|
connectedAccountId: {
|
|
in: accounts.map((account) => account.id),
|
|
},
|
|
},
|
|
skip: !accounts.length,
|
|
});
|
|
|
|
const tabs = [
|
|
...messageChannels.map((messageChannel) => ({
|
|
id: messageChannel.id,
|
|
title: messageChannel.handle,
|
|
})),
|
|
];
|
|
|
|
if (!messageChannels.length) {
|
|
return <SettingsNewAccountSection />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{tabs.length > 1 && (
|
|
<StyledMessageContainer>
|
|
<TabList
|
|
tabs={tabs}
|
|
componentInstanceId={
|
|
SETTINGS_ACCOUNT_MESSAGE_CHANNELS_TAB_LIST_COMPONENT_ID
|
|
}
|
|
/>
|
|
</StyledMessageContainer>
|
|
)}
|
|
{messageChannels.map((messageChannel) => (
|
|
<React.Fragment key={messageChannel.id}>
|
|
{(messageChannels.length === 1 ||
|
|
messageChannel.id === activeTabId) && (
|
|
<SettingsAccountsMessageChannelDetails
|
|
messageChannel={messageChannel}
|
|
/>
|
|
)}
|
|
</React.Fragment>
|
|
))}
|
|
</>
|
|
);
|
|
};
|