Files
myeasycms-v2/packages/features/team-accounts/src/server/actions/leave-team-account-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

32 lines
929 B
TypeScript

'use server';
import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
import { LeaveTeamAccountSchema } from '../../schema/leave-team-account.schema';
import { createLeaveTeamAccountService } from '../services/leave-team-account.service';
export const leaveTeamAccountAction = enhanceAction(
async (formData: FormData, user) => {
const body = Object.fromEntries(formData.entries());
const params = LeaveTeamAccountSchema.parse(body);
const service = createLeaveTeamAccountService(
getSupabaseServerActionClient({ admin: true }),
);
await service.leaveTeamAccount({
accountId: params.accountId,
userId: user.id,
});
revalidatePath('/home/[account]', 'layout');
return redirect('/home');
},
{},
);