Skip to content

chore(site): refactor deployment values service to react-query #9669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix errors
  • Loading branch information
BrunoQuaresma committed Sep 14, 2023
commit dd5cfbf3d711bd4419ff1006a2cbaf0b067d4cac
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { Stack } from "components/Stack/Stack";
import { Sidebar } from "./Sidebar";
import { createContext, Suspense, useContext, FC } from "react";
import { Loader } from "components/Loader/Loader";
import { DAUsResponse } from "api/typesGenerated";
import { RequirePermission } from "components/RequirePermission/RequirePermission";
import { usePermissions } from "hooks/usePermissions";
import { Outlet } from "react-router-dom";
import { DeploymentConfig } from "api/api";
import { useQuery } from "@tanstack/react-query";
import { deploymentConfig, deploymentDAUs } from "api/queries/deployment";
import { deploymentConfig } from "api/queries/deployment";

type DeploySettingsContextValue = {
deploymentValues: DeploymentConfig;
deploymentDAUs?: DAUsResponse;
};

const DeploySettingsContext = createContext<
Expand All @@ -33,7 +31,6 @@ export const useDeploySettings = (): DeploySettingsContextValue => {

export const DeploySettingsLayout: FC = () => {
const deploymentConfigQuery = useQuery(deploymentConfig());
const deploymentDAUsQuery = useQuery(deploymentDAUs());
const styles = useStyles();
const permissions = usePermissions();

Expand All @@ -43,11 +40,10 @@ export const DeploySettingsLayout: FC = () => {
<Stack className={styles.wrapper} direction="row" spacing={6}>
<Sidebar />
<main className={styles.content}>
{deploymentConfigQuery.data && deploymentDAUsQuery.data ? (
{deploymentConfigQuery.data ? (
<DeploySettingsContext.Provider
value={{
deploymentValues: deploymentConfigQuery.data,
deploymentDAUs: deploymentDAUsQuery.data,
}}
>
<Suspense fallback={<Loader />}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { FC } from "react";
import { Helmet } from "react-helmet-async";
import { pageTitle } from "utils/page";
import { GeneralSettingsPageView } from "./GeneralSettingsPageView";
import { useQuery } from "@tanstack/react-query";
import { deploymentDAUs } from "api/queries/deployment";

const GeneralSettingsPage: FC = () => {
const { deploymentValues, deploymentDAUs, getDeploymentDAUsError } =
useDeploySettings();
const { deploymentValues } = useDeploySettings();
const deploymentDAUsQuery = useQuery(deploymentDAUs());

return (
<>
Expand All @@ -15,8 +17,8 @@ const GeneralSettingsPage: FC = () => {
</Helmet>
<GeneralSettingsPageView
deploymentOptions={deploymentValues.options}
deploymentDAUs={deploymentDAUs}
getDeploymentDAUsError={getDeploymentDAUsError}
deploymentDAUs={deploymentDAUsQuery.data}
deploymentDAUsError={deploymentDAUsQuery.error}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const NoDAUs: Story = {
export const DAUError: Story = {
args: {
deploymentDAUs: undefined,
getDeploymentDAUsError: mockApiError({
deploymentDAUsError: mockApiError({
message: "Error fetching DAUs.",
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { DeploymentOption } from "api/api";
export type GeneralSettingsPageViewProps = {
deploymentOptions: DeploymentOption[];
deploymentDAUs?: DAUsResponse;
getDeploymentDAUsError: unknown;
deploymentDAUsError: unknown;
};
export const GeneralSettingsPageView = ({
deploymentOptions,
deploymentDAUs,
getDeploymentDAUsError,
deploymentDAUsError,
}: GeneralSettingsPageViewProps): JSX.Element => {
return (
<>
Expand All @@ -28,8 +28,8 @@ export const GeneralSettingsPageView = ({
docsHref={docs("/admin/configure")}
/>
<Stack spacing={4}>
{Boolean(getDeploymentDAUsError) && (
<ErrorAlert error={getDeploymentDAUsError} />
{Boolean(deploymentDAUsError) && (
<ErrorAlert error={deploymentDAUsError} />
)}
{deploymentDAUs && (
<Box height={200} sx={{ mb: 3 }}>
Expand Down