ReportPostModal.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class='report_post_modal'>
  3. <modal-window v-model='showModal' :loading='loading'>
  4. <div class='report_post_modal__modal' slot='main'>
  5. <h3>Report this post</h3>
  6. <div class='report_post_modal--margin'>Select a reason for reporting this post below:</div>
  7. <select-button :options='reportOptions' v-model='selectedOption' class='report_post_modal--margin' :touch-disabled='true'></select-button>
  8. </div>
  9. <div slot='footer'>
  10. <button class='button button--modal' @click.stop='submitReport'>Submit</button>
  11. <button class='button button--modal' @click.stop='setShowModal(false)'>Cancel</button>
  12. </div>
  13. </modal-window>
  14. </div>
  15. </template>
  16. <script>
  17. import ModalWindow from './ModalWindow'
  18. import SelectButton from './SelectButton'
  19. import AjaxErrorHandler from '../assets/js/errorHandler'
  20. export default {
  21. name: 'ReportPostModal',
  22. props: ['value', 'post-id'],
  23. components: {
  24. ModalWindow,
  25. SelectButton
  26. },
  27. data () {
  28. return {
  29. showModal: false,
  30. loading: false,
  31. selectedOption: 0,
  32. reportOptions: [
  33. { name: 'Reason for reporting', disabled: true },
  34. { name: 'Spam', value: 'spam' },
  35. { name: 'Inappropriate content', value: 'inappropriate' },
  36. { name: 'Harassment', value: 'harassment' }
  37. ]
  38. }
  39. },
  40. methods: {
  41. setShowModal (val) {
  42. this.showModal = val
  43. },
  44. submitReport () {
  45. if(this.selectedOption) {
  46. this.loading = true
  47. this.axios
  48. .post('/api/v1/report', {
  49. postId: this.postId,
  50. reason: this.selectedOption
  51. })
  52. .then(() => {
  53. this.setShowModal(false)
  54. this.selectedOption = 0
  55. this.loading = false
  56. })
  57. .catch(e => {
  58. this.loading = false
  59. AjaxErrorHandler(this.$store)(e)
  60. })
  61. }
  62. }
  63. },
  64. watch: {
  65. value (val) {
  66. this.showModal = val
  67. this.$emit('input', val)
  68. },
  69. showModal (val) {
  70. this.$emit('input', val)
  71. }
  72. }
  73. }
  74. </script>
  75. <style lang='scss' scoped>
  76. @import '../assets/scss/variables.scss';
  77. .report_post_modal {
  78. @at-root #{&}--margin {
  79. margin: 0.5rem 0;
  80. }
  81. @at-root #{&}__modal {
  82. padding-top: 1rem;
  83. h3 {
  84. margin: 0;
  85. }
  86. }
  87. }
  88. </style>