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:
@@ -28,12 +28,15 @@ export const createPersonalAccountCheckoutSession = enhanceAction(
|
||||
* @name createPersonalAccountBillingPortalSession
|
||||
* @description Creates a billing Portal session for a personal account
|
||||
*/
|
||||
export async function createPersonalAccountBillingPortalSession() {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = createUserBillingService(client);
|
||||
export const createPersonalAccountBillingPortalSession = enhanceAction(
|
||||
async () => {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = createUserBillingService(client);
|
||||
|
||||
// get url to billing portal
|
||||
const url = await service.createBillingPortalSession();
|
||||
// get url to billing portal
|
||||
const url = await service.createBillingPortalSession();
|
||||
|
||||
return redirect(url);
|
||||
}
|
||||
return redirect(url);
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
// billing imports
|
||||
@@ -17,30 +16,34 @@ import { createTeamBillingService } from './team-billing.service';
|
||||
* @name createTeamAccountCheckoutSession
|
||||
* @description Creates a checkout session for a team account.
|
||||
*/
|
||||
export async function createTeamAccountCheckoutSession(
|
||||
params: z.infer<typeof TeamCheckoutSchema>,
|
||||
) {
|
||||
const data = TeamCheckoutSchema.parse(params);
|
||||
export const createTeamAccountCheckoutSession = enhanceAction(
|
||||
(data) => {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = createTeamBillingService(client);
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = createTeamBillingService(client);
|
||||
|
||||
return service.createCheckout(data);
|
||||
}
|
||||
return service.createCheckout(data);
|
||||
},
|
||||
{
|
||||
schema: TeamCheckoutSchema,
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* @name createBillingPortalSession
|
||||
* @description Creates a Billing Session Portal and redirects the user to the
|
||||
* provider's hosted instance
|
||||
*/
|
||||
export async function createBillingPortalSession(formData: FormData) {
|
||||
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
|
||||
export const createBillingPortalSession = enhanceAction(
|
||||
async (formData: FormData) => {
|
||||
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = createTeamBillingService(client);
|
||||
const client = getSupabaseServerActionClient();
|
||||
const service = createTeamBillingService(client);
|
||||
|
||||
// get url to billing portal
|
||||
const url = await service.createBillingPortalSession(params);
|
||||
// get url to billing portal
|
||||
const url = await service.createBillingPortalSession(params);
|
||||
|
||||
return redirect(url);
|
||||
}
|
||||
return redirect(url);
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user