-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from avidreder/add-sage-dev-page
Add sage dev page
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import StyledButton from "@components/library/styled-button"; | ||
import StyledCard from "@components/library/styled-card"; | ||
import StyledInput from "@components/library/styled-input"; | ||
import PoeAccountConnectedGaurdPanel from "@components/poe-account-connected-guard-panel"; | ||
import { localStorageJwtName } from "@contexts/user-context"; | ||
|
||
export default function SageDevelopment() { | ||
const [error, setError] = useState(""); | ||
const [isSuccess, setIsSuccess] = useState(false); | ||
const [key, setKey] = useState( | ||
typeof window === "undefined" | ||
? "" | ||
: localStorage.getItem(localStorageJwtName) | ||
); | ||
|
||
useEffect(() => { | ||
async function sendKeyToDevServer() { | ||
try { | ||
await fetch("http://localhost:8000/auth", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
token: key, | ||
}), | ||
}); | ||
setIsSuccess(true); | ||
} catch (e: unknown) { | ||
console.log(e); | ||
if (e instanceof Error) { | ||
setError(e.message); | ||
} | ||
} | ||
} | ||
if (key) { | ||
void sendKeyToDevServer(); | ||
} | ||
}, [key]); | ||
|
||
return ( | ||
<PoeAccountConnectedGaurdPanel> | ||
<div> | ||
<StyledCard title={"Auth Key"}> | ||
<div className="font-bold"> | ||
Syncing auth with your local PoeStack Sage | ||
</div> | ||
{isSuccess && ( | ||
<div className="font-bold text-green-600">Syncing successful!</div> | ||
)} | ||
{error && <div className="text-red-600">Error: {error}</div>} | ||
</StyledCard> | ||
</div> | ||
</PoeAccountConnectedGaurdPanel> | ||
); | ||
} |