/
ProjectSettings.vue
306 lines (276 loc) · 10.8 KB
/
ProjectSettings.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-container>
<v-row>
<v-col>
<PageTitleComponent title="Project Settings" />
<PageSubtitleComponent subtitle="Edit project information and set custom project limits." link="https://docs.storj.io/learn/concepts/limits" />
</v-col>
</v-row>
<v-row>
<v-col cols="12" lg="4">
<v-card title="Project Name" variant="outlined" :border="true" rounded="xlg">
<v-card-text>
<v-chip rounded color="default" variant="tonal" size="small" class="font-weight-bold">
{{ project.name }}
</v-chip>
<v-divider class="my-4" />
<v-btn variant="outlined" color="default" size="small" @click="showEditNameDialog">
Edit Name
</v-btn>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" lg="4">
<v-card title="Project Description" variant="outlined" :border="true" rounded="xlg">
<v-card-text>
<v-chip rounded color="default" variant="tonal" size="small" class="font-weight-bold">
{{ project.description }}
</v-chip>
<v-divider class="my-4" />
<v-btn variant="outlined" color="default" size="small" @click="showEditDescriptionDialog">
Edit Description
</v-btn>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" lg="4">
<v-card title="Delete Project" variant="outlined" :border="true" rounded="xlg">
<v-card-text>
<v-chip rounded color="default" variant="tonal" size="small" class="font-weight-bold" disabled>
Not Available
</v-chip>
<v-divider class="my-4" />
<v-btn variant="outlined" color="default" size="small" href="https://docs.storj.io/support/projects#delete-the-existing-project" target="_blank">
Learn More
</v-btn>
</v-card-text>
</v-card>
</v-col>
</v-row>
<v-row>
<v-col>
<h3 class="mt-5">Limits</h3>
</v-col>
</v-row>
<v-row v-if="!isPaidTier && billingEnabled">
<v-col cols="12">
<v-card title="Free Account" variant="outlined" :border="true" rounded="xlg">
<v-card-subtitle>
{{ storageLimitFormatted }} Storage / {{ bandwidthLimitFormatted }} Bandwidth. <br>
Need more? Upgrade to Pro Account.
</v-card-subtitle>
<v-card-text>
<v-divider class="mb-4" />
<v-btn variant="flat" color="primary" size="small" @click="toggleUpgradeFlow">
Upgrade to Pro
</v-btn>
</v-card-text>
</v-card>
</v-col>
</v-row>
<v-row v-else>
<v-col cols="12" lg="4">
<v-card title="Storage Limit" variant="outlined" :border="true" rounded="xlg">
<v-card-subtitle>
Storage Limit: {{ storageLimitFormatted }} <br>
Available Storage: {{ paidStorageLimitFormatted }}
</v-card-subtitle>
<v-card-text>
<v-divider class="mb-4" />
<v-btn variant="outlined" color="default" size="small" @click="showStorageLimitDialog">
Edit Storage Limit
</v-btn>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" lg="4">
<v-card title="Download Limit" variant="outlined" :border="true" rounded="xlg">
<v-card-subtitle>
Download Limit: {{ bandwidthLimitFormatted }} per month<br>
Available Download: {{ paidBandwidthLimitFormatted }} per month
</v-card-subtitle>
<v-card-text>
<v-divider class="mb-4" />
<v-btn variant="outlined" color="default" size="small" @click="showBandwidthLimitDialog">
Edit Download Limit
</v-btn>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" lg="4">
<v-card title="Account Limits" variant="outlined" :border="true" rounded="xlg">
<v-card-subtitle>
Storage limit: {{ paidStorageLimitFormatted }} <br>
Download limit: {{ paidBandwidthLimitFormatted }} per month
</v-card-subtitle>
<v-card-text>
<v-divider class="mb-4" />
<v-btn
variant="outlined"
color="default"
size="small"
:href="projectLimitsIncreaseRequestURL"
target="_blank"
rel="noopener noreferrer"
>
Request Limits Increase
<v-icon end :icon="mdiOpenInNew" />
</v-btn>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
<edit-project-details-dialog v-model="isEditDetailsDialogShown" :field="fieldToChange" />
<edit-project-limit-dialog v-model="isEditLimitDialogShown" :limit-type="limitToChange" />
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import {
VContainer,
VCard,
VCardText,
VCardSubtitle,
VDivider,
VBtn,
VCol,
VRow,
VIcon,
VChip,
} from 'vuetify/components';
import { mdiOpenInNew } from '@mdi/js';
import { useProjectsStore } from '@/store/modules/projectsStore';
import { FieldToChange, LimitToChange, Project } from '@/types/projects';
import { useUsersStore } from '@/store/modules/usersStore';
import { Memory, Size } from '@/utils/bytesSize';
import { useConfigStore } from '@/store/modules/configStore';
import { decimalShift } from '@/utils/strings';
import { useNotify } from '@/utils/hooks';
import { AnalyticsErrorEventSource } from '@/utils/constants/analyticsEventNames';
import { useAppStore } from '@poc/store/appStore';
import EditProjectDetailsDialog from '@poc/components/dialogs/EditProjectDetailsDialog.vue';
import EditProjectLimitDialog from '@poc/components/dialogs/EditProjectLimitDialog.vue';
import PageTitleComponent from '@poc/components/PageTitleComponent.vue';
import PageSubtitleComponent from '@poc/components/PageSubtitleComponent.vue';
const isEditDetailsDialogShown = ref<boolean>(false);
const isEditLimitDialogShown = ref<boolean>(false);
const fieldToChange = ref<FieldToChange>(FieldToChange.Name);
const limitToChange = ref<LimitToChange>(LimitToChange.Storage);
const appStore = useAppStore();
const projectsStore = useProjectsStore();
const usersStore = useUsersStore();
const configStore = useConfigStore();
const notify = useNotify();
/**
* Indicates if billing features are enabled.
*/
const billingEnabled = computed<boolean>(() => configStore.state.config.billingFeaturesEnabled);
/**
* Returns selected project from the store.
*/
const project = computed<Project>(() => {
return projectsStore.state.selectedProject;
});
/**
* Returns user's paid tier status from store.
*/
const isPaidTier = computed<boolean>(() => {
return usersStore.state.user.paidTier;
});
/**
* Returns formatted storage limit.
*/
const storageLimitFormatted = computed<string>(() => {
return formatLimit(projectsStore.state.currentLimits.storageLimit);
});
/**
* Returns formatted bandwidth limit.
*/
const bandwidthLimitFormatted = computed<string>(() => {
return formatLimit(projectsStore.state.currentLimits.bandwidthLimit);
});
/**
* Returns formatted paid tier storage limit.
*/
const paidStorageLimitFormatted = computed<string>(() => {
const limit = Math.max(
projectsStore.state.currentLimits.storageLimit,
parseConfigLimit(configStore.state.config.defaultPaidStorageLimit),
);
return formatLimit(limit);
});
/**
* Returns formatted paid tier bandwidth limit.
*/
const paidBandwidthLimitFormatted = computed<string>(() => {
const limit = Math.max(
projectsStore.state.currentLimits.bandwidthLimit,
parseConfigLimit(configStore.state.config.defaultPaidBandwidthLimit),
);
return formatLimit(limit);
});
/**
* Returns project limits increase request URL from config.
*/
const projectLimitsIncreaseRequestURL = computed((): string => {
return configStore.state.config.projectLimitsIncreaseRequestURL;
});
function toggleUpgradeFlow(): void {
appStore.toggleUpgradeFlow(true);
}
/**
* Returns formatted limit value.
*/
function formatLimit(limit: number): string {
const size = new Size(limit, 2);
return `${decimalShift(size.formattedBytes, 0)} ${size.label}`;
}
/**
* Displays the Edit Project Name dialog.
*/
function showEditNameDialog(): void {
fieldToChange.value = FieldToChange.Name;
isEditDetailsDialogShown.value = true;
}
/**
* Displays the Edit Description dialog.
*/
function showEditDescriptionDialog(): void {
fieldToChange.value = FieldToChange.Description;
isEditDetailsDialogShown.value = true;
}
/**
* Displays the Storage Limit dialog.
*/
function showStorageLimitDialog(): void {
limitToChange.value = LimitToChange.Storage;
isEditLimitDialogShown.value = true;
}
/**
* Displays the Bandwidth Limit dialog.
*/
function showBandwidthLimitDialog(): void {
limitToChange.value = LimitToChange.Bandwidth;
isEditLimitDialogShown.value = true;
}
/**
* Parses limit value from config, returning it as a byte amount.
*/
function parseConfigLimit(limit: string): number {
const [value, unit] = limit.split(' ');
return parseFloat(value) * Memory[unit === 'B' ? 'Bytes' : unit];
}
/**
* Lifecycle hook after initial render.
* Fetches project limits.
*/
onMounted(async () => {
try {
await projectsStore.getProjectLimits(project.value.id);
} catch (error) {
notify.error(`Error fetching project limits. ${error.message}`, AnalyticsErrorEventSource.PROJECT_SETTINGS_AREA);
}
});
</script>