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:
@@ -27,7 +27,7 @@ import { Input } from '@kit/ui/input';
|
|||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { CreateTeamSchema } from '../schema/create-team.schema';
|
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(
|
export function CreateTeamAccountDialog(
|
||||||
props: React.PropsWithChildren<{
|
props: React.PropsWithChildren<{
|
||||||
@@ -75,7 +75,7 @@ function CreateOrganizationAccountForm(props: { onClose: () => void }) {
|
|||||||
onSubmit={form.handleSubmit((data) => {
|
onSubmit={form.handleSubmit((data) => {
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
try {
|
try {
|
||||||
await createOrganizationAccountAction(data);
|
await createTeamAccountAction(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(true);
|
setError(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,25 +3,39 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { enhanceAction } from '@kit/next/actions';
|
import { enhanceAction } from '@kit/next/actions';
|
||||||
|
import { getLogger } from '@kit/shared/logger';
|
||||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||||
|
|
||||||
import { CreateTeamSchema } from '../../schema/create-team.schema';
|
import { CreateTeamSchema } from '../../schema/create-team.schema';
|
||||||
import { createCreateTeamAccountService } from '../services/create-team-account.service';
|
import { createCreateTeamAccountService } from '../services/create-team-account.service';
|
||||||
|
|
||||||
export const createOrganizationAccountAction = enhanceAction(
|
export const createTeamAccountAction = enhanceAction(
|
||||||
async ({ name }, user) => {
|
async ({ name }, user) => {
|
||||||
|
const logger = await getLogger();
|
||||||
const client = getSupabaseServerActionClient();
|
const client = getSupabaseServerActionClient();
|
||||||
const service = createCreateTeamAccountService(client);
|
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({
|
const { data, error } = await service.createNewOrganizationAccount({
|
||||||
name,
|
name,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
logger.error({ ...ctx, error }, `Failed to create team account`);
|
||||||
|
|
||||||
throw new Error('Error creating team account');
|
throw new Error('Error creating team account');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(ctx, `Team account created`);
|
||||||
|
|
||||||
const accountHomePath = '/home/' + data.slug;
|
const accountHomePath = '/home/' + data.slug;
|
||||||
|
|
||||||
redirect(accountHomePath);
|
redirect(accountHomePath);
|
||||||
|
|||||||
@@ -3,15 +3,24 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { enhanceAction } from '@kit/next/actions';
|
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';
|
import { UpdateTeamNameSchema } from '../../schema/update-team-name.schema';
|
||||||
|
|
||||||
export const updateTeamAccountName = enhanceAction(
|
export const updateTeamAccountName = enhanceAction(
|
||||||
async (params) => {
|
async (params) => {
|
||||||
const client = getSupabaseServerComponentClient();
|
const client = getSupabaseServerActionClient();
|
||||||
|
const logger = await getLogger();
|
||||||
const { name, path, slug } = params;
|
const { name, path, slug } = params;
|
||||||
|
|
||||||
|
const ctx = {
|
||||||
|
name: 'team-accounts.update',
|
||||||
|
accountName: name,
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.info(ctx, `Updating team name...`);
|
||||||
|
|
||||||
const { error, data } = await client
|
const { error, data } = await client
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.update({
|
.update({
|
||||||
@@ -25,11 +34,15 @@ export const updateTeamAccountName = enhanceAction(
|
|||||||
.single();
|
.single();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
logger.error({ ...ctx, error }, `Failed to update team name`);
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newSlug = data.slug;
|
const newSlug = data.slug;
|
||||||
|
|
||||||
|
logger.info(ctx, `Team name updated`);
|
||||||
|
|
||||||
if (newSlug) {
|
if (newSlug) {
|
||||||
const nextPath = path.replace('[account]', newSlug);
|
const nextPath = path.replace('[account]', newSlug);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user