refactor(app-actions): correctly revalidatePath after each action
This commit is contained in:
parent
900c31ec19
commit
1d8f608936
6 changed files with 36 additions and 48 deletions
|
@ -1,7 +1,6 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { action } from '@/lib/safe-action';
|
import { action } from '@/lib/safe-action';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
||||||
|
@ -19,16 +18,15 @@ const input = z.object({
|
||||||
*/
|
*/
|
||||||
export const installAppAction = action(input, async ({ id, form }) => {
|
export const installAppAction = action(input, async ({ id, form }) => {
|
||||||
try {
|
try {
|
||||||
const appsService = new AppServiceClass(db);
|
const appsService = new AppServiceClass();
|
||||||
|
|
||||||
await appsService.installApp(id, form);
|
await appsService.installApp(id, form);
|
||||||
|
|
||||||
revalidatePath('/apps');
|
|
||||||
revalidatePath(`/app/${id}`);
|
|
||||||
revalidatePath(`/app-store/${id}`);
|
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return handleActionError(e);
|
return await handleActionError(e);
|
||||||
|
} finally {
|
||||||
|
revalidatePath('/apps');
|
||||||
|
revalidatePath(`/app/${id}`);
|
||||||
|
revalidatePath(`/app-store/${id}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { action } from '@/lib/safe-action';
|
import { action } from '@/lib/safe-action';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
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 }) => {
|
export const startAppAction = action(input, async ({ id }) => {
|
||||||
try {
|
try {
|
||||||
const appsService = new AppServiceClass(db);
|
const appsService = new AppServiceClass();
|
||||||
|
|
||||||
await appsService.startApp(id);
|
await appsService.startApp(id);
|
||||||
|
|
||||||
revalidatePath('/apps');
|
|
||||||
revalidatePath(`/app/${id}`);
|
|
||||||
revalidatePath(`/app-store/${id}`);
|
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return handleActionError(e);
|
return await handleActionError(e);
|
||||||
|
} finally {
|
||||||
|
revalidatePath('/apps');
|
||||||
|
revalidatePath(`/app/${id}`);
|
||||||
|
revalidatePath(`/app-store/${id}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { action } from '@/lib/safe-action';
|
import { action } from '@/lib/safe-action';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
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 }) => {
|
export const stopAppAction = action(input, async ({ id }) => {
|
||||||
try {
|
try {
|
||||||
const appsService = new AppServiceClass(db);
|
const appsService = new AppServiceClass();
|
||||||
|
|
||||||
await appsService.stopApp(id);
|
await appsService.stopApp(id);
|
||||||
|
|
||||||
revalidatePath('/apps');
|
|
||||||
revalidatePath(`/app/${id}`);
|
|
||||||
revalidatePath(`/app-store/${id}`);
|
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return handleActionError(e);
|
return await handleActionError(e);
|
||||||
|
} finally {
|
||||||
|
revalidatePath('/apps');
|
||||||
|
revalidatePath(`/app/${id}`);
|
||||||
|
revalidatePath(`/app-store/${id}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { action } from '@/lib/safe-action';
|
import { action } from '@/lib/safe-action';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
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 }) => {
|
export const uninstallAppAction = action(input, async ({ id }) => {
|
||||||
try {
|
try {
|
||||||
const appsService = new AppServiceClass(db);
|
const appsService = new AppServiceClass();
|
||||||
|
|
||||||
await appsService.uninstallApp(id);
|
await appsService.uninstallApp(id);
|
||||||
|
|
||||||
revalidatePath('/apps');
|
|
||||||
revalidatePath(`/app/${id}`);
|
|
||||||
revalidatePath(`/app-store/${id}`);
|
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return handleActionError(e);
|
return await handleActionError(e);
|
||||||
|
} finally {
|
||||||
|
revalidatePath('/apps');
|
||||||
|
revalidatePath(`/app/${id}`);
|
||||||
|
revalidatePath(`/app-store/${id}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { action } from '@/lib/safe-action';
|
import { action } from '@/lib/safe-action';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
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 }) => {
|
export const updateAppAction = action(input, async ({ id }) => {
|
||||||
try {
|
try {
|
||||||
const appsService = new AppServiceClass(db);
|
const appsService = new AppServiceClass();
|
||||||
|
|
||||||
await appsService.updateApp(id);
|
await appsService.updateApp(id);
|
||||||
|
|
||||||
revalidatePath('/apps');
|
|
||||||
revalidatePath(`/app/${id}`);
|
|
||||||
revalidatePath(`/app-store/${id}`);
|
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return handleActionError(e);
|
return await handleActionError(e);
|
||||||
|
} finally {
|
||||||
|
revalidatePath('/apps');
|
||||||
|
revalidatePath(`/app/${id}`);
|
||||||
|
revalidatePath(`/app-store/${id}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { action } from '@/lib/safe-action';
|
import { action } from '@/lib/safe-action';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
import { AppServiceClass } from '@/server/services/apps/apps.service';
|
||||||
|
@ -21,16 +20,15 @@ const input = z.object({
|
||||||
*/
|
*/
|
||||||
export const updateAppConfigAction = action(input, async ({ id, form }) => {
|
export const updateAppConfigAction = action(input, async ({ id, form }) => {
|
||||||
try {
|
try {
|
||||||
const appsService = new AppServiceClass(db);
|
const appsService = new AppServiceClass();
|
||||||
|
|
||||||
await appsService.updateAppConfig(id, form);
|
await appsService.updateAppConfig(id, form);
|
||||||
|
|
||||||
revalidatePath('/apps');
|
|
||||||
revalidatePath(`/app/${id}`);
|
|
||||||
revalidatePath(`/app-store/${id}`);
|
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return handleActionError(e);
|
return await handleActionError(e);
|
||||||
|
} finally {
|
||||||
|
revalidatePath('/apps');
|
||||||
|
revalidatePath(`/app/${id}`);
|
||||||
|
revalidatePath(`/app-store/${id}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue