Update user authentication and sidebar config
This commit involves improving the user authentication process in the billing and accounts pages for better reliability. It also changes the name of 'organization-account-sidebar.config' to 'team-account-sidebar.config' for improved clarity and consistency.
This commit is contained in:
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
|
||||
|
||||
import { CaretSortIcon, PersonIcon } from '@radix-ui/react-icons';
|
||||
import { Check, Plus } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@kit/ui/avatar';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -59,6 +60,8 @@ export function AccountSelector({
|
||||
selectedAccount ?? PERSONAL_ACCOUNT_SLUG,
|
||||
);
|
||||
|
||||
const { t } = useTranslation('teams');
|
||||
|
||||
useEffect(() => {
|
||||
setValue(selectedAccount ?? PERSONAL_ACCOUNT_SLUG);
|
||||
}, [selectedAccount]);
|
||||
@@ -105,7 +108,7 @@ export function AccountSelector({
|
||||
hidden: collapsed,
|
||||
})}
|
||||
>
|
||||
Personal Account
|
||||
<Trans i18nKey={'teams:personalAccount'} />
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
@@ -137,7 +140,7 @@ export function AccountSelector({
|
||||
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search account..." className="h-9" />
|
||||
<CommandInput placeholder={t('searchAccount')} className="h-9" />
|
||||
|
||||
<CommandList>
|
||||
<CommandGroup>
|
||||
@@ -147,7 +150,9 @@ export function AccountSelector({
|
||||
>
|
||||
<PersonIcon className="mr-2 h-4 w-4" />
|
||||
|
||||
<span>Personal Account</span>
|
||||
<span>
|
||||
<Trans i18nKey={'teams:personalAccount'} />
|
||||
</span>
|
||||
|
||||
<Icon item={PERSONAL_ACCOUNT_SLUG} />
|
||||
</CommandItem>
|
||||
|
||||
@@ -364,7 +364,7 @@ function FactorNameForm(
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className={'flex space-x-2'}>
|
||||
<div className={'flex justify-end space-x-2'}>
|
||||
<Button type={'button'} variant={'ghost'} onClick={props.onCancel}>
|
||||
<Trans i18nKey={'common:cancel'} />
|
||||
</Button>
|
||||
|
||||
@@ -3,16 +3,16 @@ import { useCallback } from 'react';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
||||
import { useUser } from '@kit/supabase/hooks/use-user';
|
||||
|
||||
const queryKey = ['personal-account:data'];
|
||||
|
||||
export function usePersonalAccountData() {
|
||||
const client = useSupabase();
|
||||
const user = useUser();
|
||||
|
||||
const queryFn = async () => {
|
||||
const { data, error } = await client.auth.getSession();
|
||||
|
||||
if (!data.session || error) {
|
||||
if (!user.data?.id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export function usePersonalAccountData() {
|
||||
picture_url
|
||||
`,
|
||||
)
|
||||
.eq('primary_owner_user_id', data.session.user.id)
|
||||
.eq('primary_owner_user_id', user.data?.id)
|
||||
.eq('is_personal_account', true)
|
||||
.single();
|
||||
|
||||
@@ -39,6 +39,7 @@ export function usePersonalAccountData() {
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn,
|
||||
enabled: !!user.data?.id,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class AccountMembersService {
|
||||
.from('accounts_memberships')
|
||||
.delete()
|
||||
.match({
|
||||
id: params.accountId,
|
||||
account_id: params.accountId,
|
||||
user_id: params.userId,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user