user-input.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. memo,
  3. } from 'react'
  4. import { useNodes } from 'reactflow'
  5. import FormItem from '../../nodes/_base/components/before-run-form/form-item'
  6. import { BlockEnum } from '../../types'
  7. import {
  8. useStore,
  9. useWorkflowStore,
  10. } from '../../store'
  11. import type { StartNodeType } from '../../nodes/start/types'
  12. import cn from '@/utils/classnames'
  13. const UserInput = () => {
  14. const workflowStore = useWorkflowStore()
  15. const inputs = useStore(s => s.inputs)
  16. const nodes = useNodes<StartNodeType>()
  17. const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
  18. const variables = startNode?.data.variables || []
  19. const handleValueChange = (variable: string, v: string) => {
  20. workflowStore.getState().setInputs({
  21. ...inputs,
  22. [variable]: v,
  23. })
  24. }
  25. if (!variables.length)
  26. return null
  27. return (
  28. <div className={cn('relative bg-components-panel-on-panel-item-bg rounded-xl border-[0.5px] border-components-panel-border-subtle shadow-xs z-[1]')}>
  29. <div className='px-4 pt-3 pb-4'>
  30. {variables.map((variable, index) => (
  31. <div
  32. key={variable.variable}
  33. className='mb-4 last-of-type:mb-0'
  34. >
  35. <FormItem
  36. autoFocus={index === 0}
  37. payload={variable}
  38. value={inputs[variable.variable]}
  39. onChange={v => handleValueChange(variable.variable, v)}
  40. />
  41. </div>
  42. ))}
  43. </div>
  44. </div>
  45. )
  46. }
  47. export default memo(UserInput)