all repos — stealth-developers @ 43e8c7358a2056b6ab989ef6fe8c91cf6ad58923

frontend/src/views/TicketsView.vue (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import type { User } from '@/types'
import UserChip from '@/components/UserChip.vue'

type Ticket = {
	id: number
	anonymousId: string
	ticketNumber: number
	guildId: string
	channelId: string

	type: 'general'
	status: 'open' | 'archived' | 'closed'
	topic: string | null

	authorId: User
	openedBy: User
	addedUsers: string[]

	claimedBy: User | null
	claimedAt: string | null
	closedAt: string
	closedBy: User | 'reporter' | null
	closeReason: string | null
	privateReason: string | null

	thankedAt: string | null
	warnedAt: string | null

	createdAt: string
}

const tickets = ref<Ticket[]>([])
onMounted(async () => {
	const response = await fetch('/api/tickets')
	const data = await response.json()
	tickets.value = data
})

const formatTimeAgo = (dateString: string | null) => {
	if (!dateString) return ''
	const now = new Date()
	const ticketDate = new Date(dateString)
	const diff = now.getTime() - ticketDate.getTime()
	const seconds = Math.floor(diff / 1000)
	const minutes = Math.floor(seconds / 60)
	const hours = Math.floor(minutes / 60)
	const days = Math.floor(hours / 24)
	if (days > 0) return `${days}d`
	if (hours > 0) return `${hours}h`
	if (minutes > 0) return `${minutes}m`
	return `${seconds}s`
}
</script>

<template>
	<h1>Tickets</h1>

	<div class="ticket-container">
		<div v-for="ticket in tickets" :key="ticket.id" class="ticket">
			<div class="head">
				<span class="id">{{ ticket.ticketNumber }}</span>
				<span :class="['status', ticket.status]">{{ ticket.status }}</span>
				<div class="time-ago">
					<template v-if="ticket.status === 'open'">
						for {{ formatTimeAgo(ticket.createdAt) }}
					</template>
					<template v-else> {{ formatTimeAgo(ticket.closedAt) }} ago </template>
				</div>
			</div>

			<div class="details">
				<div class="keypair">
					<span class="key">Opened by</span>
					<span class="value">
						<UserChip :user="ticket.openedBy" />
					</span>
				</div>

				<div class="keypair">
					<span class="key">Closed by</span>
					<span class="value">
						<UserChip
							v-if="ticket.closedBy"
							:user="ticket.closedBy === 'reporter' ? ticket.openedBy : ticket.closedBy"
						/>
						<span v-else>/</span>
					</span>
				</div>
			</div>

			<div class="footer">
				<RouterLink :to="`/tickets/${ticket.id}`">View Ticket</RouterLink>
			</div>
		</div>
	</div>
</template>

<style scoped>
.ticket-container {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
	gap: 0.5rem;
}

.ticket {
	display: flex;
	flex-direction: column;
	background-color: hsl(var(--base));
	border-radius: 1rem;
	overflow: hidden;

	.head {
		display: flex;
		align-items: center;
		gap: 1ch;
		padding: 0.5rem;
		background-color: hsla(var(--surface0) / 0.75);

		.id {
			font-weight: bold;
			color: hsl(var(--subtext1));

			&::before {
				content: '#';
			}
		}

		.status,
		.time-ago {
			font-weight: bold;
			color: hsl(var(--subtext0));

			&.open {
				color: hsl(var(--green));
			}
			&.archived {
				color: hsl(var(--subtext0));
			}
		}
	}

	.details {
		display: grid;
		grid-template-columns: auto minmax(0, 1fr);

		align-items: center;
		row-gap: 0.5ch;
		column-gap: 1ch;
		padding: 0.5rem;

		.keypair {
			display: contents;

			.key {
				font-weight: bolder;
				color: hsl(var(--subtext0));
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
			.value {
				color: hsl(var(--subtext1));
				font-weight: bold;
				overflow: hidden;
			}
		}
	}

	.footer {
		display: flex;
		justify-content: flex-end;
		gap: 1ch;
		padding: 0 0.5rem 0.5rem 0.5rem;

		a {
			background-color: hsla(var(--accent) / 0.75);
			color: hsl(var(--on-accent));
			padding: 0.3rem 1rem;
			border-radius: 0.5rem;
			text-decoration: none;

			&:hover {
				filter: brightness(1.1);
			}
			&:active {
				filter: brightness(0.9);
			}
		}
	}
}
</style>