Remove admin functionality related code
The admin functionality related code has been removed which includes various user and organization functionalities like delete, update, ban etc. This includes action logic, UI components and supportive utility functions. Notable deletions include the server action files, dialog components for actions like banning and deleting, and related utility functions. This massive cleanup is aimed at simplifying the codebase and the commit reflects adherence to project restructuring.
This commit is contained in:
@@ -9,7 +9,9 @@ import { z } from 'zod';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { DeleteInvitationSchema } from '../schema/delete-invitation.schema';
|
||||
import { InviteMembersSchema } from '../schema/invite-members.schema';
|
||||
import { UpdateInvitationSchema } from '../schema/update-invitation-schema';
|
||||
import { AccountInvitationsService } from '../services/account-invitations.service';
|
||||
|
||||
/**
|
||||
@@ -44,7 +46,11 @@ export async function createInvitationsAction(params: {
|
||||
*
|
||||
* @return {Object} - The result of the delete operation.
|
||||
*/
|
||||
export async function deleteInvitationAction(params: { invitationId: string }) {
|
||||
export async function deleteInvitationAction(
|
||||
params: z.infer<typeof DeleteInvitationSchema>,
|
||||
) {
|
||||
const invitation = DeleteInvitationSchema.parse(params);
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const { data, error } = await client.auth.getUser();
|
||||
|
||||
@@ -54,27 +60,22 @@ export async function deleteInvitationAction(params: { invitationId: string }) {
|
||||
|
||||
const service = new AccountInvitationsService(client);
|
||||
|
||||
await service.removeInvitation({
|
||||
invitationId: params.invitationId,
|
||||
});
|
||||
await service.deleteInvitation(invitation);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
export async function updateInvitationAction(params: {
|
||||
invitationId: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
}) {
|
||||
export async function updateInvitationAction(
|
||||
params: z.infer<typeof UpdateInvitationSchema>,
|
||||
) {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const invitation = UpdateInvitationSchema.parse(params);
|
||||
|
||||
await assertSession(client);
|
||||
|
||||
const service = new AccountInvitationsService(client);
|
||||
|
||||
await service.updateInvitation({
|
||||
invitationId: params.invitationId,
|
||||
role: params.role,
|
||||
});
|
||||
await service.updateInvitation(invitation);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@kit/ui/dropdown-menu';
|
||||
import { If } from '@kit/ui/if';
|
||||
import { Input } from '@kit/ui/input';
|
||||
import { ProfileAvatar } from '@kit/ui/profile-avatar';
|
||||
|
||||
import { RoleBadge } from '../role-badge';
|
||||
@@ -37,9 +38,30 @@ export function AccountInvitationsTable({
|
||||
invitations,
|
||||
permissions,
|
||||
}: AccountInvitationsTableProps) {
|
||||
const [search, setSearch] = useState('');
|
||||
const columns = useMemo(() => getColumns(permissions), [permissions]);
|
||||
|
||||
return <DataTable columns={columns} data={invitations} />;
|
||||
const filteredInvitations = invitations.filter((member) => {
|
||||
const searchString = search.toLowerCase();
|
||||
const email = member.email.split('@')[0]?.toLowerCase() ?? '';
|
||||
|
||||
return (
|
||||
email.includes(searchString) ||
|
||||
member.role.toLowerCase().includes(searchString)
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={'flex flex-col space-y-2'}>
|
||||
<Input
|
||||
value={search}
|
||||
onInput={(e) => setSearch((e.target as HTMLInputElement).value)}
|
||||
placeholder={'Search Invitation'}
|
||||
/>
|
||||
|
||||
<DataTable columns={columns} data={filteredInvitations} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function getColumns(permissions: {
|
||||
|
||||
@@ -34,7 +34,7 @@ type Role = Database['public']['Enums']['account_role'];
|
||||
export const UpdateInvitationDialog: React.FC<{
|
||||
isOpen: boolean;
|
||||
setIsOpen: (isOpen: boolean) => void;
|
||||
invitationId: string;
|
||||
invitationId: number;
|
||||
userRole: Role;
|
||||
}> = ({ isOpen, setIsOpen, invitationId, userRole }) => {
|
||||
return (
|
||||
@@ -65,7 +65,7 @@ function UpdateInvitationForm({
|
||||
userRole,
|
||||
setIsOpen,
|
||||
}: React.PropsWithChildren<{
|
||||
invitationId: string;
|
||||
invitationId: number;
|
||||
userRole: Role;
|
||||
setIsOpen: (isOpen: boolean) => void;
|
||||
}>) {
|
||||
@@ -75,7 +75,10 @@ function UpdateInvitationForm({
|
||||
const onSubmit = ({ role }: { role: Role }) => {
|
||||
startTransition(async () => {
|
||||
try {
|
||||
await updateInvitationAction({ invitationId, role });
|
||||
await updateInvitationAction({
|
||||
invitationId,
|
||||
role,
|
||||
});
|
||||
|
||||
setIsOpen(false);
|
||||
} catch (e) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@kit/ui/dropdown-menu';
|
||||
import { If } from '@kit/ui/if';
|
||||
import { Input } from '@kit/ui/input';
|
||||
import { ProfileAvatar } from '@kit/ui/profile-avatar';
|
||||
|
||||
import { RoleBadge } from '../role-badge';
|
||||
@@ -42,12 +43,34 @@ export function AccountMembersTable({
|
||||
permissions,
|
||||
currentUserId,
|
||||
}: AccountMembersTableProps) {
|
||||
const [search, setSearch] = useState('');
|
||||
|
||||
const columns = useMemo(
|
||||
() => getColumns(permissions, currentUserId),
|
||||
[currentUserId, permissions],
|
||||
);
|
||||
|
||||
return <DataTable columns={columns} data={members} />;
|
||||
const filteredMembers = members.filter((member) => {
|
||||
const searchString = search.toLowerCase();
|
||||
const displayName = member.name ?? member.email.split('@')[0];
|
||||
|
||||
return (
|
||||
displayName.includes(searchString) ||
|
||||
member.role.toLowerCase().includes(searchString)
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={'flex flex-col space-y-2'}>
|
||||
<Input
|
||||
value={search}
|
||||
onInput={(e) => setSearch((e.target as HTMLInputElement).value)}
|
||||
placeholder={'Search Member'}
|
||||
/>
|
||||
|
||||
<DataTable columns={columns} data={filteredMembers} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function getColumns(
|
||||
@@ -111,7 +134,7 @@ function getColumns(
|
||||
<If condition={isPrimaryOwner}>
|
||||
<span
|
||||
className={
|
||||
'rounded-md bg-yellow-400 px-2.5 py-1 text-xs font-medium'
|
||||
'rounded-md bg-yellow-400 px-2.5 py-1 text-xs font-medium dark:text-black'
|
||||
}
|
||||
>
|
||||
Primary
|
||||
|
||||
@@ -10,7 +10,7 @@ const roleClassNameBuilder = cva('font-medium capitalize', {
|
||||
variants: {
|
||||
role: {
|
||||
owner: 'bg-primary',
|
||||
member: 'bg-blue-50 text-blue-500 hover:bg-blue-50',
|
||||
member: 'bg-blue-50 text-blue-500 dark:bg-blue-500/10',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const DeleteInvitationSchema = z.object({
|
||||
invitationId: z.bigint(),
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
type Role = Database['public']['Enums']['account_role'];
|
||||
|
||||
export const UpdateInvitationSchema = z.object({
|
||||
id: z.bigint(),
|
||||
role: z.custom<Role>(() => z.string().min(1)),
|
||||
});
|
||||
@@ -7,7 +7,9 @@ import { Mailer } from '@kit/mailers';
|
||||
import { Logger } from '@kit/shared/logger';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
import { DeleteInvitationSchema } from '../schema/delete-invitation.schema';
|
||||
import { InviteMembersSchema } from '../schema/invite-members.schema';
|
||||
import { UpdateInvitationSchema } from '../schema/update-invitation-schema';
|
||||
|
||||
const invitePath = process.env.INVITATION_PAGE_PATH;
|
||||
const siteURL = process.env.NEXT_PUBLIC_SITE_URL;
|
||||
@@ -33,10 +35,10 @@ export class AccountInvitationsService {
|
||||
|
||||
constructor(private readonly client: SupabaseClient<Database>) {}
|
||||
|
||||
async removeInvitation(params: { invitationId: string }) {
|
||||
async deleteInvitation(params: z.infer<typeof DeleteInvitationSchema>) {
|
||||
Logger.info('Removing invitation', {
|
||||
invitationId: params.invitationId,
|
||||
name: this.namespace,
|
||||
...params,
|
||||
});
|
||||
|
||||
const { data, error } = await this.client
|
||||
@@ -51,20 +53,16 @@ export class AccountInvitationsService {
|
||||
}
|
||||
|
||||
Logger.info('Invitation successfully removed', {
|
||||
invitationId: params.invitationId,
|
||||
...params,
|
||||
name: this.namespace,
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async updateInvitation(params: {
|
||||
invitationId: string;
|
||||
role: Database['public']['Enums']['account_role'];
|
||||
}) {
|
||||
async updateInvitation(params: z.infer<typeof UpdateInvitationSchema>) {
|
||||
Logger.info('Updating invitation', {
|
||||
invitationId: params.invitationId,
|
||||
role: params.role,
|
||||
...params,
|
||||
name: this.namespace,
|
||||
});
|
||||
|
||||
@@ -74,7 +72,7 @@ export class AccountInvitationsService {
|
||||
role: params.role,
|
||||
})
|
||||
.match({
|
||||
id: params.invitationId,
|
||||
id: params.id,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
@@ -82,8 +80,7 @@ export class AccountInvitationsService {
|
||||
}
|
||||
|
||||
Logger.info('Invitation successfully updated', {
|
||||
invitationId: params.invitationId,
|
||||
role: params.role,
|
||||
...params,
|
||||
name: this.namespace,
|
||||
});
|
||||
|
||||
@@ -154,7 +151,7 @@ export class AccountInvitationsService {
|
||||
try {
|
||||
const { renderInviteEmail } = await import('@kit/emails');
|
||||
|
||||
const html = await renderInviteEmail({
|
||||
const html = renderInviteEmail({
|
||||
link: this.getInvitationLink(invitation.invite_token),
|
||||
invitedUserEmail: invitation.email,
|
||||
inviter: user.email,
|
||||
|
||||
Reference in New Issue
Block a user