PunishmentItem.vue 3.0 KB

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