createPlaylist.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, {useState} from 'react';
  2. import { sendForm } from './SendForm';
  3. import Modal from 'react-bootstrap/Modal';
  4. import Button from 'react-bootstrap/Button';
  5. import { actionUsersPlaylists } from '../store/promiseReducer';
  6. import { store } from '../store/store';
  7. import { history } from '../App';
  8. export const CreatePlaylist = (props) => {
  9. const [name, setName] = useState('');
  10. const [description, setDescription] = useState('');
  11. const [privat, setPrivat] = useState(0);
  12. const [image, setImage] = useState(null);
  13. const PostCreatePlaylist = async(event) =>{
  14. event.preventDefault();
  15. const data = new FormData();
  16. data.append("name", name);
  17. description && data.append("description", description);
  18. data.append("private", privat);
  19. image && data.append("photo", image, image.name);
  20. let result = await sendForm('playlists/create', data);
  21. console.log(result);
  22. store.dispatch(actionUsersPlaylists(store.getState().auth?.user?.id));
  23. //history.push(`/playlist/${result.playlist.id}`)
  24. }
  25. return <>
  26. <Modal
  27. {...props}
  28. size="lg"
  29. aria-labelledby="contained-modal-title-vcenter"
  30. centered
  31. >
  32. <Modal.Header closeButton>
  33. <Modal.Title id="contained-modal-title-vcenter">Create new Playlist</Modal.Title>
  34. </Modal.Header>
  35. <Modal.Body >
  36. <form onSubmit={PostCreatePlaylist} className="authorization center align-items-center justify-content-center d-flex" id='CreatePlaylistForm'>
  37. <div className="border p-3 col-9">
  38. {/* <hr/> */}
  39. <div className="d-flex justify-content-between">
  40. <div className="w-auto">
  41. <label className="form-label">Image</label>
  42. <input type="file" name="picture" accept="image/*" id="file" className='form-control mb-3' onChange={(e) => setImage(e.target.files[0])} multiple={false}/>
  43. <input className="form-check-input me-3" type="checkbox" id="flexCheckIndeterminate" checked={privat} onChange={e => setPrivat(e.target.checked? 1 : 0)}/>
  44. <label className="form-check-label" >Private?</label>
  45. </div>
  46. <div className="w-50">
  47. <label className="form-label">Name</label><br/>
  48. <input type="text" id="username" className='input form-control mb-3' value={name} onChange={e => setName(e.target.value)}/>
  49. <label className="form-label">Description</label>
  50. <textarea type="password" id="password" className='form-control mb-3' value={description} onChange={e => setDescription(e.target.value)}/>
  51. </div>
  52. </div>
  53. {/* <button type='submit' className="btn btn-outline-danger" onClick={props.onHide} >Create</button> */}
  54. </div>
  55. </form>
  56. </Modal.Body>
  57. <Modal.Footer>
  58. <Button variant="outline-danger" type='submit' form='CreatePlaylistForm' className="btn btn-outline-danger" onClick={props.onHide}>Create</Button>
  59. </Modal.Footer>
  60. </Modal>
  61. </>
  62. }