Files
Edu/apps/admin-portal/src/hooks/use-system-settings.ts
SpecialX b3511910d1 feat(admin-portal): 完整实现 admin-portal 管理端微前端
包含 src 全部实现、Dockerfile、配置文件等
2026-07-10 19:09:12 +08:00

49 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 系统设置 Hooks
*
* contract §2.4systemSettings / 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;
}