ViewPunishment.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div>
  3. <modal title="View Punishment">
  4. <template #body v-if="punishment && punishment._id">
  5. <punishment-item :punishment="punishment" />
  6. </template>
  7. </modal>
  8. </div>
  9. </template>
  10. <script>
  11. import { mapGetters, mapActions } from "vuex";
  12. import { format, formatDistance, parseISO } from "date-fns";
  13. import Toast from "toasters";
  14. import ws from "@/ws";
  15. import { mapModalState, mapModalActions } from "@/vuex_helpers";
  16. import PunishmentItem from "../PunishmentItem.vue";
  17. export default {
  18. components: { PunishmentItem },
  19. props: {
  20. modalUuid: { type: String, default: "" }
  21. },
  22. data() {
  23. return {
  24. ban: {}
  25. };
  26. },
  27. computed: {
  28. ...mapModalState("modals/viewPunishment/MODAL_UUID", {
  29. punishmentId: state => state.punishmentId,
  30. punishment: state => state.punishment
  31. }),
  32. ...mapGetters({
  33. socket: "websockets/getSocket"
  34. })
  35. },
  36. mounted() {
  37. ws.onConnect(this.init);
  38. },
  39. beforeUnmount() {
  40. // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
  41. this.$store.unregisterModule([
  42. "modals",
  43. "viewPunishment",
  44. this.modalUuid
  45. ]);
  46. },
  47. methods: {
  48. init() {
  49. this.socket.dispatch(
  50. `punishments.findOne`,
  51. this.punishmentId,
  52. res => {
  53. if (res.status === "success") {
  54. const { punishment } = res.data;
  55. this.viewPunishment(punishment);
  56. } else {
  57. new Toast("Punishment with that ID not found");
  58. this.closeModal("viewPunishment");
  59. }
  60. }
  61. );
  62. },
  63. ...mapActions("modalVisibility", ["closeModal"]),
  64. ...mapModalActions("modals/viewPunishment/MODAL_UUID", [
  65. "viewPunishment"
  66. ]),
  67. format,
  68. formatDistance,
  69. parseISO
  70. }
  71. };
  72. </script>