Skip to content

Commit

Permalink
Save token within sharing tab for now (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvargas92495 authored May 11, 2024
1 parent a4e972c commit 670a366
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
27 changes: 0 additions & 27 deletions scripts/buildComponents.js

This file was deleted.

44 changes: 44 additions & 0 deletions src/components/StaticSiteDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import { v4 } from "uuid";
import { getNodeEnv } from "roamjs-components/util/env";
import { z } from "zod";
import { render as renderToast } from "roamjs-components/components/Toast";
import getToken from "roamjs-components/util/getToken";
import localStorageSet from "roamjs-components/util/localStorageSet";

const DEFAULT_TEMPLATE = `<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -2706,6 +2708,47 @@ const RequestRedirectsContent: StageContent = ({ openPanel }) => {

type Sharing = { uuid: string; user: string; permission: string; date: string };

const LegacyRoamJSToken = () => {
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
const roamjsToken = getToken();
if (inputRef.current && roamjsToken) {
inputRef.current.value = roamjsToken;
}
}, []);
return (
<div className="flex justify-between items-center">
<InputGroup defaultValue="" inputRef={inputRef} type="password" />
<Button
text={"Save RoamJS Token"}
onClick={() => {
try {
const token = inputRef.current?.value;
if (token) {
const normalizedToken =
token.length <= 20 ? token : window.atob(token).split(":")[1];
localStorageSet("token", normalizedToken);
renderToast({
content: "Saved token",
intent: "success",
id: "roamjs-token-success",
});
} else {
throw new Error("No token to save");
}
} catch (e) {
renderToast({
content: `Error saving token: ${(e as Error).message}`,
intent: "danger",
id: "roamjs-token-error",
});
}
}}
/>
</div>
);
};

const RequestSharingContent: StageContent = ({ openPanel }) => {
const nextStage = useServiceNextStage(openPanel);
const [loading, setLoading] = useState(true);
Expand Down Expand Up @@ -2826,6 +2869,7 @@ const RequestSharingContent: StageContent = ({ openPanel }) => {
</>
)}
</div>
<LegacyRoamJSToken />
<ServiceNextButton onClick={onSubmit} />
</div>
);
Expand Down

0 comments on commit 670a366

Please sign in to comment.