Skip to content

Commit dd5c5be

Browse files
committed
feature: get store config data
1 parent 1f8d82c commit dd5c5be

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/NavBar/StoreConfig/StoreConfigNavItem.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { StoreConfigInnerDialog } from "./StoreConfigDialog";
77
import Dialog from "@pluralsight/ps-design-system-dialog";
88
import useFetch from "use-http";
99
import { WebhookStoreUrlContext } from "../WebhookStoreUrl/WebhookStoreUrl.context";
10-
import { IDENTITY_TOKEN_KEY } from "../../local-storage";
10+
import { ACCESS_TOKEN_KEY, IDENTITY_TOKEN_KEY } from "../../local-storage";
1111
import { decodeJWT } from "../../utils/decode-jwt";
1212

1313
export const StoreConfigNavItem = () => {
@@ -16,23 +16,36 @@ export const StoreConfigNavItem = () => {
1616
const [authConfig, setAuthConfig] = useState<{ protected: boolean }>({
1717
protected: false,
1818
});
19+
const [storeConfig, setStoreConfig] = useState<{
20+
maxNumberOfWebhookPerHost?: number;
21+
defaultTarget?: string[];
22+
}>({});
1923

2024
const { value: webhookStoreUrl } = useContext(WebhookStoreUrlContext);
21-
const { get, response } = useFetch(webhookStoreUrl);
25+
const accessToken = localStorage.getItem(ACCESS_TOKEN_KEY);
26+
const { get, response } = useFetch(webhookStoreUrl, {
27+
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
28+
});
2229
const idToken = localStorage.getItem(IDENTITY_TOKEN_KEY);
2330
const identityToken =
2431
idToken &&
2532
decodeJWT<{ name: string; ghOrganisations: string[] }, any>(idToken);
2633

2734
useEffect(() => {
2835
getAuthConfig();
36+
getStoreConfig();
2937
}, []);
3038

3139
async function getAuthConfig() {
3240
const initialiseAuthConfig = await get("auth-metadata");
3341
if (response.ok) setAuthConfig(initialiseAuthConfig);
3442
}
3543

44+
async function getStoreConfig() {
45+
const initialiseStoreConfig = await get("store-metadata");
46+
if (response.ok) setStoreConfig(initialiseStoreConfig);
47+
}
48+
3649
const accessConfig = {
3750
type: authConfig.protected ? "private" : "public",
3851
sublabel: authConfig.protected ? "Only you" : "Anyone with the link",
@@ -54,8 +67,8 @@ export const StoreConfigNavItem = () => {
5467
display: "github.webhook.store",
5568
},
5669
];
57-
const defaultTargets = ["https://google.com", "https://google.com"];
58-
const storageLimit = 100;
70+
const defaultTargets = storeConfig.defaultTarget;
71+
const storageLimit = storeConfig.maxNumberOfWebhookPerHost;
5972

6073
return (
6174
<Below

src/apollo.client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const getAccessToken = async (
7777
}
7878
);
7979
const json = await accessTokenRequest.json();
80+
if (json.statusCode > 300) {
81+
console.error("Cannot refresh token", json);
82+
throw new Error(json.message);
83+
}
8084
const accessToken = json.accessToken;
8185
localStorage.setItem(ACCESS_TOKEN_KEY, accessToken);
8286

0 commit comments

Comments
 (0)