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:
giancarlo
2024-05-10 20:33:05 +07:00
parent 6b3b3cb58b
commit 39e0a229b6
24 changed files with 106 additions and 106 deletions

View File

@@ -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) => {

View File

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

View File

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

View File

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