diff --git a/site/src/api/queries/deployment.ts b/site/src/api/queries/deployment.ts index f74e120688709..0d095258c50e2 100644 --- a/site/src/api/queries/deployment.ts +++ b/site/src/api/queries/deployment.ts @@ -13,3 +13,10 @@ export const deploymentDAUs = () => { queryFn: () => API.getDeploymentDAUs(), }; }; + +export const deploymentStats = () => { + return { + queryKey: ["deployment", "stats"], + queryFn: () => API.getDeploymentStats(), + }; +}; diff --git a/site/src/components/Dashboard/DeploymentBanner/DeploymentBanner.tsx b/site/src/components/Dashboard/DeploymentBanner/DeploymentBanner.tsx index 16b64d061543d..2d5cab0fe4637 100644 --- a/site/src/components/Dashboard/DeploymentBanner/DeploymentBanner.tsx +++ b/site/src/components/Dashboard/DeploymentBanner/DeploymentBanner.tsx @@ -1,20 +1,20 @@ -import { useMachine } from "@xstate/react"; import { usePermissions } from "hooks/usePermissions"; import { DeploymentBannerView } from "./DeploymentBannerView"; -import { deploymentStatsMachine } from "xServices/deploymentStats/deploymentStatsMachine"; +import { useQuery } from "@tanstack/react-query"; +import { deploymentStats } from "api/queries/deployment"; export const DeploymentBanner: React.FC = () => { const permissions = usePermissions(); - const [state, sendEvent] = useMachine(deploymentStatsMachine); + const deploymentStatsQuery = useQuery(deploymentStats()); - if (!permissions.viewDeploymentValues || !state.context.deploymentStats) { + if (!permissions.viewDeploymentValues || !deploymentStatsQuery.data) { return null; } return ( sendEvent("RELOAD")} + stats={deploymentStatsQuery.data} + fetchStats={() => deploymentStatsQuery.refetch()} /> ); }; diff --git a/site/src/xServices/deploymentStats/deploymentStatsMachine.ts b/site/src/xServices/deploymentStats/deploymentStatsMachine.ts deleted file mode 100644 index 6301764af4d03..0000000000000 --- a/site/src/xServices/deploymentStats/deploymentStatsMachine.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { getDeploymentStats } from "api/api"; -import { DeploymentStats } from "api/typesGenerated"; -import { assign, createMachine } from "xstate"; - -export const deploymentStatsMachine = createMachine( - { - /** @xstate-layout N4IgpgJg5mDOIC5QTABwDYHsCeBbMAdgC4DKRAhkbALLkDGAFgJYFgB0sFVAxBJq2xYA3TAGt2KDDnzEylGvWYDO8hMMx1KTfgG0ADAF19BxKFSZYTItoKmQAD0QBWAMwuANCGyIATAHYATgBfIM9JLDxCUi4FRhZ2FR4wACdkzGS2DEoAM3TcNnDpKLkqWjjlGLUCEU1rXUNjO3NLOtskB0QAvU9vBAAWVxCwtAiZaPkypXYmCHQwbgAlAFEAGQB5AEEAEUb25qsbO0cEAEY9AA4exDOANhDQkAJMFHh2wsjZGMn4posD-iOiD6Piup3ObCcQxA7zGJViUw4MV+LUO7WOfT03S81xOLihMOKX0U8UEszAyP+bVAxxc5z6oJ8AT6EPuQSAA */ - id: "deploymentStatsMachine", - predictableActionArguments: true, - - schema: { - context: {} as { - deploymentStats?: DeploymentStats; - getDeploymentStatsError?: unknown; - }, - events: {} as { type: "RELOAD" }, - services: {} as { - getDeploymentStats: { - data: DeploymentStats; - }; - }, - }, - tsTypes: {} as import("./deploymentStatsMachine.typegen").Typegen0, - initial: "stats", - states: { - stats: { - invoke: { - src: "getDeploymentStats", - onDone: { - target: "idle", - actions: ["assignDeploymentStats"], - }, - onError: { - target: "idle", - actions: ["assignDeploymentStatsError"], - }, - }, - tags: "loading", - }, - idle: { - on: { - RELOAD: "stats", - }, - }, - }, - }, - { - services: { - getDeploymentStats: getDeploymentStats, - }, - actions: { - assignDeploymentStats: assign({ - deploymentStats: (_, { data }) => data, - }), - assignDeploymentStatsError: assign({ - getDeploymentStatsError: (_, { data }) => data, - }), - }, - }, -);