IssuesModal.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <modal title="Report">
  3. <div slot="body">
  4. <router-link
  5. v-if="$route.query.returnToSong"
  6. class="button is-dark back-to-song"
  7. :to="{
  8. path: '/admin/songs',
  9. query: { id: report.songId }
  10. }"
  11. >
  12. <i class="material-icons">keyboard_return</i> &nbsp; Edit Song
  13. </router-link>
  14. <article class="message">
  15. <div class="message-body">
  16. <strong>Song ID:</strong>
  17. {{ report.song.songId }} / {{ report.song._id }}
  18. <br />
  19. <strong>Author:</strong>
  20. <user-id-to-username
  21. :userId="report.createdBy"
  22. :alt="report.createdBy"
  23. />
  24. <br />
  25. <strong>Time of report:</strong>
  26. <span :title="report.createdAt">
  27. {{
  28. formatDistance(
  29. new Date(report.createdAt),
  30. new Date(),
  31. {
  32. addSuffix: true
  33. }
  34. )
  35. }}
  36. </span>
  37. <br />
  38. <span v-if="report.description">
  39. <strong>Description:</strong>
  40. {{ report.description }}
  41. </span>
  42. </div>
  43. </article>
  44. <table v-if="report.issues.length > 0" class="table is-narrow">
  45. <thead>
  46. <tr>
  47. <td>Issue</td>
  48. <td>Reasons</td>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. <tr v-for="(issue, index) in report.issues" :key="index">
  53. <td>
  54. <span>{{ issue.name }}</span>
  55. </td>
  56. <td>
  57. <span>{{ issue.reasons }}</span>
  58. </td>
  59. </tr>
  60. </tbody>
  61. </table>
  62. </div>
  63. <div slot="footer">
  64. <a class="button is-primary" href="#" @click="resolve(report._id)">
  65. <span>Resolve</span>
  66. </a>
  67. <a
  68. class="button is-primary"
  69. :href="`/admin/songs?songId=${report.song.songId}`"
  70. target="_blank"
  71. >
  72. <span>Go to song</span>
  73. </a>
  74. <a
  75. class="button is-danger"
  76. @click="
  77. closeModal({
  78. sector: 'admin',
  79. modal: 'viewReport'
  80. })
  81. "
  82. href="#"
  83. >
  84. <span>Cancel</span>
  85. </a>
  86. </div>
  87. </modal>
  88. </template>
  89. <script>
  90. import { mapActions, mapState } from "vuex";
  91. import { formatDistance } from "date-fns";
  92. import Toast from "toasters";
  93. import UserIdToUsername from "../UserIdToUsername.vue";
  94. import Modal from "./Modal.vue";
  95. export default {
  96. computed: {
  97. ...mapState("admin/reports", {
  98. report: state => state.report
  99. })
  100. },
  101. mounted() {
  102. if (this.$route.query.returnToSong) {
  103. this.closeModal({ sector: "admin", modal: "editSong" });
  104. }
  105. },
  106. methods: {
  107. formatDistance,
  108. resolve(reportId) {
  109. return this.resolveReport(reportId)
  110. .then(res => {
  111. if (res.status === "success")
  112. this.closeModal({
  113. sector: "admin",
  114. modal: "viewReport"
  115. });
  116. })
  117. .catch(
  118. err => new Toast({ content: err.message, timeout: 5000 })
  119. );
  120. },
  121. ...mapActions("admin/reports", ["resolveReport"]),
  122. ...mapActions("modals", ["closeModal"])
  123. },
  124. components: { Modal, UserIdToUsername }
  125. };
  126. </script>
  127. <style lang="scss">
  128. @import "styles/global.scss";
  129. .back-to-song {
  130. display: flex;
  131. margin-bottom: 20px;
  132. }
  133. </style>