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:
giancarlo
2024-03-25 15:40:43 +08:00
parent 752259ab17
commit 95793c42b4
135 changed files with 1062 additions and 2872 deletions

View File

@@ -1,17 +1,10 @@
import { headers } from 'next/headers';
import { notFound } from 'next/navigation';
import type { SupabaseClient } from '@supabase/supabase-js';
import { Logger } from '@kit/shared/logger';
import { Database } from '@kit/supabase/database';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import { Heading } from '@kit/ui/heading';
import { If } from '@kit/ui/if';
import { Trans } from '@kit/ui/trans';
import ExistingUserInviteForm from '~/join/_components/ExistingUserInviteForm';
import NewUserInviteForm from '~/join/_components/NewUserInviteForm';
import { withI18n } from '~/lib/i18n/with-i18n';
interface Context {
@@ -28,12 +21,10 @@ async function JoinTeamAccountPage({ searchParams }: Context) {
const token = searchParams.invite_token;
const data = await getInviteDataFromInviteToken(token);
if (!data.membership) {
if (!data) {
notFound();
}
const organization = data.membership.organization;
return (
<>
<Heading level={4}>
@@ -62,70 +53,26 @@ async function JoinTeamAccountPage({ searchParams }: Context) {
</If>
</p>
</div>
<If
condition={data.session}
fallback={<NewUserInviteForm code={token} />}
>
{(session) => <ExistingUserInviteForm code={token} session={session} />}
</If>
</>
);
}
export default withI18n(JoinTeamAccountPage);
async function getInviteDataFromInviteToken(code: string) {
const client = getSupabaseServerComponentClient();
async function getInviteDataFromInviteToken(token: string) {
// we use an admin client to be able to read the pending membership
// without having to be logged in
const adminClient = getSupabaseServerComponentClient({ admin: true });
const { data: membership, error } = await getInvite(adminClient, code);
const { data: invitation, error } = await adminClient
.from('invitations')
.select('*')
.eq('invite_token', token)
.single();
// if the invite wasn't found, it's 404
if (error) {
Logger.warn(
{
code,
error,
},
`User navigated to invite page, but it wasn't found. Redirecting to home page...`,
);
notFound();
if (!invitation ?? error) {
return null;
}
const { data: userSession } = await client.auth.getSession();
const session = userSession?.session;
const csrfToken = headers().get('x-csrf-token');
return {
csrfToken,
session,
membership,
code,
};
}
function getInvite(adminClient: SupabaseClient<Database>, code: string) {
return getMembershipByInviteCode<{
id: number;
code: string;
organization: {
name: string;
id: number;
};
}>(adminClient, {
code,
query: `
id,
code,
organization: organization_id (
name,
id
)
`,
});
return invitation;
}