PunishmentItem.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, computed } from "vue";
  3. import { format, formatDistance, parseISO } from "date-fns";
  4. import { useUserAuthStore } from "@/stores/userAuth";
  5. const UserLink = defineAsyncComponent(
  6. () => import("@/components/UserLink.vue")
  7. );
  8. const props = defineProps({
  9. punishment: { type: Object, default: () => {} }
  10. });
  11. defineEmits(["deactivate"]);
  12. const { hasPermission } = useUserAuthStore();
  13. const active = computed(
  14. () =>
  15. props.punishment.active &&
  16. new Date(props.punishment.expiresAt).getTime() > Date.now()
  17. );
  18. </script>
  19. <template>
  20. <div class="universal-item punishment-item">
  21. <div class="item-icon">
  22. <p class="is-expanded checkbox-control">
  23. <label
  24. class="switch"
  25. :class="{
  26. disabled: !(
  27. hasPermission('punishments.deactivate') && active
  28. )
  29. }"
  30. >
  31. <input
  32. type="checkbox"
  33. :checked="active"
  34. @click="
  35. hasPermission('punishments.deactivate') && active
  36. ? $emit('deactivate', $event)
  37. : $event.preventDefault()
  38. "
  39. />
  40. <span
  41. class="slider round"
  42. :class="{
  43. disabled: !(
  44. hasPermission('punishments.deactivate') &&
  45. active
  46. )
  47. }"
  48. ></span>
  49. </label>
  50. </p>
  51. <p>
  52. <strong>{{ active ? "Active" : "Inactive" }}</strong>
  53. </p>
  54. </div>
  55. <div class="item-title-description">
  56. <h2 v-if="punishment.type === 'banUserId'" class="item-title">
  57. <strong>Punishment</strong> for user
  58. <user-link
  59. :user-id="punishment.value"
  60. :alt="punishment.value"
  61. />
  62. </h2>
  63. <h2 class="item-title" v-else>
  64. <strong>Punishment</strong> for IP
  65. {{ punishment.value }}
  66. </h2>
  67. <h3 class="item-title-2">Reason: {{ punishment.reason }}</h3>
  68. <ul>
  69. <li class="item-description" :title="punishment.expiresAt">
  70. Expires
  71. {{
  72. formatDistance(
  73. parseISO(punishment.expiresAt),
  74. new Date(),
  75. { addSuffix: true }
  76. )
  77. }}
  78. ({{
  79. format(
  80. parseISO(punishment.expiresAt),
  81. "MMMM do yyyy, h:mm:ss a"
  82. )
  83. }})
  84. </li>
  85. <li class="item-description">
  86. Punished by
  87. <user-link
  88. :user-id="punishment.punishedBy"
  89. :alt="punishment.punishedBy"
  90. />
  91. <span :title="punishment.punishedAt">
  92. &nbsp;{{
  93. formatDistance(
  94. parseISO(punishment.punishedAt),
  95. new Date(),
  96. { addSuffix: true }
  97. )
  98. }}
  99. ({{
  100. format(
  101. parseISO(punishment.punishedAt),
  102. "MMMM do yyyy, h:mm:ss a"
  103. )
  104. }})
  105. </span>
  106. </li>
  107. </ul>
  108. </div>
  109. </div>
  110. </template>
  111. <style lang="less" scoped>
  112. .night-mode {
  113. .punishment-item {
  114. background-color: var(--dark-grey-2) !important;
  115. border: 0 !important;
  116. }
  117. }
  118. .punishment-item {
  119. padding: 15px;
  120. justify-content: flex-start;
  121. .item-icon {
  122. min-width: 85px;
  123. max-width: 85px;
  124. height: 85px;
  125. margin-left: 20px;
  126. margin-right: 35px;
  127. display: flex;
  128. flex-direction: column;
  129. align-items: center;
  130. justify-content: space-evenly;
  131. border: 1px solid var(--light-grey-3);
  132. border-radius: @border-radius;
  133. }
  134. .item-title {
  135. font-size: 19px;
  136. margin: 0;
  137. }
  138. .item-title-2 {
  139. font-size: 17px;
  140. margin: 0;
  141. }
  142. ul {
  143. list-style: inside;
  144. margin-top: 10px;
  145. .item-description {
  146. font-size: 14px;
  147. margin: 0;
  148. }
  149. }
  150. }
  151. </style>