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.
45 lines
915 B
TypeScript
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,
|
|
},
|
|
);
|