Remove team account related services and actions
Removed services and actions related to team account deletion as well as updated paths within other dependent files, better reflecting their new locations. Also, added a new service titled 'AccountBillingService' for handling billing-related operations and restructured the form layout and handled translation in 'team-account-danger-zone' component.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
'use server';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Logger } from '@kit/shared/logger';
|
||||
import { requireAuth } from '@kit/supabase/require-auth';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { CreateTeamSchema } from '../../schema/create-team.schema';
|
||||
import { CreateTeamAccountService } from '../services/create-team-account.service';
|
||||
|
||||
const TEAM_ACCOUNTS_HOME_PATH = z
|
||||
.string({
|
||||
required_error: 'variable TEAM_ACCOUNTS_HOME_PATH is required',
|
||||
})
|
||||
.min(1)
|
||||
.parse(process.env.TEAM_ACCOUNTS_HOME_PATH);
|
||||
|
||||
export async function createOrganizationAccountAction(
|
||||
params: z.infer<typeof CreateTeamSchema>,
|
||||
) {
|
||||
const { name: accountName } = CreateTeamSchema.parse(params);
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = new CreateTeamAccountService(client);
|
||||
const session = await requireAuth(client);
|
||||
|
||||
if (session.error) {
|
||||
redirect(session.redirectTo);
|
||||
}
|
||||
|
||||
const userId = session.data.user.id;
|
||||
|
||||
const createAccountResponse = await service.createNewOrganizationAccount({
|
||||
name: accountName,
|
||||
userId,
|
||||
});
|
||||
|
||||
if (createAccountResponse.error) {
|
||||
Logger.error(
|
||||
{
|
||||
userId,
|
||||
error: createAccountResponse.error,
|
||||
name: 'accounts',
|
||||
},
|
||||
`Error creating team account`,
|
||||
);
|
||||
|
||||
throw new Error('Error creating team account');
|
||||
}
|
||||
|
||||
const accountHomePath =
|
||||
TEAM_ACCOUNTS_HOME_PATH + '/' + createAccountResponse.data.slug;
|
||||
|
||||
redirect(accountHomePath);
|
||||
}
|
||||
Reference in New Issue
Block a user