|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import { Skeleton } from '@comp/ui/skeleton'; |
4 | 3 | import { DubEmbed } from '@dub/embed-react'; |
5 | | -import { useTheme } from 'next-themes'; |
6 | | -import { useEffect, useState } from 'react'; |
7 | | - |
8 | | -export const DubReferral = () => { |
9 | | - const [publicToken, setPublicToken] = useState(''); |
10 | | - const [error, setError] = useState<string | null>(null); |
11 | | - const [isLoading, setIsLoading] = useState(true); |
12 | | - const { theme } = useTheme(); |
13 | | - |
14 | | - useEffect(() => { |
15 | | - const fetchPublicToken = async () => { |
16 | | - try { |
17 | | - setIsLoading(true); |
18 | | - setError(null); |
19 | | - |
20 | | - const response = await fetch('/api/dub/embed-token'); |
21 | | - |
22 | | - if (!response.ok) { |
23 | | - throw new Error(`Failed to fetch token: ${response.status} ${response.statusText}`); |
24 | | - } |
25 | | - |
26 | | - const data = await response.json(); |
27 | | - |
28 | | - if (!data.publicToken) { |
29 | | - throw new Error('No public token received from server'); |
30 | | - } |
31 | | - |
32 | | - setPublicToken(data.publicToken); |
33 | | - } catch (err) { |
34 | | - console.error('Error fetching public token:', err); |
35 | | - setError(err instanceof Error ? err.message : 'An unexpected error occurred'); |
36 | | - } finally { |
37 | | - setIsLoading(false); |
38 | | - } |
39 | | - }; |
40 | | - |
41 | | - fetchPublicToken(); |
42 | | - }, []); |
43 | | - |
44 | | - if (isLoading) { |
45 | | - return ( |
46 | | - <div className="flex items-center justify-center"> |
47 | | - <Skeleton className="h-[100vh] w-full max-w-[1024px] rounded-none" /> |
48 | | - </div> |
49 | | - ); |
50 | | - } |
51 | | - |
52 | | - if (error) { |
53 | | - return ( |
54 | | - <div className="flex min-h-[400px] items-center justify-center"> |
55 | | - <div className="w-full max-w-md rounded-md border border-destructive/50 bg-destructive/10 p-6 text-center"> |
56 | | - <h3 className="mb-2 text-sm font-medium text-destructive">Oops, something went wrong</h3> |
57 | | - <p className="text-xs text-destructive/80">{error}</p> |
58 | | - <p className="mt-4 text-xs text-muted-foreground"> |
59 | | - Please refresh the page and try again. If the problem persists,{' '} |
60 | | - <a |
61 | | - href="https://discord.gg/compai" |
62 | | - target="_blank" |
63 | | - rel="noopener noreferrer" |
64 | | - className="underline underline-offset-2 hover:text-foreground transition-colors" |
65 | | - > |
66 | | - contact us |
67 | | - </a> |
68 | | - . |
69 | | - </p> |
70 | | - </div> |
71 | | - </div> |
72 | | - ); |
73 | | - } |
74 | 4 |
|
| 5 | +export const DubReferral = ({ publicToken }: { publicToken: string | null }) => { |
75 | 6 | if (!publicToken) { |
76 | 7 | return ( |
77 | | - <div className="rounded-md border border-muted bg-muted/50 p-4"> |
| 8 | + <div className="flex min-h-[400px] items-center justify-center"> |
78 | 9 | <p className="text-sm text-muted-foreground"> |
79 | 10 | No token available. Please try refreshing the page. |
80 | 11 | </p> |
81 | 12 | </div> |
82 | 13 | ); |
83 | 14 | } |
84 | 15 |
|
85 | | - const dubTheme = theme === 'dark' ? 'dark' : 'light'; |
86 | | - |
87 | 16 | return ( |
88 | 17 | <DubEmbed |
89 | 18 | data="referrals" |
90 | 19 | token={publicToken} |
91 | 20 | options={{ |
92 | | - theme: dubTheme, |
| 21 | + theme: 'system', |
93 | 22 | }} |
94 | 23 | /> |
95 | 24 | ); |
|
0 commit comments