ViewPunishment.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 { mapState, mapGetters, mapActions } from "vuex";
  12. import { format, formatDistance, parseISO } from "date-fns";
  13. import ws from "@/ws";
  14. import Toast from "toasters";
  15. import Modal from "../Modal.vue";
  16. import PunishmentItem from "../PunishmentItem.vue";
  17. export default {
  18. components: { Modal, PunishmentItem },
  19. props: {
  20. punishmentId: { type: String, default: "" },
  21. sector: { type: String, default: "admin" }
  22. },
  23. data() {
  24. return {
  25. ban: {}
  26. };
  27. },
  28. computed: {
  29. ...mapState("modals/viewPunishment", {
  30. punishment: state => state.punishment
  31. }),
  32. ...mapGetters({
  33. socket: "websockets/getSocket"
  34. })
  35. },
  36. mounted() {
  37. ws.onConnect(this.init);
  38. },
  39. methods: {
  40. init() {
  41. this.socket.dispatch(
  42. `punishments.findOne`,
  43. this.punishmentId,
  44. res => {
  45. if (res.status === "success") {
  46. const { punishment } = res.data;
  47. this.viewPunishment(punishment);
  48. } else {
  49. new Toast("Punishment with that ID not found");
  50. this.closeModal("viewPunishment");
  51. }
  52. }
  53. );
  54. },
  55. ...mapActions("modalVisibility", ["closeModal"]),
  56. ...mapActions("modals/viewPunishment", ["viewPunishment"]),
  57. format,
  58. formatDistance,
  59. parseISO
  60. }
  61. };
  62. </script>