Skip to content

Commit 1f8d82c

Browse files
committed
feature: get data from store and display them
1 parent 6a047a0 commit 1f8d82c

5 files changed

Lines changed: 76 additions & 11 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"react": "^18.2.0",
5252
"react-dom": "^18.2.0",
5353
"react-github-btn": "^1.3.0",
54-
"react-table": "^7.7.0"
54+
"react-table": "^7.7.0",
55+
"use-http": "^1.0.27"
5556
},
5657
"devDependencies": {
5758
"@testing-library/jest-dom": "^5.16.5",

src/NavBar/StoreConfig/StoreConfigDialog.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@ export const StoreConfigInnerDialog = ({
1010
accessConfig,
1111
}: {
1212
availableStores: { url: string; display: string }[];
13-
accessConfig: { type: "public" | "private" };
13+
accessConfig: { type: "public" | "private"; sublabel: string };
1414
storageLimit?: number;
1515
defaultTargets?: string[];
1616
}) => {
17-
console.log(defaultTargets, accessConfig);
18-
const accessConfigSublabel =
19-
accessConfig.type === "public" ? "Anyone with the link" : "Only you";
2017
return (
2118
<>
2219
<Heading>
2320
<h1>Store Config</h1>
2421
</Heading>
2522
<div style={{ display: "flex" }}>
26-
<DataWell label="Access" subLabel={accessConfigSublabel}>
23+
<DataWell label="Access" subLabel={accessConfig.sublabel}>
2724
{accessConfig.type} {accessConfig.type === "public" ? "⚠️" : null}
2825
</DataWell>
2926
{storageLimit && (
30-
<DataWell label="Storage Limit">100 webhooks</DataWell>
27+
<DataWell label="Storage Limit">{storageLimit}</DataWell>
3128
)}
3229
{defaultTargets && (
3330
<DataWell label="Default Target">

src/NavBar/StoreConfig/StoreConfigNavItem.tsx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,59 @@
11
import { Label } from "@pluralsight/ps-design-system-text";
22
import { Below } from "@pluralsight/ps-design-system-position";
33

4-
import React, { useState } from "react";
4+
import React, { useContext, useEffect, useState } from "react";
55
import Button from "@pluralsight/ps-design-system-button";
66
import { StoreConfigInnerDialog } from "./StoreConfigDialog";
77
import Dialog from "@pluralsight/ps-design-system-dialog";
8+
import useFetch from "use-http";
9+
import { WebhookStoreUrlContext } from "../WebhookStoreUrl/WebhookStoreUrl.context";
10+
import { IDENTITY_TOKEN_KEY } from "../../local-storage";
11+
import { decodeJWT } from "../../utils/decode-jwt";
812

913
export const StoreConfigNavItem = () => {
1014
const [isClicked, setClicked] = useState<boolean>(false);
1115

12-
const accessConfig = { type: "public" } as const;
13-
const availableStores = [{ url: "https://google.com", display: "Google" }];
16+
const [authConfig, setAuthConfig] = useState<{ protected: boolean }>({
17+
protected: false,
18+
});
19+
20+
const { value: webhookStoreUrl } = useContext(WebhookStoreUrlContext);
21+
const { get, response } = useFetch(webhookStoreUrl);
22+
const idToken = localStorage.getItem(IDENTITY_TOKEN_KEY);
23+
const identityToken =
24+
idToken &&
25+
decodeJWT<{ name: string; ghOrganisations: string[] }, any>(idToken);
26+
27+
useEffect(() => {
28+
getAuthConfig();
29+
}, []);
30+
31+
async function getAuthConfig() {
32+
const initialiseAuthConfig = await get("auth-metadata");
33+
if (response.ok) setAuthConfig(initialiseAuthConfig);
34+
}
35+
36+
const accessConfig = {
37+
type: authConfig.protected ? "private" : "public",
38+
sublabel: authConfig.protected ? "Only you" : "Anyone with the link",
39+
} as const;
40+
const availableStores = identityToken
41+
? [
42+
{
43+
url: `https://${identityToken.payload.name}.github-org.webhook.store/?access_token=${idToken}`,
44+
display: `${identityToken.payload.name}.github-org.webhook.store`,
45+
},
46+
...identityToken.payload.ghOrganisations.map((orgName) => ({
47+
url: `https://${orgName}.github-org.webhook.store/?access_token=${idToken}`,
48+
display: `${orgName}.github-org.webhook.store`,
49+
})),
50+
]
51+
: [
52+
{
53+
url: "https://github.webhook.store",
54+
display: "github.webhook.store",
55+
},
56+
];
1457
const defaultTargets = ["https://google.com", "https://google.com"];
1558
const storageLimit = 100;
1659

src/NavBar/WebhookStoreUrl/WebhookStoreUrl.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function WebhookStoreUrlInput() {
1919
size={TextInput.sizes.small}
2020
defaultValue={value}
2121
onBlur={(event) => {
22-
setValue(event.target.value);
22+
setValue(new URL(event.target.value).origin);
2323
}}
2424
></TextInput>
2525
</>

yarn.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11322,6 +11322,25 @@ url@^0.11.0:
1132211322
punycode "1.3.2"
1132311323
querystring "0.2.0"
1132411324

11325+
urs@^0.0.8:
11326+
version "0.0.8"
11327+
resolved "https://registry.yarnpkg.com/urs/-/urs-0.0.8.tgz#8a0e0b792073cdb7eec926d08ab1e017ffab3f66"
11328+
integrity sha512-LaSSPpr91XrVA3vW2zPupw4K6DSQEDKdL4yQZX1mO2fpljIMpB5zctrjRvxLurelWSgKsHsCmfHNCImscryirQ==
11329+
11330+
use-http@^1.0.27:
11331+
version "1.0.27"
11332+
resolved "https://registry.yarnpkg.com/use-http/-/use-http-1.0.27.tgz#f0acdecebf7dd7f9f3218dc83a68239658b5d452"
11333+
integrity sha512-R2V3dzkx+YfIi3Sm35njGFRBzPEyM1AODMx6VSyHiyYzVVq2iYbA3HEjGK5fyw66D8stK5iaP4zU3X7LDmuiyg==
11334+
dependencies:
11335+
urs "^0.0.8"
11336+
use-ssr "^1.0.24"
11337+
utility-types "^3.10.0"
11338+
11339+
use-ssr@^1.0.24:
11340+
version "1.0.25"
11341+
resolved "https://registry.yarnpkg.com/use-ssr/-/use-ssr-1.0.25.tgz#c7f54b59d6e52db26749b1d4115a650101a190bd"
11342+
integrity sha512-VYF8kJKI+X7+U4XgGoUER2BUl0vIr+8OhlIhyldgSGE0KHMoDRXPvWeHUUeUktq7ACEOVLzXGq1+QRxcvtwvyQ==
11343+
1132511344
use@^3.1.0:
1132611345
version "3.1.1"
1132711346
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
@@ -11359,6 +11378,11 @@ utila@~0.4:
1135911378
resolved "https://registry.yarnpkg.com/utila/-/utila-0.4.0.tgz#8a16a05d445657a3aea5eecc5b12a4fa5379772c"
1136011379
integrity sha512-Z0DbgELS9/L/75wZbro8xAnT50pBVFQZ+hUEueGDU5FN51YSCYM+jdxsfCiHjwNP/4LCDD0i/graKpeBnOXKRA==
1136111380

11381+
utility-types@^3.10.0:
11382+
version "3.10.0"
11383+
resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.10.0.tgz#ea4148f9a741015f05ed74fd615e1d20e6bed82b"
11384+
integrity sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg==
11385+
1136211386
utils-merge@1.0.1:
1136311387
version "1.0.1"
1136411388
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"

0 commit comments

Comments
 (0)