2023-02-22 11:23:04 +00:00
|
|
|
import { NextPage } from "next";
|
|
|
|
import React, { useEffect } from "react";
|
|
|
|
import { NoProvidersConfigured } from "../../ui/no-providers-configured";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { DatadogConfig } from "../../ui/datadog/datadog-config";
|
|
|
|
import { DatadogSite, useConfigQuery } from "../../../generated/graphql";
|
2023-06-27 17:20:58 +00:00
|
|
|
import { useAppBridge } from "@saleor/app-sdk/app-bridge";
|
2023-02-22 11:23:04 +00:00
|
|
|
import { DATADOG_SITES_LINKS } from "../../datadog-urls";
|
2023-06-27 17:20:58 +00:00
|
|
|
import { Box, Button, Text } from "@saleor/macaw-ui/next";
|
|
|
|
import { Breadcrumbs, TextLink } from "@saleor/apps-ui";
|
2023-02-22 11:23:04 +00:00
|
|
|
|
|
|
|
const useActiveProvider = () => {
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const selectedProvider = router.query?.path && router.query.path[0];
|
|
|
|
|
|
|
|
return selectedProvider ?? null;
|
|
|
|
};
|
|
|
|
|
2023-06-27 17:20:58 +00:00
|
|
|
const ConfigurationPage = () => {
|
2023-02-22 11:23:04 +00:00
|
|
|
const [configuration, fetchConfiguration] = useConfigQuery();
|
|
|
|
const { appBridge } = useAppBridge();
|
|
|
|
|
|
|
|
const datadogCredentials = configuration.data?.integrations.datadog?.credentials;
|
|
|
|
const datadogError = configuration.data?.integrations.datadog?.error;
|
|
|
|
|
2023-06-27 17:20:58 +00:00
|
|
|
const { push } = useRouter();
|
|
|
|
|
2023-02-22 11:23:04 +00:00
|
|
|
useEffect(() => {
|
|
|
|
fetchConfiguration();
|
|
|
|
}, [fetchConfiguration]);
|
|
|
|
|
|
|
|
const selectedProvider = useActiveProvider();
|
|
|
|
|
|
|
|
if (configuration.fetching && !configuration.data) {
|
2023-06-27 17:20:58 +00:00
|
|
|
return <Text>Loading...</Text>;
|
2023-02-22 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedProvider === "datadog") {
|
|
|
|
return <DatadogConfig />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!configuration.data?.integrations.datadog) {
|
|
|
|
return <NoProvidersConfigured />;
|
|
|
|
}
|
|
|
|
|
|
|
|
// when configured and everything is fine
|
|
|
|
if (datadogCredentials && !datadogError) {
|
|
|
|
const site = configuration.data?.integrations.datadog?.credentials.site ?? DatadogSite.Us1;
|
|
|
|
|
|
|
|
return (
|
2023-06-27 17:20:58 +00:00
|
|
|
<Box display={"flex"} gap={4} flexDirection={"column"}>
|
|
|
|
<Text as={"h1"} variant="heading">
|
2023-02-22 11:23:04 +00:00
|
|
|
App configured
|
2023-06-27 17:20:58 +00:00
|
|
|
</Text>
|
|
|
|
<Text as={"p"}>
|
2023-02-22 11:23:04 +00:00
|
|
|
Visit{" "}
|
2023-06-27 17:20:58 +00:00
|
|
|
<TextLink newTab href={DATADOG_SITES_LINKS[site] ?? "https://app.datadoghq.com/"}>
|
2023-02-22 11:23:04 +00:00
|
|
|
Datadog
|
2023-06-27 17:20:58 +00:00
|
|
|
</TextLink>{" "}
|
2023-02-22 11:23:04 +00:00
|
|
|
to access your logs
|
2023-06-27 17:20:58 +00:00
|
|
|
</Text>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
push("/configuration/datadog");
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Edit configuration
|
|
|
|
</Button>
|
|
|
|
</Box>
|
2023-02-22 11:23:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (datadogError) {
|
|
|
|
return (
|
2023-06-27 17:20:58 +00:00
|
|
|
<Box>
|
|
|
|
<Text variant="heading" as={"h1"}>
|
2023-02-22 11:23:04 +00:00
|
|
|
Configuration Error
|
2023-06-27 17:20:58 +00:00
|
|
|
</Text>
|
|
|
|
<Text color={"textCriticalDefault"}>{datadogError}</Text>
|
|
|
|
<Button
|
|
|
|
marginTop={8}
|
|
|
|
onClick={() => {
|
|
|
|
push("/configuration/datadog");
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Edit configuration
|
|
|
|
</Button>
|
|
|
|
</Box>
|
2023-02-22 11:23:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ConfigurationPage;
|