Refactor account handling to improve performance
This commit dates the transition from a global user session to individual account handling based on user ID. The transition was made across several components, notably the account settings, icons, and selector. This change improves performance by reducing unnecessary requests and ensures more accurate data handling. The commit also includes some cleanups and minor fixes spread across different components.
This commit is contained in:
@@ -13,6 +13,8 @@ const features = {
|
||||
|
||||
export function TeamAccountAccountsSelector(params: {
|
||||
selectedAccount: string;
|
||||
userId: string;
|
||||
|
||||
accounts: Array<{
|
||||
label: string | null;
|
||||
value: string | null;
|
||||
@@ -25,6 +27,7 @@ export function TeamAccountAccountsSelector(params: {
|
||||
<AccountSelector
|
||||
selectedAccount={params.selectedAccount}
|
||||
accounts={params.accounts}
|
||||
userId={params.userId}
|
||||
collapsed={false}
|
||||
features={features}
|
||||
onAccountChange={(value) => {
|
||||
|
||||
@@ -41,6 +41,7 @@ const features = {
|
||||
export const TeamAccountLayoutMobileNavigation = (
|
||||
props: React.PropsWithChildren<{
|
||||
account: string;
|
||||
userId: string;
|
||||
accounts: Accounts;
|
||||
}>,
|
||||
) => {
|
||||
@@ -83,7 +84,7 @@ export const TeamAccountLayoutMobileNavigation = (
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent sideOffset={10} className={'w-screen rounded-none'}>
|
||||
<TeamAccountsModal accounts={props.accounts} />
|
||||
<TeamAccountsModal userId={props.userId} accounts={props.accounts} />
|
||||
|
||||
{Links}
|
||||
|
||||
@@ -137,7 +138,7 @@ function SignOutDropdownItem(
|
||||
);
|
||||
}
|
||||
|
||||
function TeamAccountsModal(props: { accounts: Accounts }) {
|
||||
function TeamAccountsModal(props: { accounts: Accounts; userId: string }) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
@@ -165,6 +166,7 @@ function TeamAccountsModal(props: { accounts: Accounts }) {
|
||||
<div className={'py-16'}>
|
||||
<AccountSelector
|
||||
className={'w-full max-w-full'}
|
||||
userId={props.userId}
|
||||
onAccountChange={(value) => {
|
||||
const path = value
|
||||
? pathsConfig.app.accountHome.replace('[account]', value)
|
||||
|
||||
@@ -59,7 +59,8 @@ function SidebarContainer(props: {
|
||||
collapsible?: boolean;
|
||||
user: User;
|
||||
}) {
|
||||
const { account, accounts } = props;
|
||||
const { account, accounts, user } = props;
|
||||
const userId = user.id;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -68,12 +69,13 @@ function SidebarContainer(props: {
|
||||
className={'flex max-w-full items-center justify-between space-x-4'}
|
||||
>
|
||||
<TeamAccountAccountsSelector
|
||||
userId={userId}
|
||||
selectedAccount={account}
|
||||
accounts={accounts}
|
||||
/>
|
||||
|
||||
<TeamAccountNotifications
|
||||
userId={props.user.id}
|
||||
userId={userId}
|
||||
accountId={props.accountId}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -50,6 +50,7 @@ export function TeamAccountNavigationMenu(props: {
|
||||
|
||||
<div className={'flex justify-end space-x-2.5'}>
|
||||
<TeamAccountAccountsSelector
|
||||
userId={user.id}
|
||||
selectedAccount={account.slug}
|
||||
accounts={accounts.map((account) => ({
|
||||
label: account.name,
|
||||
|
||||
Reference in New Issue
Block a user