feat(admin-portal): 完整实现 admin-portal 管理端微前端
包含 src 全部实现、Dockerfile、配置文件等
This commit is contained in:
48
apps/admin-portal/src/hooks/use-system-settings.ts
Normal file
48
apps/admin-portal/src/hooks/use-system-settings.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 系统设置 Hooks
|
||||
*
|
||||
* contract §2.4:systemSettings / updateSystemSettings
|
||||
*/
|
||||
import { useCallback } from "react";
|
||||
import { useGraphMutation, useGraphQuery } from "./use-graphql";
|
||||
import {
|
||||
SYSTEM_SETTINGS_QUERY,
|
||||
UPDATE_SYSTEM_SETTINGS_MUTATION,
|
||||
} from "@/lib/graphql-client";
|
||||
import type { SystemSettingsViewModel } from "@/types/view-models";
|
||||
|
||||
interface SystemSettingsResponse {
|
||||
systemSettings: SystemSettingsViewModel;
|
||||
}
|
||||
|
||||
interface UpdateSystemSettingsResponse {
|
||||
updateSystemSettings: {
|
||||
schoolName: string;
|
||||
schoolCode: string;
|
||||
academicYear: string;
|
||||
semester: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function useSystemSettings() {
|
||||
const result = useGraphQuery<SystemSettingsResponse>(SYSTEM_SETTINGS_QUERY);
|
||||
return {
|
||||
...result,
|
||||
data: result.data?.systemSettings ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function useUpdateSystemSettings() {
|
||||
const [run, state] = useGraphMutation<
|
||||
UpdateSystemSettingsResponse,
|
||||
{ input: Partial<SystemSettingsViewModel> }
|
||||
>(UPDATE_SYSTEM_SETTINGS_MUTATION);
|
||||
const update = useCallback(
|
||||
async (input: Partial<SystemSettingsViewModel>) => {
|
||||
const res = await run({ input });
|
||||
return res.data?.updateSystemSettings ?? null;
|
||||
},
|
||||
[run],
|
||||
);
|
||||
return [update, state] as const;
|
||||
}
|
||||
Reference in New Issue
Block a user