Remove redundant files and update pnpm lockfile

This commit is contained in:
giancarlo
2024-04-30 22:16:38 +07:00
parent 9eded69f15
commit 19aa40493f
78 changed files with 8835 additions and 10056 deletions

View File

@@ -0,0 +1,91 @@
import 'server-only';
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '~/lib/database.types';
import { loadTeamWorkspace } from '../../../_lib/server/team-account-workspace.loader';
/**
* Load data for the members page
* @param client
* @param slug
*/
export async function loadMembersPageData(
client: SupabaseClient<Database>,
slug: string,
) {
return Promise.all([
loadTeamWorkspace(slug),
loadAccountMembers(client, slug),
loadInvitations(client, slug),
loadUser(client),
canAddMember,
]);
}
/**
* @name canAddMember
* @description Check if the current user can add a member to the account
*
* This needs additional logic to determine if the user can add a member to the account
* Please implement the logic and return a boolean value
*
* The same check needs to be added when creating an invitation
*
*/
async function canAddMember() {
return Promise.resolve(true);
}
async function loadUser(client: SupabaseClient<Database>) {
const { data, error } = await client.auth.getUser();
if (error) {
throw error;
}
return data.user;
}
/**
* Load account members
* @param client
* @param account
*/
async function loadAccountMembers(
client: SupabaseClient<Database>,
account: string,
) {
const { data, error } = await client.rpc('get_account_members', {
account_slug: account,
});
if (error) {
console.error(error);
throw error;
}
return data ?? [];
}
/**
* Load account invitations
* @param client
* @param account
*/
async function loadInvitations(
client: SupabaseClient<Database>,
account: string,
) {
const { data, error } = await client.rpc('get_account_invitations', {
account_slug: account,
});
if (error) {
console.error(error);
throw error;
}
return data ?? [];
}