-
Notifications
You must be signed in to change notification settings - Fork 385
/
ProjectsTableComponent.vue
213 lines (191 loc) · 8.02 KB
/
ProjectsTableComponent.vue
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-card variant="flat" :border="true" class="rounded-xlg">
<v-text-field
v-model="search"
label="Search"
prepend-inner-icon="mdi-magnify"
single-line
hide-details
clearable
/>
<v-data-table
:sort-by="sortBy"
:headers="headers"
:items="items"
:search="search"
no-data-text="No results found"
class="elevation-1"
item-key="path"
>
<template #item.name="{ item }">
<v-btn
v-if="item.raw.role !== ProjectRole.Invited"
class="rounded-lg pl-1 pr-4 justify-start font-weight-bold"
variant="text"
height="40"
color="default"
block
@click="openProject(item.raw)"
>
<img src="../assets/icon-project-tonal.svg" alt="Project" class="mr-3">
{{ item.raw.name }}
</v-btn>
<div v-else class="pl-1 pr-4 d-flex align-center justify-start font-weight-bold">
<img src="../assets/icon-project-tonal.svg" alt="Project" class="mr-3">
<span class="text-no-wrap">{{ item.raw.name }}</span>
</div>
</template>
<template #item.role="{ item }">
<v-chip :color="PROJECT_ROLE_COLORS[item.raw.role]" rounded="xl" size="small" class="font-weight-bold">
{{ item.raw.role }}
</v-chip>
</template>
<template #item.createdAt="{ item }">
{{ getFormattedDate(item.raw.createdAt) }}
</template>
<template #item.actions="{ item }">
<div class="w-100 d-flex align-center justify-space-between">
<v-btn
v-if="item.raw.role === ProjectRole.Invited"
color="primary"
size="small"
:disabled="decliningIds.has(item.raw.id)"
@click="emit('joinClick', item.raw)"
>
Join Project
</v-btn>
<v-btn v-else color="primary" size="small" @click="openProject(item.raw)">Open Project</v-btn>
<v-btn
v-if="item.raw.role === ProjectRole.Owner || item.raw.role === ProjectRole.Invited"
class="ml-2"
icon
color="default"
variant="text"
size="small"
density="comfortable"
:loading="decliningIds.has(item.raw.id)"
>
<v-icon icon="mdi-dots-vertical" size="18" />
<v-menu activator="parent" location="bottom end" transition="scale-transition">
<v-list class="pa-0">
<template v-if="item.raw.role === ProjectRole.Owner">
<v-list-item link :to="`/projects/${item.raw.id}/settings`">
<template #prepend>
<icon-settings />
</template>
<v-list-item-title class="text-body-2 ml-3">
Project Settings
</v-list-item-title>
</v-list-item>
<v-divider />
<v-list-item link>
<template #prepend>
<icon-team />
</template>
<v-list-item-title class="text-body-2 ml-3">
Invite Members
</v-list-item-title>
</v-list-item>
</template>
<v-list-item v-else link @click="declineInvitation(item.raw)">
<template #prepend>
<icon-trash />
</template>
<v-list-item-title class="text-body-2 ml-3">
Decline
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-btn>
</div>
</template>
</v-data-table>
</v-card>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import {
VCard,
VTextField,
VListItem,
VChip,
VBtn,
VMenu,
VList,
VIcon,
VListItemTitle,
VDivider,
} from 'vuetify/components';
import { VDataTable } from 'vuetify/labs/components';
import { ProjectItemModel, PROJECT_ROLE_COLORS } from '@poc/types/projects';
import { ProjectInvitationResponse } from '@/types/projects';
import { ProjectRole } from '@/types/projectMembers';
import { SHORT_MONTHS_NAMES } from '@/utils/constants/date';
import { useProjectsStore } from '@/store/modules/projectsStore';
import { useAnalyticsStore } from '@/store/modules/analyticsStore';
import { AnalyticsErrorEventSource, AnalyticsEvent } from '@/utils/constants/analyticsEventNames';
import { useNotify } from '@/utils/hooks';
import IconSettings from '@poc/components/icons/IconSettings.vue';
import IconTeam from '@poc/components/icons/IconTeam.vue';
import IconTrash from '@poc/components/icons/IconTrash.vue';
const props = defineProps<{
items: ProjectItemModel[],
}>();
const emit = defineEmits<{
(event: 'joinClick', item: ProjectItemModel): void;
}>();
const search = ref<string>('');
const decliningIds = ref(new Set<string>());
const analyticsStore = useAnalyticsStore();
const projectsStore = useProjectsStore();
const router = useRouter();
const notify = useNotify();
const sortBy = [{ key: 'name', order: 'asc' }];
const headers = [
{ title: 'Project', key: 'name', align: 'start' },
{ title: 'Role', key: 'role' },
{ title: 'Members', key: 'memberCount' },
{ title: 'Date Added', key: 'createdAt' },
{ title: 'Actions', key: 'actions', sortable: false, width: '0' },
];
/**
* Formats the given project creation date.
*/
function getFormattedDate(date: Date): string {
return `${date.getDate()} ${SHORT_MONTHS_NAMES[date.getMonth()]} ${date.getFullYear()}`;
}
/**
* Selects the project and navigates to the project dashboard.
*/
function openProject(item: ProjectItemModel): void {
projectsStore.selectProject(item.id);
router.push(`/projects/${item.id}/dashboard`);
analyticsStore.pageVisit('/projects/dashboard');
}
/**
* Declines the project invitation.
*/
async function declineInvitation(item: ProjectItemModel): Promise<void> {
if (decliningIds.value.has(item.id)) return;
decliningIds.value.add(item.id);
try {
await projectsStore.respondToInvitation(item.id, ProjectInvitationResponse.Decline);
analyticsStore.eventTriggered(AnalyticsEvent.PROJECT_INVITATION_DECLINED);
} catch (error) {
error.message = `Failed to decline project invitation. ${error.message}`;
notify.notifyError(error, AnalyticsErrorEventSource.PROJECT_INVITATION);
}
try {
await projectsStore.getUserInvitations();
await projectsStore.getProjects();
} catch (error) {
error.message = `Failed to reload projects and invitations list. ${error.message}`;
notify.notifyError(error, AnalyticsErrorEventSource.PROJECT_INVITATION);
}
decliningIds.value.delete(item.id);
}
</script>