|
1 | 1 | "use client"; |
2 | 2 |
|
3 | 3 | import { useGlobalConnect } from "./GlobalConnectProvider"; |
4 | | -import DemoAppSelector from "./DemoAppSelector"; |
5 | | -import DemoClientCode from "./DemoClientCode"; |
6 | | -import DemoConnectButton from "./DemoConnectButton"; |
7 | | -import DemoConnectionStatus from "./DemoConnectionStatus"; |
| 4 | +import CodeBlock from "./CodeBlock"; |
8 | 5 |
|
9 | 6 | export default function AccountConnectionDemo() { |
| 7 | + const { |
| 8 | + appSlug, |
| 9 | + setAppSlug, |
| 10 | + tokenData, |
| 11 | + getClientCodeSnippet, |
| 12 | + connectAccount, |
| 13 | + connectedAccount, |
| 14 | + error |
| 15 | + } = useGlobalConnect(); |
| 16 | + |
10 | 17 | return ( |
11 | | - <div className="border rounded-md overflow-hidden"> |
| 18 | + <div className="border rounded-md overflow-hidden mt-4"> |
12 | 19 | <div className="bg-gray-100 border-b px-4 py-2 font-medium text-sm"> |
13 | | - Step 2: Connect an Account (Client-side) |
| 20 | + Connect an account from your frontend |
14 | 21 | </div> |
15 | 22 | <div className="p-4"> |
16 | 23 | <div className="mb-4"> |
17 | 24 | <label className="flex items-center mb-4"> |
18 | 25 | <span className="font-medium text-sm">App to connect:</span> |
19 | | - <span className="ml-2"><DemoAppSelector /></span> |
| 26 | + <select |
| 27 | + value={appSlug} |
| 28 | + onChange={(e) => setAppSlug(e.target.value)} |
| 29 | + className="ml-2 p-1 border rounded text-sm" |
| 30 | + disabled={!tokenData} |
| 31 | + > |
| 32 | + <option value="slack">Slack</option> |
| 33 | + <option value="github">GitHub</option> |
| 34 | + <option value="google_sheets">Google Sheets</option> |
| 35 | + </select> |
20 | 36 | </label> |
21 | 37 |
|
22 | 38 | <div className="mb-4"> |
23 | | - <div className="text-sm mb-2 font-medium">Client-side code executed in the browser:</div> |
24 | 39 | <div className="border border-blue-100 rounded-lg overflow-hidden"> |
25 | | - <DemoClientCode /> |
| 40 | + <CodeBlock code={getClientCodeSnippet()} language="javascript" /> |
26 | 41 | </div> |
27 | 42 | </div> |
28 | 43 | </div> |
29 | 44 |
|
30 | 45 | <div className="mt-4 mb-2"> |
31 | | - <DemoConnectButton /> |
| 46 | + <button |
| 47 | + onClick={connectAccount} |
| 48 | + disabled={!tokenData} |
| 49 | + className="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors disabled:opacity-50 font-medium text-sm" |
| 50 | + > |
| 51 | + Connect Account |
| 52 | + </button> |
32 | 53 | </div> |
33 | 54 |
|
34 | | - <DemoConnectionStatus /> |
| 55 | + {error && ( |
| 56 | + <div className="mt-4 p-3 bg-red-50 border border-red-200 text-red-800 rounded-md"> |
| 57 | + <div className="font-medium text-sm">Error</div> |
| 58 | + <div className="mt-1 text-sm">{error}</div> |
| 59 | + </div> |
| 60 | + )} |
| 61 | + |
| 62 | + {connectedAccount && ( |
| 63 | + <div className="mt-4 p-3 bg-green-50 border border-green-200 text-green-800 rounded-md"> |
| 64 | + <div className="font-medium text-sm">Account successfully connected!</div> |
| 65 | + <div className="mt-1 text-sm"> |
| 66 | + {connectedAccount.name && ( |
| 67 | + <div>Account name: <span className="font-medium">{connectedAccount.name}</span></div> |
| 68 | + )} |
| 69 | + {connectedAccount.id && ( |
| 70 | + <div>Account ID: <span className="font-mono text-xs">{connectedAccount.id}</span></div> |
| 71 | + )} |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + )} |
35 | 75 | </div> |
36 | 76 | </div> |
37 | 77 | ); |
|
0 commit comments