feat: add workspace settings manage
This commit is contained in:
parent
4e3fd9db64
commit
3dca8fc27c
@ -10,6 +10,7 @@ export type UserLoginInfo = NonNullable<AppRouterOutput['user']['info']>;
|
||||
interface UserState {
|
||||
info: UserLoginInfo | null;
|
||||
updateCurrentWorkspaceName: (name: string) => void;
|
||||
updateCurrentWorkspaceSettings: (settings: Record<string, any>) => void;
|
||||
}
|
||||
|
||||
export const useUserStore = createWithEqualityFn<UserState>()(
|
||||
@ -27,6 +28,21 @@ export const useUserStore = createWithEqualityFn<UserState>()(
|
||||
}
|
||||
});
|
||||
},
|
||||
updateCurrentWorkspaceSettings: (settings) => {
|
||||
set((state) => {
|
||||
const currentUserInfo = useUserStore.getState().info;
|
||||
if (!currentUserInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const workspace of state.info?.workspaces ?? []) {
|
||||
workspace.workspace.settings = {
|
||||
...workspace.workspace.settings,
|
||||
...settings,
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
})),
|
||||
shallow
|
||||
);
|
||||
@ -88,6 +104,7 @@ export function useCurrentWorkspaceSafe() {
|
||||
id: currentWorkspace.workspace.id,
|
||||
name: currentWorkspace.workspace.name,
|
||||
role: currentWorkspace.role,
|
||||
settings: currentWorkspace.workspace.settings,
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -19,6 +19,7 @@ export const workspaceDashboardLayoutSchema = z.object({
|
||||
export const workspaceSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
settings: z.record(z.string(), z.any()),
|
||||
});
|
||||
|
||||
export const userInfoSchema = z.object({
|
||||
|
@ -41,6 +41,7 @@ export const createUserSelect = {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
settings: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -26,6 +26,7 @@ import {
|
||||
} from '../../model/user.js';
|
||||
import { WorkspacesOnUsersModelSchema } from '../../prisma/zod/workspacesonusers.js';
|
||||
import { monitorManager } from '../../model/monitor/index.js';
|
||||
import { get, merge } from 'lodash-es';
|
||||
|
||||
export const workspaceRouter = router({
|
||||
create: protectProedure
|
||||
@ -236,6 +237,41 @@ export const workspaceRouter = router({
|
||||
|
||||
return list;
|
||||
}),
|
||||
updateSettings: workspaceAdminProcedure
|
||||
.meta(
|
||||
buildWorkspaceOpenapi({
|
||||
method: 'POST',
|
||||
path: '/{workspaceId}/updateSettings',
|
||||
})
|
||||
)
|
||||
.input(
|
||||
z.object({
|
||||
settings: z.object({}).passthrough(),
|
||||
})
|
||||
)
|
||||
.output(workspaceSchema)
|
||||
.mutation(async ({ input }) => {
|
||||
const { workspaceId, settings } = input;
|
||||
|
||||
const prev = await prisma.workspace.findUniqueOrThrow({
|
||||
where: {
|
||||
id: workspaceId,
|
||||
},
|
||||
select: {
|
||||
settings: true,
|
||||
},
|
||||
});
|
||||
|
||||
const res = await prisma.workspace.update({
|
||||
where: {
|
||||
id: workspaceId,
|
||||
},
|
||||
data: {
|
||||
settings: merge({}, prev.settings, settings),
|
||||
},
|
||||
});
|
||||
return res;
|
||||
}),
|
||||
invite: workspaceAdminProcedure
|
||||
.meta(
|
||||
buildWorkspaceOpenapi({
|
||||
|
Loading…
Reference in New Issue
Block a user