forked from dubinc/dub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
262 additions
and
157 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
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
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
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
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,11 @@ | ||
# `@dub/embed-react` | ||
|
||
`@dub/embed-react` is a library of React components that are used embed Dub's widget on third-party websites. | ||
|
||
## Installation | ||
|
||
To install the package, run: | ||
|
||
```bash | ||
pnpm i @dub/embed-react | ||
``` |
11 changes: 7 additions & 4 deletions
11
packages/widgets/package.json → packages/embeds/react/package.json
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
File renamed without changes.
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,48 @@ | ||
import { APP_DOMAIN } from "@dub/utils"; | ||
import { useEffect } from "react"; | ||
|
||
interface DubDashboardProps { | ||
linkToken: string; | ||
onTokenExpired?: () => void; | ||
url?: string; | ||
} | ||
|
||
const iframeStyles = { | ||
width: "100%", | ||
height: "100vh", | ||
border: "none", | ||
}; | ||
|
||
export const DubDashboard = ({ | ||
linkToken, | ||
onTokenExpired, | ||
url = `${APP_DOMAIN}/embed/dashboard`, | ||
}: DubDashboardProps) => { | ||
// Listen for messages from the iframe | ||
useEffect(() => { | ||
const handleMessage = (event: MessageEvent) => { | ||
if (event.origin !== APP_DOMAIN) { | ||
return; | ||
} | ||
|
||
if (event.data === "TOKEN_EXPIRED") { | ||
console.error("[Dub] Link token is expired."); | ||
onTokenExpired?.(); | ||
} | ||
}; | ||
|
||
window.addEventListener("message", handleMessage); | ||
|
||
return () => window.removeEventListener("message", handleMessage); | ||
}, [onTokenExpired]); | ||
|
||
// If no link token is provided | ||
if (!linkToken) { | ||
console.error("[Dub] A link token is required to embed the dashboard."); | ||
return null; | ||
} | ||
|
||
const dashboardUrl = `${url}?token=${linkToken}`; | ||
|
||
return <iframe src={dashboardUrl} style={iframeStyles} />; | ||
}; |
File renamed without changes.
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,16 @@ | ||
// TODO: | ||
// - Convert to TS | ||
// - Add a loading state | ||
// - Add a close button | ||
// - Inline embed (dashboard) | ||
// - Floating button + widget | ||
// - Open on a button click | ||
|
||
interface DubOptions { | ||
linkToken: string; | ||
widgetUrl: string; | ||
dashboardUrl: string; | ||
} | ||
|
||
// <DubDashboard /> | ||
// <DubWidget /> |
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,2 @@ | ||
export * from "./dashboard"; | ||
export * from "./widget"; |
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,3 @@ | ||
export const DubWidget = () => { | ||
return <div>Dub Widget</div>; | ||
}; |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
packages/widgets/tsup.config.ts → packages/embeds/react/tsup.config.ts
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
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.