import React from 'react'
import { PostFrom, usePostFromArgs } from './component'
import { useDispatch } from '../../store'
import { addScene } from '../../store/scene'
import { Modal } from 'antd'


export const AddScene = (props: {onClose: () => void}) => {
  const dispatch = useDispatch()
  const postFromArgs = usePostFromArgs(async post => {
    const action = addScene(post)
    await dispatch(action).unwrap()
    props.onClose()
  })

  return (
    <Modal 
      title="添加场景" 
      okText='添加'
      cancelText='取消'
      visible={true} 
      onOk={postFromArgs.onSubmit} 
      onCancel={props.onClose}>
      <PostFrom {...postFromArgs} />
    </Modal>
  )
}