Files
myeasycms-v2/packages/features/team-accounts/src/server/actions/team-details-server-actions.ts
giancarlo 0616d3b288 Refactor account server actions using the enhanced action helper
The enhanced action helper has been utilized to refactor account-related server actions across the codebase. This change aims to streamline the server-side handling of user accounts, team accounts, and related functionality. As a result, various account-related server actions have now been wrapped with the helper, providing uniformity and consistency in action handling.
2024-04-27 18:31:11 +07:00

45 lines
915 B
TypeScript

'use server';
import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import { UpdateTeamNameSchema } from '../../schema/update-team-name.schema';
export const updateTeamAccountName = enhanceAction(
async (params) => {
const client = getSupabaseServerComponentClient();
const { name, path, slug } = params;
const { error, data } = await client
.from('accounts')
.update({
name,
slug,
})
.match({
slug,
})
.select('slug')
.single();
if (error) {
throw error;
}
const newSlug = data.slug;
if (newSlug) {
const nextPath = path.replace('[account]', newSlug);
redirect(nextPath);
}
return { success: true };
},
{
schema: UpdateTeamNameSchema,
},
);