ViewPunishment.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div>
  3. <modal title="View Punishment">
  4. <div slot="body" v-if="punishment && punishment._id">
  5. <article class="message">
  6. <div class="message-body">
  7. <strong>Type:</strong>
  8. {{ punishment.type }}
  9. <br />
  10. <strong>Value:</strong>
  11. {{ punishment.value }}
  12. <br />
  13. <strong>Reason:</strong>
  14. {{ punishment.reason }}
  15. <br />
  16. <strong>Active:</strong>
  17. {{ punishment.active }}
  18. <br />
  19. <strong>Expires at:</strong>
  20. {{
  21. format(
  22. parseISO(punishment.expiresAt),
  23. "MMMM do yyyy, h:mm:ss a"
  24. )
  25. }}
  26. ({{
  27. formatDistance(
  28. parseISO(punishment.expiresAt),
  29. new Date(),
  30. { addSuffix: true }
  31. )
  32. }})
  33. <br />
  34. <strong>Punished at:</strong>
  35. {{
  36. format(
  37. parseISO(punishment.punishedAt),
  38. "MMMM do yyyy, h:mm:ss a"
  39. )
  40. }}
  41. ({{
  42. formatDistance(
  43. parseISO(punishment.punishedAt),
  44. new Date(),
  45. { addSuffix: true }
  46. )
  47. }})
  48. <br />
  49. <strong>Punished by:</strong>
  50. <user-id-to-username
  51. :user-id="punishment.punishedBy"
  52. :alt="punishment.punishedBy"
  53. />
  54. <br />
  55. </div>
  56. </article>
  57. </div>
  58. <div slot="footer"></div>
  59. </modal>
  60. </div>
  61. </template>
  62. <script>
  63. import { mapState, mapGetters, mapActions } from "vuex";
  64. import { format, formatDistance, parseISO } from "date-fns"; // eslint-disable-line no-unused-vars
  65. import Toast from "toasters";
  66. import Modal from "../Modal.vue";
  67. import UserIdToUsername from "../UserIdToUsername.vue";
  68. export default {
  69. components: { Modal, UserIdToUsername },
  70. props: {
  71. punishmentId: { type: String, default: "" },
  72. sector: { type: String, default: "admin" }
  73. },
  74. data() {
  75. return {
  76. ban: {}
  77. };
  78. },
  79. computed: {
  80. ...mapState("modals/viewPunishment", {
  81. punishment: state => state.punishment
  82. }),
  83. ...mapGetters({
  84. socket: "websockets/getSocket"
  85. })
  86. },
  87. mounted() {
  88. this.socket.dispatch(
  89. `punishments.getPunishmentById`,
  90. this.punishmentId,
  91. res => {
  92. if (res.status === "success") {
  93. const { punishment } = res.data;
  94. this.viewPunishment(punishment);
  95. } else {
  96. new Toast("Punishment with that ID not found");
  97. this.closeModal("viewPunishment");
  98. }
  99. }
  100. );
  101. },
  102. methods: {
  103. ...mapActions("modalVisibility", ["closeModal"]),
  104. ...mapActions("modals/viewPunishment", ["viewPunishment"]),
  105. format,
  106. formatDistance,
  107. parseISO
  108. }
  109. };
  110. </script>