-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
63 lines (60 loc) · 2.33 KB
/
App.tsx
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
58
59
60
61
62
63
import { useEffect, useState } from 'react'
import { Box, Input, Button } from '@mui/material'
import Sidebar from 'Components/Sidebar'
import IncomePrompt from 'Components/IncomePrompt'
import './App.css'
import Module from 'Components/Module'
function App() {
const [userKey, setUserKey] = useState('')
const [bookName, setFolderName] = useState('')
const [submit, setSubmit] = useState(false)
useEffect(() => {
if (submit) {
;(window as any).getAuthToken = async function () {
const response = await fetch('https://auth.ocrolusexample.com/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userId: userKey,
bookName: bookName,
}),
})
const json = await response.json()
return json.accessToken
}
}
}, [userKey, bookName, submit])
return (
<Box sx={{ display: 'flex' }}>
<Sidebar />
<Box component="main" className="content-column" sx={{ flexGrow: 1, p: 3 }}>
<IncomePrompt />
<Box sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
<Input
style={{ marginRight: '15px' }}
type="text"
placeholder="Enter User Key"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setUserKey(e.target.value)}
/>
{userKey && (
<Input
style={{ marginRight: '15px' }}
type="text"
placeholder="Enter Book Name"
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setFolderName(e.target.value)
}
/>
)}
<Button onClick={() => setSubmit(!submit)}>Get Token</Button>
</Box>
<Module>
<Box id="ocrolus-widget-frame"></Box>
</Module>
</Box>
</Box>
)
}
export default App