Advertisement
Guest User

changePost

a guest
Aug 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. export const changePostAction = (post) => {
  2. return (dispatch) => {
  3. dispatch(blockEditButton(true));
  4. let formData = new FormData();
  5. formData.append('postId', post.details.data.postId.value);
  6. formData.append('title', post.details.data.title.value);
  7. // formData.append('categoryId', post.category.data.subcategory.value);
  8. formData.append('description', post.details.data.describe.value);
  9. formData.append('price', post.details.data.price.value);
  10. formData.append('latitude', post.details.data.location.info.latitude);
  11. formData.append('longtitude', post.details.data.location.info.longetude);
  12. formData.append('location', post.details.data.location.info.address);
  13. //formData.append('type', post.category.data.type.value);
  14. formData.append('availableUntil', post.details.data.date.value);
  15. post.images.data.images.new.forEach(file => {
  16. formData.append('image', file);
  17. });
  18. post.images.data.images.deleted.forEach(name => {
  19. formData.append('imagesToDelete', name);
  20. });
  21.  
  22. PostApi.editPost(formData).then(response => {
  23. if(response.data.success === false){
  24. messageError('Data editing error');
  25. }
  26. else{
  27. dispatch(showPostWindowAction());
  28. dispatch(blockEditButton(false));
  29. dispatch(resetPostData());
  30. messageSuccess('Data edited successfully')
  31. }
  32. }).catch(error => {
  33. dispatch(blockEditButton(false));
  34. ErrorStatus(error,dispatch,
  35. {status:401,function: dispatch(showPostWindowAction())}
  36. );
  37. })
  38. }
  39. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement