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.
This commit is contained in:
@@ -2,41 +2,43 @@
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
|
||||
import { UpdateTeamNameSchema } from '../../schema/update-team-name.schema';
|
||||
|
||||
export async function updateTeamAccountName(
|
||||
params: z.infer<typeof UpdateTeamNameSchema>,
|
||||
) {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const { name, slug, path } = UpdateTeamNameSchema.parse(params);
|
||||
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();
|
||||
const { error, data } = await client
|
||||
.from('accounts')
|
||||
.update({
|
||||
name,
|
||||
slug,
|
||||
})
|
||||
.match({
|
||||
slug,
|
||||
})
|
||||
.select('slug')
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const newSlug = data.slug;
|
||||
const newSlug = data.slug;
|
||||
|
||||
if (newSlug) {
|
||||
const nextPath = path.replace('[account]', newSlug);
|
||||
if (newSlug) {
|
||||
const nextPath = path.replace('[account]', newSlug);
|
||||
|
||||
redirect(nextPath);
|
||||
}
|
||||
redirect(nextPath);
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
return { success: true };
|
||||
},
|
||||
{
|
||||
schema: UpdateTeamNameSchema,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user