-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.tsx
More file actions
57 lines (50 loc) · 1.75 KB
/
index.tsx
File metadata and controls
57 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { useRouter, useSearchParams, usePathname } from "next/navigation";
import { useEffect, useState } from "react";
export default function Index() {
const [data, setData] = useState("");
const router = useRouter();
const searchParams = useSearchParams();
const pathname = usePathname();
const appSlug = searchParams?.get("appSlug");
const userId = searchParams?.get("userId");
useEffect(() => {
let isRedirectNeeded = false;
const newSearchParams = new URLSearchParams(new URL(document.URL).searchParams);
if (!userId) {
newSearchParams.set("userId", "1");
isRedirectNeeded = true;
}
if (!appSlug) {
newSearchParams.set("appSlug", "google-calendar");
isRedirectNeeded = true;
}
if (isRedirectNeeded) {
router.push(`${pathname}?${newSearchParams.toString()}`);
}
}, [router, pathname, userId, appSlug]);
async function updateToken({ invalid } = { invalid: false }) {
const res = await fetch(
`/api/setTokenInCalCom?invalid=${invalid ? 1 : 0}&userId=${userId}&appSlug=${appSlug}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
const data = await res.json();
setData(JSON.stringify(data));
}
return (
<div>
<h1>Welcome to Credential Sync Playground</h1>
<p>
You are managing credentials for cal.com <strong>userId={userId}</strong> for{" "}
<strong>appSlug={appSlug}</strong>. Update query params to manage a different user or app{" "}
</p>
<button onClick={() => updateToken({ invalid: true })}>Give an invalid token to Cal.com</button>
<button onClick={() => updateToken()}>Give a valid token to Cal.com</button>
<div>{data}</div>
</div>
);
}