Skip to content

Commit 433b300

Browse files
committed
add force save func
1 parent 2641f7f commit 433b300

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

apps/web/app/routes/ws/settings/general.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ export default function GeneralSettingsPage() {
3030
slug?: string;
3131
}>({});
3232

33-
const utils = trpc.useUtils();
33+
const saveWorkspace = trpc.workspace.save.useMutation({
34+
onSuccess: () => {
35+
toast.success("Workspace saved sucessfully");
36+
},
37+
onError: (error: unknown) => {
38+
const message =
39+
error instanceof Error ? error.message : "Failed to update workspace";
40+
toast.error(message);
41+
},
42+
});
43+
3444
const updateWorkspace = trpc.workspace.update.useMutation({
3545
onSuccess: () => {
3646
toast.success("Workspace updated successfully");
37-
// Invalidate the user session to refetch the updated workspace info
38-
void utils.user.session.invalidate();
3947
},
4048
onError: (error: unknown) => {
4149
const message =
@@ -167,6 +175,22 @@ export default function GeneralSettingsPage() {
167175
</form>
168176
</CardContent>
169177
</Card>
178+
179+
<Card>
180+
<CardHeader>
181+
<CardTitle>Workspace Information</CardTitle>
182+
<CardDescription>
183+
Update your workspace name and URL slug
184+
</CardDescription>
185+
</CardHeader>
186+
<CardContent>
187+
<Button
188+
onClick={() => saveWorkspace.mutate({ workspaceId: workspace.id })}
189+
>
190+
Force Save Workspace
191+
</Button>
192+
</CardContent>
193+
</Card>
170194
</div>
171195
);
172196
}

packages/events/src/kafka/events.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type * as schema from "@ctrlplane/db/schema";
22
import type { WorkspaceEngine } from "@ctrlplane/workspace-engine-sdk";
33

44
export enum Event {
5+
WorkspaceSave = "workspace.save",
6+
57
SystemCreated = "system.created",
68
SystemUpdated = "system.updated",
79
SystemDeleted = "system.deleted",
@@ -159,6 +161,7 @@ export type EventPayload = {
159161
};
160162

161163
export type GoEventPayload = {
164+
[Event.WorkspaceSave]: object;
162165
[Event.SystemCreated]: WorkspaceEngine["schemas"]["System"];
163166
[Event.SystemUpdated]: WorkspaceEngine["schemas"]["System"];
164167
[Event.SystemDeleted]: WorkspaceEngine["schemas"]["System"];

packages/trpc/src/routes/workspace.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ import { z } from "zod";
33

44
import { eq, takeFirst, takeFirstOrNull } from "@ctrlplane/db";
55
import * as schema from "@ctrlplane/db/schema";
6+
import { Event, sendGoEvent } from "@ctrlplane/events";
67
import { Permission } from "@ctrlplane/validators/auth";
78

89
import { protectedProcedure, router } from "../trpc.js";
910

1011
export const workspaceRouter = router({
12+
save: protectedProcedure
13+
.input(z.object({ workspaceId: z.uuid() }))
14+
.mutation(async ({ input }) => {
15+
await sendGoEvent({
16+
workspaceId: input.workspaceId,
17+
eventType: Event.WorkspaceSave,
18+
timestamp: Date.now(),
19+
data: {},
20+
});
21+
return true;
22+
}),
23+
1124
get: protectedProcedure
1225
.meta({
1326
authorizationCheck: ({ canUser, input }) =>

0 commit comments

Comments
 (0)