refactor(app-actions): correctly revalidatePath after each action

This commit is contained in:
Nicolas Meienberger 2023-11-12 12:30:32 +01:00
parent 900c31ec19
commit 1d8f608936
6 changed files with 36 additions and 48 deletions

View file

@ -1,7 +1,6 @@
'use server';
import { z } from 'zod';
import { db } from '@/server/db';
import { action } from '@/lib/safe-action';
import { revalidatePath } from 'next/cache';
import { AppServiceClass } from '@/server/services/apps/apps.service';
@ -19,16 +18,15 @@ const input = z.object({
*/
export const installAppAction = action(input, async ({ id, form }) => {
try {
const appsService = new AppServiceClass(db);
const appsService = new AppServiceClass();
await appsService.installApp(id, form);
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
return { success: true };
} catch (e) {
return handleActionError(e);
return await handleActionError(e);
} finally {
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
}
});

View file

@ -1,7 +1,6 @@
'use server';
import { z } from 'zod';
import { db } from '@/server/db';
import { action } from '@/lib/safe-action';
import { revalidatePath } from 'next/cache';
import { AppServiceClass } from '@/server/services/apps/apps.service';
@ -14,16 +13,15 @@ const input = z.object({ id: z.string() });
*/
export const startAppAction = action(input, async ({ id }) => {
try {
const appsService = new AppServiceClass(db);
const appsService = new AppServiceClass();
await appsService.startApp(id);
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
return { success: true };
} catch (e) {
return handleActionError(e);
return await handleActionError(e);
} finally {
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
}
});

View file

@ -1,7 +1,6 @@
'use server';
import { z } from 'zod';
import { db } from '@/server/db';
import { action } from '@/lib/safe-action';
import { revalidatePath } from 'next/cache';
import { AppServiceClass } from '@/server/services/apps/apps.service';
@ -14,16 +13,15 @@ const input = z.object({ id: z.string() });
*/
export const stopAppAction = action(input, async ({ id }) => {
try {
const appsService = new AppServiceClass(db);
const appsService = new AppServiceClass();
await appsService.stopApp(id);
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
return { success: true };
} catch (e) {
return handleActionError(e);
return await handleActionError(e);
} finally {
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
}
});

View file

@ -1,7 +1,6 @@
'use server';
import { z } from 'zod';
import { db } from '@/server/db';
import { action } from '@/lib/safe-action';
import { revalidatePath } from 'next/cache';
import { AppServiceClass } from '@/server/services/apps/apps.service';
@ -14,16 +13,15 @@ const input = z.object({ id: z.string() });
*/
export const uninstallAppAction = action(input, async ({ id }) => {
try {
const appsService = new AppServiceClass(db);
const appsService = new AppServiceClass();
await appsService.uninstallApp(id);
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
return { success: true };
} catch (e) {
return handleActionError(e);
return await handleActionError(e);
} finally {
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
}
});

View file

@ -1,7 +1,6 @@
'use server';
import { z } from 'zod';
import { db } from '@/server/db';
import { action } from '@/lib/safe-action';
import { revalidatePath } from 'next/cache';
import { AppServiceClass } from '@/server/services/apps/apps.service';
@ -14,16 +13,15 @@ const input = z.object({ id: z.string() });
*/
export const updateAppAction = action(input, async ({ id }) => {
try {
const appsService = new AppServiceClass(db);
const appsService = new AppServiceClass();
await appsService.updateApp(id);
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
return { success: true };
} catch (e) {
return handleActionError(e);
return await handleActionError(e);
} finally {
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
}
});

View file

@ -1,7 +1,6 @@
'use server';
import { z } from 'zod';
import { db } from '@/server/db';
import { action } from '@/lib/safe-action';
import { revalidatePath } from 'next/cache';
import { AppServiceClass } from '@/server/services/apps/apps.service';
@ -21,16 +20,15 @@ const input = z.object({
*/
export const updateAppConfigAction = action(input, async ({ id, form }) => {
try {
const appsService = new AppServiceClass(db);
const appsService = new AppServiceClass();
await appsService.updateAppConfig(id, form);
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
return { success: true };
} catch (e) {
return handleActionError(e);
return await handleActionError(e);
} finally {
revalidatePath('/apps');
revalidatePath(`/app/${id}`);
revalidatePath(`/app-store/${id}`);
}
});