diff --git a/pkgs/clan-app/ui/src/hooks/queries.ts b/pkgs/clan-app/ui/src/hooks/queries.ts index 83d6cd14c..b276f826d 100644 --- a/pkgs/clan-app/ui/src/hooks/queries.ts +++ b/pkgs/clan-app/ui/src/hooks/queries.ts @@ -182,3 +182,43 @@ export const useSystemStorageOptions = (): SystemStorageOptionsQuery => { }, })); }; + +export type MachineHardwareSummary = + SuccessData<"get_machine_hardware_summary">; +export type MachineHardwareSummaryQuery = + UseQueryResult; + +export const useMachineHardwareSummary = ( + clanUri: string, + machineName: string, +): MachineHardwareSummaryQuery => { + const client = useApiClient(); + return useQuery(() => ({ + queryKey: [ + "clans", + encodeBase64(clanUri), + "machines", + machineName, + "hardware_summary", + ], + queryFn: async () => { + const call = client.fetch("get_machine_hardware_summary", { + machine: { + flake: { + identifier: clanUri, + }, + name: machineName, + }, + }); + const result = await call.result; + + if (result.status === "error") { + // todo should we create some specific error types? + console.error("Error fetching clan details:", result.errors); + throw new Error(result.errors[0].message); + } + + return result.data; + }, + })); +};