Implement custom roles and improve permissions logic
The commit refactors the handling of account roles and enhances permissions checks. The account role has been shifted to use a string type, providing the ability to define custom roles. It also introduces the RolesDataProvider component, which stipulates role-related data for different forms and tables. The modification goes further to consider user role hierarchy in permissions checks, offering a more granular access control.
This commit is contained in:
@@ -78,7 +78,7 @@ function buildLazyComponent<
|
||||
|
||||
return (
|
||||
<Suspense fallback={fallback}>
|
||||
{/* @ts-expect-error */}
|
||||
{/* @ts-expect-error: weird TS */}
|
||||
<LoadedComponent
|
||||
onClose={props.onClose}
|
||||
checkoutToken={props.checkoutToken}
|
||||
|
||||
@@ -35,6 +35,7 @@ type AccountInvitationsTableProps = {
|
||||
permissions: {
|
||||
canUpdateInvitation: boolean;
|
||||
canRemoveInvitation: boolean;
|
||||
currentUserRoleHierarchy: number;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -72,6 +73,7 @@ export function AccountInvitationsTable({
|
||||
function useGetColumns(permissions: {
|
||||
canUpdateInvitation: boolean;
|
||||
canRemoveInvitation: boolean;
|
||||
currentUserRoleHierarchy: number;
|
||||
}): ColumnDef<Invitations[0]>[] {
|
||||
const { t } = useTranslation('teams');
|
||||
|
||||
@@ -197,6 +199,7 @@ function ActionsDropdown({
|
||||
setIsOpen={setIsUpdatingRole}
|
||||
invitationId={invitation.id}
|
||||
userRole={invitation.role}
|
||||
userRoleHierarchy={permissions.currentUserRoleHierarchy}
|
||||
/>
|
||||
</If>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
@@ -29,15 +28,17 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { UpdateRoleSchema } from '../../schema/update-role-schema';
|
||||
import { updateInvitationAction } from '../../server/actions/team-invitations-server-actions';
|
||||
import { MembershipRoleSelector } from '../members/membership-role-selector';
|
||||
import { RolesDataProvider } from '../members/roles-data-provider';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
export const UpdateInvitationDialog: React.FC<{
|
||||
isOpen: boolean;
|
||||
setIsOpen: (isOpen: boolean) => void;
|
||||
invitationId: number;
|
||||
userRole: Role;
|
||||
}> = ({ isOpen, setIsOpen, invitationId, userRole }) => {
|
||||
userRoleHierarchy: number;
|
||||
}> = ({ isOpen, setIsOpen, invitationId, userRole, userRoleHierarchy }) => {
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DialogContent>
|
||||
@@ -51,11 +52,16 @@ export const UpdateInvitationDialog: React.FC<{
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<UpdateInvitationForm
|
||||
setIsOpen={setIsOpen}
|
||||
invitationId={invitationId}
|
||||
userRole={userRole}
|
||||
/>
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(roles) => (
|
||||
<UpdateInvitationForm
|
||||
invitationId={invitationId}
|
||||
userRole={userRole}
|
||||
userRoleHierarchy={roles.length}
|
||||
setIsOpen={setIsOpen}
|
||||
/>
|
||||
)}
|
||||
</RolesDataProvider>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
@@ -64,10 +70,12 @@ export const UpdateInvitationDialog: React.FC<{
|
||||
function UpdateInvitationForm({
|
||||
invitationId,
|
||||
userRole,
|
||||
userRoleHierarchy,
|
||||
setIsOpen,
|
||||
}: React.PropsWithChildren<{
|
||||
invitationId: number;
|
||||
userRole: Role;
|
||||
userRoleHierarchy: number;
|
||||
setIsOpen: (isOpen: boolean) => void;
|
||||
}>) {
|
||||
const { t } = useTranslation('teams');
|
||||
@@ -128,11 +136,18 @@ function UpdateInvitationForm({
|
||||
</FormLabel>
|
||||
|
||||
<FormControl>
|
||||
<MembershipRoleSelector
|
||||
currentUserRole={userRole}
|
||||
value={field.value}
|
||||
onChange={(newRole) => form.setValue('role', newRole)}
|
||||
/>
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(roles) => (
|
||||
<MembershipRoleSelector
|
||||
roles={roles}
|
||||
currentUserRole={userRole}
|
||||
value={field.value}
|
||||
onChange={(newRole) =>
|
||||
form.setValue(field.name, newRole)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</RolesDataProvider>
|
||||
</FormControl>
|
||||
|
||||
<FormDescription>
|
||||
|
||||
@@ -28,25 +28,38 @@ import { UpdateMemberRoleDialog } from './update-member-role-dialog';
|
||||
type Members =
|
||||
Database['public']['Functions']['get_account_members']['Returns'];
|
||||
|
||||
interface Permissions {
|
||||
canUpdateRole: (roleHierarchy: number) => boolean;
|
||||
canRemoveFromAccount: (roleHierarchy: number) => boolean;
|
||||
canTransferOwnership: boolean;
|
||||
}
|
||||
|
||||
type AccountMembersTableProps = {
|
||||
members: Members;
|
||||
|
||||
currentUserId: string;
|
||||
|
||||
permissions: {
|
||||
canUpdateRole: boolean;
|
||||
canTransferOwnership: boolean;
|
||||
canRemoveFromAccount: boolean;
|
||||
};
|
||||
userRoleHierarchy: number;
|
||||
isPrimaryOwner: boolean;
|
||||
canManageRoles: boolean;
|
||||
};
|
||||
|
||||
export function AccountMembersTable({
|
||||
members,
|
||||
permissions,
|
||||
currentUserId,
|
||||
isPrimaryOwner,
|
||||
userRoleHierarchy,
|
||||
canManageRoles,
|
||||
}: AccountMembersTableProps) {
|
||||
const [search, setSearch] = useState('');
|
||||
const { t } = useTranslation('teams');
|
||||
|
||||
const permissions = {
|
||||
canUpdateRole: (targetRole: number) =>
|
||||
canManageRoles && targetRole < userRoleHierarchy,
|
||||
canRemoveFromAccount: (targetRole: number) =>
|
||||
canManageRoles && targetRole < userRoleHierarchy,
|
||||
canTransferOwnership: isPrimaryOwner,
|
||||
};
|
||||
|
||||
const columns = useGetColumns(permissions, currentUserId);
|
||||
|
||||
const filteredMembers = members.filter((member) => {
|
||||
@@ -73,11 +86,7 @@ export function AccountMembersTable({
|
||||
}
|
||||
|
||||
function useGetColumns(
|
||||
permissions: {
|
||||
canUpdateRole: boolean;
|
||||
canTransferOwnership: boolean;
|
||||
canRemoveFromAccount: boolean;
|
||||
},
|
||||
permissions: Permissions,
|
||||
currentUserId: string,
|
||||
): ColumnDef<Members[0]>[] {
|
||||
const { t } = useTranslation('teams');
|
||||
@@ -173,7 +182,7 @@ function ActionsDropdown({
|
||||
member,
|
||||
currentUserId,
|
||||
}: {
|
||||
permissions: AccountMembersTableProps['permissions'];
|
||||
permissions: Permissions;
|
||||
member: Members[0];
|
||||
currentUserId: string;
|
||||
}) {
|
||||
@@ -188,6 +197,22 @@ function ActionsDropdown({
|
||||
return null;
|
||||
}
|
||||
|
||||
const memberRoleHierarchy = member.role_hierarchy_level;
|
||||
const canUpdateRole = permissions.canUpdateRole(memberRoleHierarchy);
|
||||
|
||||
const canRemoveFromAccount =
|
||||
permissions.canRemoveFromAccount(memberRoleHierarchy);
|
||||
|
||||
// if has no permission to update role, transfer ownership or remove from account
|
||||
// do not render the dropdown menu
|
||||
if (
|
||||
!canUpdateRole &&
|
||||
!permissions.canTransferOwnership &&
|
||||
!canRemoveFromAccount
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu>
|
||||
@@ -198,7 +223,7 @@ function ActionsDropdown({
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent>
|
||||
<If condition={permissions.canUpdateRole}>
|
||||
<If condition={canUpdateRole}>
|
||||
<DropdownMenuItem onClick={() => setIsUpdatingRole(true)}>
|
||||
<Trans i18nKey={'teams:updateRole'} />
|
||||
</DropdownMenuItem>
|
||||
@@ -210,7 +235,7 @@ function ActionsDropdown({
|
||||
</DropdownMenuItem>
|
||||
</If>
|
||||
|
||||
<If condition={permissions.canRemoveFromAccount}>
|
||||
<If condition={canRemoveFromAccount}>
|
||||
<DropdownMenuItem onClick={() => setIsRemoving(true)}>
|
||||
<Trans i18nKey={'teams:removeMember'} />
|
||||
</DropdownMenuItem>
|
||||
@@ -234,6 +259,7 @@ function ActionsDropdown({
|
||||
accountId={member.id}
|
||||
userId={member.user_id}
|
||||
userRole={member.role}
|
||||
userRoleHierarchy={memberRoleHierarchy}
|
||||
/>
|
||||
</If>
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import { Plus, X } from 'lucide-react';
|
||||
import { useFieldArray, useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
@@ -36,16 +35,19 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { InviteMembersSchema } from '../../schema/invite-members.schema';
|
||||
import { createInvitationsAction } from '../../server/actions/team-invitations-server-actions';
|
||||
import { MembershipRoleSelector } from './membership-role-selector';
|
||||
import { RolesDataProvider } from './roles-data-provider';
|
||||
|
||||
type InviteModel = ReturnType<typeof createEmptyInviteModel>;
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
export function InviteMembersDialogContainer({
|
||||
account,
|
||||
userRoleHierarchy,
|
||||
children,
|
||||
}: React.PropsWithChildren<{
|
||||
account: string;
|
||||
userRoleHierarchy: number;
|
||||
}>) {
|
||||
const [pending, startTransition] = useTransition();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
@@ -65,19 +67,24 @@ export function InviteMembersDialogContainer({
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<InviteMembersForm
|
||||
pending={pending}
|
||||
onSubmit={(data) => {
|
||||
startTransition(async () => {
|
||||
await createInvitationsAction({
|
||||
account,
|
||||
invitations: data.invitations,
|
||||
});
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(roles) => (
|
||||
<InviteMembersForm
|
||||
pending={pending}
|
||||
roles={roles}
|
||||
onSubmit={(data) => {
|
||||
startTransition(async () => {
|
||||
await createInvitationsAction({
|
||||
account,
|
||||
invitations: data.invitations,
|
||||
});
|
||||
|
||||
setIsOpen(false);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
setIsOpen(false);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</RolesDataProvider>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
@@ -85,10 +92,12 @@ export function InviteMembersDialogContainer({
|
||||
|
||||
function InviteMembersForm({
|
||||
onSubmit,
|
||||
roles,
|
||||
pending,
|
||||
}: {
|
||||
onSubmit: (data: { invitations: InviteModel[] }) => void;
|
||||
pending: boolean;
|
||||
roles: string[];
|
||||
}) {
|
||||
const { t } = useTranslation('teams');
|
||||
|
||||
@@ -156,6 +165,7 @@ function InviteMembersForm({
|
||||
|
||||
<FormControl>
|
||||
<MembershipRoleSelector
|
||||
roles={roles}
|
||||
value={field.value}
|
||||
onChange={(role) => {
|
||||
form.setValue(field.name, role);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -8,15 +7,14 @@ import {
|
||||
} from '@kit/ui/select';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
export const MembershipRoleSelector: React.FC<{
|
||||
roles: Role[];
|
||||
value: Role;
|
||||
currentUserRole?: Role;
|
||||
onChange: (role: Role) => unknown;
|
||||
}> = ({ value, currentUserRole, onChange }) => {
|
||||
const rolesList: Role[] = ['owner', 'member'];
|
||||
|
||||
}> = ({ roles, value, currentUserRole, onChange }) => {
|
||||
return (
|
||||
<Select value={value} onValueChange={onChange}>
|
||||
<SelectTrigger data-test={'role-selector-trigger'}>
|
||||
@@ -24,12 +22,12 @@ export const MembershipRoleSelector: React.FC<{
|
||||
</SelectTrigger>
|
||||
|
||||
<SelectContent>
|
||||
{rolesList.map((role) => {
|
||||
{roles.map((role) => {
|
||||
return (
|
||||
<SelectItem
|
||||
key={role}
|
||||
data-test={`role-item-${role}`}
|
||||
disabled={currentUserRole && currentUserRole === role}
|
||||
disabled={currentUserRole === role}
|
||||
value={role}
|
||||
>
|
||||
<span className={'text-sm capitalize'}>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { cva } from 'class-variance-authority';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Badge } from '@kit/ui/badge';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
const roleClassNameBuilder = cva('font-medium capitalize', {
|
||||
variants: {
|
||||
@@ -19,6 +18,7 @@ const roleClassNameBuilder = cva('font-medium capitalize', {
|
||||
export const RoleBadge: React.FC<{
|
||||
role: Role;
|
||||
}> = ({ role }) => {
|
||||
// @ts-expect-error: hard to type this since users can add custom roles
|
||||
const className = roleClassNameBuilder({ role });
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
||||
import { LoadingOverlay } from '@kit/ui/loading-overlay';
|
||||
|
||||
export function RolesDataProvider(props: {
|
||||
maxRoleHierarchy: number;
|
||||
children: (roles: string[]) => React.ReactNode;
|
||||
}) {
|
||||
const rolesQuery = useFetchRoles({
|
||||
maxRoleHierarchy: props.maxRoleHierarchy,
|
||||
});
|
||||
|
||||
if (rolesQuery.isLoading) {
|
||||
return <LoadingOverlay fullPage={false} />;
|
||||
}
|
||||
|
||||
// TODO handle error
|
||||
if (rolesQuery.isError) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{props.children(rolesQuery.data ?? [])}</>;
|
||||
}
|
||||
|
||||
function useFetchRoles(props: { maxRoleHierarchy: number }) {
|
||||
const supabase = useSupabase();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['roles', props.maxRoleHierarchy],
|
||||
queryFn: async () => {
|
||||
const { error, data } = await supabase
|
||||
.from('roles')
|
||||
.select('name')
|
||||
.gte('hierarchy_level', props.maxRoleHierarchy)
|
||||
.order('hierarchy_level', { ascending: true });
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return data.map((item) => item.name);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
@@ -29,8 +28,9 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { UpdateRoleSchema } from '../../schema/update-role-schema';
|
||||
import { updateMemberRoleAction } from '../../server/actions/team-members-server-actions';
|
||||
import { MembershipRoleSelector } from './membership-role-selector';
|
||||
import { RolesDataProvider } from './roles-data-provider';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
export const UpdateMemberRoleDialog: React.FC<{
|
||||
isOpen: boolean;
|
||||
@@ -38,7 +38,15 @@ export const UpdateMemberRoleDialog: React.FC<{
|
||||
userId: string;
|
||||
accountId: string;
|
||||
userRole: Role;
|
||||
}> = ({ isOpen, setIsOpen, userId, accountId, userRole }) => {
|
||||
userRoleHierarchy: number;
|
||||
}> = ({
|
||||
isOpen,
|
||||
setIsOpen,
|
||||
userId,
|
||||
accountId,
|
||||
userRole,
|
||||
userRoleHierarchy,
|
||||
}) => {
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DialogContent>
|
||||
@@ -52,12 +60,17 @@ export const UpdateMemberRoleDialog: React.FC<{
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<UpdateMemberForm
|
||||
setIsOpen={setIsOpen}
|
||||
userId={userId}
|
||||
accountId={accountId}
|
||||
userRole={userRole}
|
||||
/>
|
||||
<RolesDataProvider maxRoleHierarchy={userRoleHierarchy}>
|
||||
{(data) => (
|
||||
<UpdateMemberForm
|
||||
setIsOpen={setIsOpen}
|
||||
userId={userId}
|
||||
accountId={accountId}
|
||||
userRole={userRole}
|
||||
roles={data}
|
||||
/>
|
||||
)}
|
||||
</RolesDataProvider>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
@@ -68,11 +81,13 @@ function UpdateMemberForm({
|
||||
userRole,
|
||||
accountId,
|
||||
setIsOpen,
|
||||
roles,
|
||||
}: React.PropsWithChildren<{
|
||||
userId: string;
|
||||
userRole: Role;
|
||||
accountId: string;
|
||||
setIsOpen: (isOpen: boolean) => void;
|
||||
roles: Role[];
|
||||
}>) {
|
||||
const [pending, startTransition] = useTransition();
|
||||
const [error, setError] = useState<boolean>();
|
||||
@@ -128,6 +143,7 @@ function UpdateMemberForm({
|
||||
|
||||
<FormControl>
|
||||
<MembershipRoleSelector
|
||||
roles={roles}
|
||||
currentUserRole={userRole}
|
||||
value={field.value}
|
||||
onChange={(newRole) => form.setValue('role', newRole)}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
const InviteSchema = z.object({
|
||||
email: z.string().email(),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
type Role = string;
|
||||
|
||||
export const UpdateInvitationSchema = z.object({
|
||||
invitationId: z.number(),
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
|
||||
export const UpdateRoleSchema = z.object({
|
||||
role: z.custom<Role>((value) => z.string().parse(value)),
|
||||
role: z.string().min(1),
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function removeMemberFromAccountAction(params: {
|
||||
export async function updateMemberRoleAction(params: {
|
||||
accountId: string;
|
||||
userId: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
}) {
|
||||
const client = getSupabaseServerActionClient();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export class AccountMembersService {
|
||||
async updateMemberRole(params: {
|
||||
accountId: string;
|
||||
userId: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
}) {
|
||||
const { data, error } = await this.client
|
||||
.from('accounts_memberships')
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
import { LeaveTeamAccountSchema } from '../../schema/leave-team-account.schema';
|
||||
|
||||
export class LeaveAccountService {
|
||||
constructor(private readonly client: SupabaseClient<Database>) {}
|
||||
|
||||
async leaveTeamAccount(params: { accountId: string; userId: string }) {
|
||||
async leaveTeamAccount(params: z.infer<typeof LeaveTeamAccountSchema>) {
|
||||
await Promise.resolve();
|
||||
|
||||
console.log(params);
|
||||
// TODO
|
||||
// implement this method
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ type Config = z.infer<typeof MailerSchema>;
|
||||
*/
|
||||
export class CloudflareMailer implements Mailer {
|
||||
async sendEmail(config: Config) {
|
||||
// make lint happy for now
|
||||
await Promise.resolve();
|
||||
|
||||
console.log('Sending email with Cloudflare Workers', config);
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ export class StripeWebhookHandlerService
|
||||
const { subscription } = params;
|
||||
const lineItem = subscription.items.data[0];
|
||||
const price = lineItem?.price;
|
||||
const priceId = price?.id!;
|
||||
const priceId = price?.id as string;
|
||||
const interval = price?.recurring?.interval ?? null;
|
||||
|
||||
const active =
|
||||
@@ -194,8 +194,8 @@ export class StripeWebhookHandlerService
|
||||
price_amount: params.amount,
|
||||
cancel_at_period_end: subscription.cancel_at_period_end ?? false,
|
||||
interval: interval as string,
|
||||
currency: price?.currency as string,
|
||||
product_id: price?.product as string,
|
||||
currency: (price as Stripe.Price).currency,
|
||||
product_id: (price as Stripe.Price).product,
|
||||
variant_id: priceId,
|
||||
interval_count: price?.recurring?.interval_count ?? 1,
|
||||
period_starts_at: getISOString(subscription.current_period_start),
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"@kit/prettier-config": "workspace:*",
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@supabase/gotrue-js": "2.62.2",
|
||||
"@supabase/ssr": "^0.1.0",
|
||||
"@supabase/supabase-js": "^2.41.1",
|
||||
"@tanstack/react-query": "5.28.6"
|
||||
|
||||
@@ -38,17 +38,17 @@ export type Database = {
|
||||
Row: {
|
||||
account_id: string;
|
||||
id: number;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
};
|
||||
Insert: {
|
||||
account_id: string;
|
||||
id?: number;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
};
|
||||
Update: {
|
||||
account_id?: string;
|
||||
id?: number;
|
||||
role?: Database['public']['Enums']['account_role'];
|
||||
role?: string;
|
||||
};
|
||||
Relationships: [
|
||||
{
|
||||
@@ -72,6 +72,13 @@ export type Database = {
|
||||
referencedRelation: 'user_accounts';
|
||||
referencedColumns: ['id'];
|
||||
},
|
||||
{
|
||||
foreignKeyName: 'account_roles_role_fkey';
|
||||
columns: ['role'];
|
||||
isOneToOne: false;
|
||||
referencedRelation: 'roles';
|
||||
referencedColumns: ['name'];
|
||||
},
|
||||
];
|
||||
};
|
||||
accounts: {
|
||||
@@ -141,7 +148,7 @@ export type Database = {
|
||||
accounts_memberships: {
|
||||
Row: {
|
||||
account_id: string;
|
||||
account_role: Database['public']['Enums']['account_role'];
|
||||
account_role: string;
|
||||
created_at: string;
|
||||
created_by: string | null;
|
||||
updated_at: string;
|
||||
@@ -150,7 +157,7 @@ export type Database = {
|
||||
};
|
||||
Insert: {
|
||||
account_id: string;
|
||||
account_role: Database['public']['Enums']['account_role'];
|
||||
account_role: string;
|
||||
created_at?: string;
|
||||
created_by?: string | null;
|
||||
updated_at?: string;
|
||||
@@ -159,7 +166,7 @@ export type Database = {
|
||||
};
|
||||
Update: {
|
||||
account_id?: string;
|
||||
account_role?: Database['public']['Enums']['account_role'];
|
||||
account_role?: string;
|
||||
created_at?: string;
|
||||
created_by?: string | null;
|
||||
updated_at?: string;
|
||||
@@ -188,6 +195,13 @@ export type Database = {
|
||||
referencedRelation: 'user_accounts';
|
||||
referencedColumns: ['id'];
|
||||
},
|
||||
{
|
||||
foreignKeyName: 'accounts_memberships_account_role_fkey';
|
||||
columns: ['account_role'];
|
||||
isOneToOne: false;
|
||||
referencedRelation: 'roles';
|
||||
referencedColumns: ['name'];
|
||||
},
|
||||
{
|
||||
foreignKeyName: 'accounts_memberships_created_by_fkey';
|
||||
columns: ['created_by'];
|
||||
@@ -287,7 +301,7 @@ export type Database = {
|
||||
id: number;
|
||||
invite_token: string;
|
||||
invited_by: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
updated_at: string;
|
||||
};
|
||||
Insert: {
|
||||
@@ -298,7 +312,7 @@ export type Database = {
|
||||
id?: number;
|
||||
invite_token: string;
|
||||
invited_by: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
Update: {
|
||||
@@ -309,7 +323,7 @@ export type Database = {
|
||||
id?: number;
|
||||
invite_token?: string;
|
||||
invited_by?: string;
|
||||
role?: Database['public']['Enums']['account_role'];
|
||||
role?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
Relationships: [
|
||||
@@ -341,25 +355,83 @@ export type Database = {
|
||||
referencedRelation: 'users';
|
||||
referencedColumns: ['id'];
|
||||
},
|
||||
{
|
||||
foreignKeyName: 'invitations_role_fkey';
|
||||
columns: ['role'];
|
||||
isOneToOne: false;
|
||||
referencedRelation: 'roles';
|
||||
referencedColumns: ['name'];
|
||||
},
|
||||
];
|
||||
};
|
||||
role_permissions: {
|
||||
Row: {
|
||||
id: number;
|
||||
permission: Database['public']['Enums']['app_permissions'];
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
};
|
||||
Insert: {
|
||||
id?: number;
|
||||
permission: Database['public']['Enums']['app_permissions'];
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
};
|
||||
Update: {
|
||||
id?: number;
|
||||
permission?: Database['public']['Enums']['app_permissions'];
|
||||
role?: Database['public']['Enums']['account_role'];
|
||||
role?: string;
|
||||
};
|
||||
Relationships: [];
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: 'role_permissions_role_fkey';
|
||||
columns: ['role'];
|
||||
isOneToOne: false;
|
||||
referencedRelation: 'roles';
|
||||
referencedColumns: ['name'];
|
||||
},
|
||||
];
|
||||
};
|
||||
roles: {
|
||||
Row: {
|
||||
account_id: string | null;
|
||||
hierarchy_level: number;
|
||||
is_custom: boolean;
|
||||
name: string;
|
||||
};
|
||||
Insert: {
|
||||
account_id?: string | null;
|
||||
hierarchy_level: number;
|
||||
is_custom?: boolean;
|
||||
name: string;
|
||||
};
|
||||
Update: {
|
||||
account_id?: string | null;
|
||||
hierarchy_level?: number;
|
||||
is_custom?: boolean;
|
||||
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'];
|
||||
},
|
||||
];
|
||||
};
|
||||
subscriptions: {
|
||||
Row: {
|
||||
@@ -474,10 +546,18 @@ export type Database = {
|
||||
id: string | null;
|
||||
name: string | null;
|
||||
picture_url: string | null;
|
||||
role: Database['public']['Enums']['account_role'] | null;
|
||||
role: string | null;
|
||||
slug: string | null;
|
||||
};
|
||||
Relationships: [];
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: 'accounts_memberships_account_role_fkey';
|
||||
columns: ['role'];
|
||||
isOneToOne: false;
|
||||
referencedRelation: 'roles';
|
||||
referencedColumns: ['name'];
|
||||
},
|
||||
];
|
||||
};
|
||||
};
|
||||
Functions: {
|
||||
@@ -559,7 +639,7 @@ export type Database = {
|
||||
Args: {
|
||||
account_id: string;
|
||||
email: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
};
|
||||
Returns: {
|
||||
account_id: string;
|
||||
@@ -569,7 +649,7 @@ export type Database = {
|
||||
id: number;
|
||||
invite_token: string;
|
||||
invited_by: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
updated_at: string;
|
||||
};
|
||||
};
|
||||
@@ -582,7 +662,7 @@ export type Database = {
|
||||
email: string;
|
||||
account_id: string;
|
||||
invited_by: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
expires_at: string;
|
||||
@@ -598,7 +678,8 @@ export type Database = {
|
||||
id: string;
|
||||
user_id: string;
|
||||
account_id: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
role_hierarchy_level: number;
|
||||
primary_owner_user_id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
@@ -627,6 +708,14 @@ export type Database = {
|
||||
updated_by: string | null;
|
||||
}[];
|
||||
};
|
||||
has_more_elevated_role: {
|
||||
Args: {
|
||||
target_user_id: string;
|
||||
target_account_id: string;
|
||||
role_name: string;
|
||||
};
|
||||
Returns: boolean;
|
||||
};
|
||||
has_permission: {
|
||||
Args: {
|
||||
user_id: string;
|
||||
@@ -638,7 +727,7 @@ export type Database = {
|
||||
has_role_on_account: {
|
||||
Args: {
|
||||
account_id: string;
|
||||
account_role?: Database['public']['Enums']['account_role'];
|
||||
account_role?: string;
|
||||
};
|
||||
Returns: boolean;
|
||||
};
|
||||
@@ -670,7 +759,8 @@ export type Database = {
|
||||
name: string;
|
||||
picture_url: string;
|
||||
slug: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
role: string;
|
||||
role_hierarchy_level: number;
|
||||
primary_owner_user_id: string;
|
||||
subscription_status: Database['public']['Enums']['subscription_status'];
|
||||
permissions: Database['public']['Enums']['app_permissions'][];
|
||||
@@ -690,7 +780,6 @@ export type Database = {
|
||||
};
|
||||
};
|
||||
Enums: {
|
||||
account_role: 'owner' | 'member';
|
||||
app_permissions:
|
||||
| 'roles.manage'
|
||||
| 'billing.manage'
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import type {
|
||||
AuthError,
|
||||
SignInWithPasswordlessCredentials,
|
||||
} from '@supabase/gotrue-js';
|
||||
import type { SignInWithPasswordlessCredentials } from '@supabase/gotrue-js';
|
||||
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
@@ -15,7 +12,7 @@ export function useSignInWithOtp() {
|
||||
const result = await client.auth.signInWithOtp(credentials);
|
||||
|
||||
if (result.error) {
|
||||
if (shouldIgnoreError(result.error)) {
|
||||
if (shouldIgnoreError(result.error.message)) {
|
||||
console.warn(
|
||||
`Ignoring error during development: ${result.error.message}`,
|
||||
);
|
||||
@@ -37,10 +34,10 @@ export function useSignInWithOtp() {
|
||||
|
||||
export default useSignInWithOtp;
|
||||
|
||||
function shouldIgnoreError(error: AuthError) {
|
||||
function shouldIgnoreError(error: string) {
|
||||
return isSmsProviderNotSetupError(error);
|
||||
}
|
||||
|
||||
function isSmsProviderNotSetupError(error: AuthError) {
|
||||
return error.message.includes(`sms Provider could not be found`);
|
||||
function isSmsProviderNotSetupError(error: string) {
|
||||
return error.includes(`sms Provider could not be found`);
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
const SIDEBAR_COLLAPSED_STORAGE_KEY = 'sidebarState';
|
||||
|
||||
function useCollapsible(initialValue?: boolean) {
|
||||
const [isCollapsed, setIsCollapsed] = useState(initialValue);
|
||||
|
||||
const onCollapseChange = useCallback((collapsed: boolean) => {
|
||||
setIsCollapsed(collapsed);
|
||||
storeCollapsibleState(collapsed);
|
||||
}, []);
|
||||
|
||||
return [isCollapsed, onCollapseChange] as [boolean, typeof onCollapseChange];
|
||||
}
|
||||
|
||||
function storeCollapsibleState(collapsed: boolean) {
|
||||
// TODO: implement below
|
||||
/*
|
||||
setCookie(
|
||||
SIDEBAR_COLLAPSED_STORAGE_KEY,
|
||||
collapsed ? 'collapsed' : 'expanded',
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
export default useCollapsible;
|
||||
@@ -138,7 +138,6 @@ export const ImageUploadInput = forwardRef<React.ElementRef<'input'>, Props>(
|
||||
}
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
||||
<label
|
||||
id={'image-upload-input'}
|
||||
className={`relative flex h-10 w-full cursor-pointer rounded-md border border-dashed border-input
|
||||
|
||||
@@ -71,7 +71,6 @@ export function ImageUploader(
|
||||
|
||||
return (
|
||||
<div className={'flex items-center space-x-4'}>
|
||||
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
|
||||
<label className={'relative h-20 w-20 animate-in fade-in zoom-in-50'}>
|
||||
<Image fill className={'h-20 w-20 rounded-full'} src={image} alt={''} />
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { MDXComponents } from 'mdx/types';
|
||||
import { getMDXComponent } from 'next-contentlayer/hooks';
|
||||
|
||||
import Components from './mdx-components';
|
||||
// @ts-ignore
|
||||
// @ts-expect-error: weird typescript error with css modules
|
||||
import styles from './mdx-renderer.module.css';
|
||||
|
||||
export function Mdx({
|
||||
|
||||
Reference in New Issue
Block a user