Add logging to team account creation and update

The commit enhances the team account creation and update features by adding logging capabilities. It renames createOrganizationAccountAction to createTeamAccountAction for better contextual relevance. The logging provides informative insights into the process of creating and updating the name of the team account, aiding in easier debugging in the event of an error.
This commit is contained in:
giancarlo
2024-05-03 09:09:47 +07:00
parent 468204d355
commit 549097efa6
3 changed files with 32 additions and 5 deletions

View File

@@ -27,7 +27,7 @@ import { Input } from '@kit/ui/input';
import { Trans } from '@kit/ui/trans';
import { CreateTeamSchema } from '../schema/create-team.schema';
import { createOrganizationAccountAction } from '../server/actions/create-team-account-server-actions';
import { createTeamAccountAction } from '../server/actions/create-team-account-server-actions';
export function CreateTeamAccountDialog(
props: React.PropsWithChildren<{
@@ -75,7 +75,7 @@ function CreateOrganizationAccountForm(props: { onClose: () => void }) {
onSubmit={form.handleSubmit((data) => {
startTransition(async () => {
try {
await createOrganizationAccountAction(data);
await createTeamAccountAction(data);
} catch (error) {
setError(true);
}

View File

@@ -3,25 +3,39 @@
import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getLogger } from '@kit/shared/logger';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
import { CreateTeamSchema } from '../../schema/create-team.schema';
import { createCreateTeamAccountService } from '../services/create-team-account.service';
export const createOrganizationAccountAction = enhanceAction(
export const createTeamAccountAction = enhanceAction(
async ({ name }, user) => {
const logger = await getLogger();
const client = getSupabaseServerActionClient();
const service = createCreateTeamAccountService(client);
const ctx = {
name: 'team-accounts.create',
userId: user.id,
accountName: name,
};
logger.info(ctx, `Creating team account...`);
const { data, error } = await service.createNewOrganizationAccount({
name,
userId: user.id,
});
if (error) {
logger.error({ ...ctx, error }, `Failed to create team account`);
throw new Error('Error creating team account');
}
logger.info(ctx, `Team account created`);
const accountHomePath = '/home/' + data.slug;
redirect(accountHomePath);

View File

@@ -3,15 +3,24 @@
import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import { getLogger } from '@kit/shared/logger';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
import { UpdateTeamNameSchema } from '../../schema/update-team-name.schema';
export const updateTeamAccountName = enhanceAction(
async (params) => {
const client = getSupabaseServerComponentClient();
const client = getSupabaseServerActionClient();
const logger = await getLogger();
const { name, path, slug } = params;
const ctx = {
name: 'team-accounts.update',
accountName: name,
};
logger.info(ctx, `Updating team name...`);
const { error, data } = await client
.from('accounts')
.update({
@@ -25,11 +34,15 @@ export const updateTeamAccountName = enhanceAction(
.single();
if (error) {
logger.error({ ...ctx, error }, `Failed to update team name`);
throw error;
}
const newSlug = data.slug;
logger.info(ctx, `Team name updated`);
if (newSlug) {
const nextPath = path.replace('[account]', newSlug);