Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/NavBar/WebhookStoreUrl/WebhookStoreUrl.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { Label } from "@pluralsight/ps-design-system-text";
import TextInput from "@pluralsight/ps-design-system-textinput";
import React, { useContext } from "react";
import { WebhookStoreUrlContext } from "./WebhookStoreUrl.context";
import NavItem from "@pluralsight/ps-design-system-navitem";

export function WebhookStoreUrlInput() {
const { value, setValue } = useContext(WebhookStoreUrlContext);
return (
<>
<NavItem key={"WebhookStoreUrlInput"}>
<Label
size={Label.sizes.xSmall}
style={{ marginRight: "8px", marginLeft: "8px" }}
Expand All @@ -22,6 +23,6 @@ export function WebhookStoreUrlInput() {
setValue(new URL(event.target.value).origin);
}}
></TextInput>
</>
</NavItem>
);
}
6 changes: 3 additions & 3 deletions src/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import NavItem from "@pluralsight/ps-design-system-navitem";
import { ProxyStatus } from "./NavBar/ProxyStatus/ProxyStatus.component";
import { LoginOrDisplayUser } from "./NavBar/User/LoginOrDisplayUser";
import { StoreConfigNavItem } from "./NavBar/StoreConfig/StoreConfigNavItem";
import { ENVIRONMENT_KEY } from "./local-storage";

function SkillsLogo() {
return (
Expand Down Expand Up @@ -66,13 +67,12 @@ function SkillsBranding(props: any) {
}

export default function TopNav() {
const isDevEnv = localStorage.getItem(ENVIRONMENT_KEY) === "development";
return (
<NavBar
brand={<SkillsBranding />}
items={[
<NavItem key={"WebhookStoreUrlInput"}>
<WebhookStoreUrlInput />
</NavItem>,
isDevEnv ? <WebhookStoreUrlInput key={"WebhookStoreUrlInput"} /> : null,
<ProxyStatus key={"ProxyStatus"} />,
<StoreConfigNavItem key={"StoreConfig"} />,
]}
Expand Down
1 change: 1 addition & 0 deletions src/local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const IDENTITY_TOKEN_KEY = "identityToken";
export const ACCESS_TOKEN_KEY = "accessToken";
export const ENVIRONMENT_KEY = "environment";
14 changes: 13 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import App from "./App";
import Honeybadger from "@honeybadger-io/js";
import { HoneybadgerErrorBoundary } from "@honeybadger-io/react";
import posthog from "posthog-js";
import { ENVIRONMENT_KEY } from "./local-storage";

const autoRedirectOnGithubAuth =
window.location.hostname === "github.webhook.store";
Expand All @@ -21,7 +22,18 @@ posthog.init(import.meta.env.VITE_POSTHOG_API_KEY as string, {
api_host: "https://app.posthog.com",
});

posthog.capture("my event", { property: "value" });
const initEnvInLocalStorage = () => {
const env = localStorage.getItem(ENVIRONMENT_KEY);
if (!env) {
if (window.location.origin.startsWith("http://localhost:")) {
localStorage.setItem(ENVIRONMENT_KEY, "development");
} else {
localStorage.setItem(ENVIRONMENT_KEY, "production");
}
}
};

initEnvInLocalStorage();

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
Expand Down