B2B-88: add starter kit structure and elements

This commit is contained in:
devmc-ee
2025-06-08 16:18:30 +03:00
parent 657a36a298
commit e7b25600cb
1280 changed files with 77893 additions and 5688 deletions

View File

@@ -0,0 +1,79 @@
import 'server-only';
import { SupabaseClient } from '@supabase/supabase-js';
import { loadTeamWorkspace } from '~/home/[account]/_lib/server/team-account-workspace.loader';
import { Database } from '~/lib/database.types';
/**
* Load data for the members page
* @param client
* @param slug
*/
export async function loadMembersPageData(
client: SupabaseClient<Database>,
slug: string,
) {
return Promise.all([
loadAccountMembers(client, slug),
loadInvitations(client, slug),
canAddMember,
loadTeamWorkspace(slug),
]);
}
/**
* @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);
}
/**
* 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 ?? [];
}