/
EnterProjectPassphraseDialog.vue
190 lines (168 loc) · 6.25 KB
/
EnterProjectPassphraseDialog.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
// Copyright (C) 2024 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-dialog
v-model="model"
:persistent="isLoading"
width="400px"
transition="fade-transition"
>
<v-card ref="innerContent" rounded="xlg">
<v-card-item class="pa-5 pl-7">
<template #prepend>
<img class="d-block" src="@/assets/createAccessGrantFlow/accessEncryption.svg" alt="icon">
</template>
<v-card-title class="font-weight-bold">
{{ isSkipping ? 'Skip passphrase' : 'Enter passphrase' }}
</v-card-title>
<template #append>
<v-btn
icon="$close"
variant="text"
size="small"
color="default"
:disabled="isLoading"
@click="model = false"
/>
</template>
</v-card-item>
<v-divider />
<v-card-item class="pa-7 pb-3">
<v-form v-model="formValid" @submit.prevent="onContinue">
<v-row>
<v-col cols="12">
<p v-if="isSkipping" class="pb-3">
Do you want to remember this choice and skip the passphrase when opening a project?
</p>
<p v-else>
Enter your encryption passphrase to view and manage the data in this project.
</p>
</v-col>
<v-col v-if="!isSkipping" cols="12">
<v-text-field
id="Encryption Passphrase"
v-model="passphrase"
label="Encryption Passphrase"
:type="isPassphraseVisible ? 'text' : 'password'"
variant="outlined"
:hide-details="false"
:rules="[ RequiredRule ]"
autofocus
required
>
<template #append-inner>
<password-input-eye-icons
:is-visible="isPassphraseVisible"
type="passphrase"
@toggleVisibility="isPassphraseVisible = !isPassphraseVisible"
/>
</template>
</v-text-field>
</v-col>
</v-row>
</v-form>
</v-card-item>
<v-divider />
<v-card-actions class="pa-4">
<v-col>
<v-btn
variant="outlined"
color="default"
block
:disabled="isLoading"
@click="() => isSkipping ? model = false : onSkip()"
>
{{ isSkipping ? 'No, skip just now' : 'Skip' }}
</v-btn>
</v-col>
<v-col>
<v-btn
color="primary"
variant="flat"
block
:loading="isLoading"
:disabled="!formValid"
@click="() => isSkipping ? onSkip(true) : onContinue()"
>
{{ isSkipping ? 'Yes, always skip' : 'Continue ->' }}
</v-btn>
</v-col>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script setup lang="ts">
import { Component, computed, ref, watch } from 'vue';
import {
VBtn,
VCard,
VCardActions,
VCardItem,
VCardTitle,
VCol,
VDialog,
VDivider,
VForm,
VRow,
VTextField,
} from 'vuetify/components';
import { RequiredRule } from '@/types/common';
import { useAnalyticsStore } from '@/store/modules/analyticsStore';
import { useBucketsStore } from '@/store/modules/bucketsStore';
import { useAppStore } from '@/store/modules/appStore';
import { useProjectsStore } from '@/store/modules/projectsStore';
import { useLoading } from '@/composables/useLoading';
import {
AnalyticsErrorEventSource,
AnalyticsEvent,
} from '@/utils/constants/analyticsEventNames';
import { useNotify } from '@/utils/hooks';
import { useUsersStore } from '@/store/modules/usersStore.js';
import PasswordInputEyeIcons from '@/components/PasswordInputEyeIcons.vue';
const analyticsStore = useAnalyticsStore();
const bucketsStore = useBucketsStore();
const appStore = useAppStore();
const projectsStore = useProjectsStore();
const usersStore = useUsersStore();
const notify = useNotify();
const { isLoading, withLoading } = useLoading();
const passphrase = ref<string>('');
const isPassphraseVisible = ref<boolean>(false);
const isSkipping = ref<boolean>(false);
const innerContent = ref<Component | null>(null);
const formValid = ref<boolean>(false);
const model = computed({
get: () => appStore.state.isProjectPassphraseDialogShown,
set: appStore.toggleProjectPassphraseDialog,
});
const emit = defineEmits<{
(event: 'passphraseEntered'): void,
}>();
function onSkip(confirmed = false): void {
if (!confirmed) {
isSkipping.value = true;
return;
}
withLoading(async () => {
try {
await usersStore.updateSettings({ passphrasePrompt: false });
model.value = false;
} catch (error) {
notify.notifyError(error, AnalyticsErrorEventSource.CREATE_PROJECT_PASSPHRASE_MODAL);
}
});
}
async function onContinue(): Promise<void> {
analyticsStore.eventTriggered(AnalyticsEvent.PASSPHRASE_CREATED, {
method: 'enter',
});
bucketsStore.setPassphrase(passphrase.value);
bucketsStore.setPromptForPassphrase(false);
model.value = false;
}
watch(innerContent, comp => {
if (!comp) {
passphrase.value = '';
}
});
</script>