forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
52 lines (46 loc) · 1.38 KB
/
index.tsx
File metadata and controls
52 lines (46 loc) · 1.38 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
import * as React from 'react'
import { useAppState, useActions, useReaction } from '../../overmind'
import { isValidJson } from '../../overmind/utils'
import { colors } from '../../theme'
import * as styles from './styles'
const ActionPayload: React.FunctionComponent = () => {
const state = useAppState()
const actions = useActions()
const reaction = useReaction()
const input = React.useRef(null)
React.useEffect(() => {
reaction(
() => state.currentApp.selectedActionQuery,
() => setTimeout(() => input.current && input.current.focus())
)
}, [])
const payload = state.currentApp.actionQueryPayload
return (
<div className={styles.wrapper}>
<input
ref={input}
style={{
borderColor:
!payload || isValidJson(payload) ? 'transparent' : colors.red,
}}
disabled={
!state.currentApp.selectedActionQuery || state.isExecutingAction
}
placeholder={
state.currentApp.selectedActionQuery ? 'Add some payload...' : null
}
onKeyDown={(event) => {
if (event.keyCode === 13) {
actions.executeAction()
}
}}
className={styles.input}
value={payload}
onChange={(event) =>
actions.setActionQueryPayload(event.currentTarget.value)
}
/>
</div>
)
}
export default ActionPayload