Remove account id dependencies from role management
This commit refactor the role management, removing the dependencies on account ids throughout our system. Changes include removing account id related attributes in the roles table schema and functions, modifying seed data and simplifying the role data provider code. This makes role structure more generic and simplifies the role handling process.
This commit is contained in:
@@ -144,10 +144,7 @@ function UpdateInvitationForm({
|
||||
</FormLabel>
|
||||
|
||||
<FormControl>
|
||||
<RolesDataProvider
|
||||
accountId={account}
|
||||
maxRoleHierarchy={userRoleHierarchy}
|
||||
>
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(roles) => (
|
||||
<MembershipRoleSelector
|
||||
roles={roles}
|
||||
|
||||
@@ -52,12 +52,10 @@ const MAX_INVITES = 5;
|
||||
|
||||
export function InviteMembersDialogContainer({
|
||||
accountSlug,
|
||||
accountId,
|
||||
userRoleHierarchy,
|
||||
children,
|
||||
}: React.PropsWithChildren<{
|
||||
accountSlug: string;
|
||||
accountId: string;
|
||||
userRoleHierarchy: number;
|
||||
}>) {
|
||||
const [pending, startTransition] = useTransition();
|
||||
@@ -79,10 +77,7 @@ export function InviteMembersDialogContainer({
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<RolesDataProvider
|
||||
accountId={accountId}
|
||||
maxRoleHierarchy={userRoleHierarchy}
|
||||
>
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(roles) => (
|
||||
<InviteMembersForm
|
||||
pending={pending}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { LoadingOverlay } from '@kit/ui/loading-overlay';
|
||||
|
||||
export function RolesDataProvider(props: {
|
||||
maxRoleHierarchy: number;
|
||||
accountId: string;
|
||||
children: (roles: string[]) => React.ReactNode;
|
||||
}) {
|
||||
const rolesQuery = useFetchRoles(props);
|
||||
@@ -21,7 +20,7 @@ export function RolesDataProvider(props: {
|
||||
return <>{props.children(rolesQuery.data ?? [])}</>;
|
||||
}
|
||||
|
||||
function useFetchRoles(props: { maxRoleHierarchy: number; accountId: string }) {
|
||||
function useFetchRoles(props: { maxRoleHierarchy: number }) {
|
||||
const supabase = useSupabase();
|
||||
|
||||
return useQuery({
|
||||
@@ -31,7 +30,6 @@ function useFetchRoles(props: { maxRoleHierarchy: number; accountId: string }) {
|
||||
.from('roles')
|
||||
.select('name')
|
||||
.gte('hierarchy_level', props.maxRoleHierarchy)
|
||||
.or(`account_id.eq.${props.accountId}, account_id.is.null`)
|
||||
.order('hierarchy_level', { ascending: true });
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -60,10 +60,7 @@ export const UpdateMemberRoleDialog: React.FC<{
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<RolesDataProvider
|
||||
accountId={teamAccountId}
|
||||
maxRoleHierarchy={userRoleHierarchy}
|
||||
>
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(data) => (
|
||||
<UpdateMemberForm
|
||||
setIsOpen={setIsOpen}
|
||||
|
||||
@@ -512,43 +512,18 @@ export type Database = {
|
||||
}
|
||||
roles: {
|
||||
Row: {
|
||||
account_id: string | null
|
||||
hierarchy_level: number
|
||||
name: string
|
||||
}
|
||||
Insert: {
|
||||
account_id?: string | null
|
||||
hierarchy_level: number
|
||||
name: string
|
||||
}
|
||||
Update: {
|
||||
account_id?: string | null
|
||||
hierarchy_level?: number
|
||||
name?: string
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "roles_account_id_fkey"
|
||||
columns: ["account_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "accounts"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "roles_account_id_fkey"
|
||||
columns: ["account_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user_account_workspace"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "roles_account_id_fkey"
|
||||
columns: ["account_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user_accounts"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
Relationships: []
|
||||
}
|
||||
subscription_items: {
|
||||
Row: {
|
||||
|
||||
Reference in New Issue
Block a user