-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.vue
More file actions
228 lines (200 loc) · 5.86 KB
/
Copy pathindex.vue
File metadata and controls
228 lines (200 loc) · 5.86 KB
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
<script setup lang="ts">
import { ref, computed, useTemplateRef } from 'vue';
import { TextInput, BrandButton, CheckboxInput, NoticeBar, NoticeBarTypes } from '@thunderbirdops/services-ui';
import { PhArrowRight } from '@phosphor-icons/vue';
import { TBPRO_WAIT_LIST } from '@kc/defines';
const firstError = window._page.currentView?.firstError;
const formAction = window._page.currentView?.formAction;
const rememberMe = window._page.currentView?.rememberMe;
const forgotPasswordUrl = window._page.currentView?.forgotPasswordUrl;
const supportUrl = window._page.currentView?.supportUrl;
const loginForm = useTemplateRef('login-form');
const message = window._page?.message;
const tbProPrimaryDomain = window._page.currentView?.tbProPrimaryDomain;
const onSubmit = () => {
if (loginForm.value.checkValidity()) {
loginForm?.value?.submit();
}
};
const usernameError = computed(() => {
return firstError ? '' : null;
});
const passwordError = computed(() => {
return firstError ? '' : null;
});
// CheckboxInput requires a valid ref as a model to show the check icon
const rememberMeChecked = ref(rememberMe);
const username = ref(window._page.currentView?.loginHint);
const showUsernameHelpText = ref(false);
const usernameLocalPart = ref('');
const suggestedUsername = computed(() => `${usernameLocalPart.value}@${tbProPrimaryDomain}`);
const onUsernameBlur = (e: Event) => {
const inputValue = (e.target as HTMLInputElement).value.toLowerCase();
const [localPart, domain] = inputValue.split('@');
usernameLocalPart.value = localPart;
showUsernameHelpText.value = localPart && (!domain || domain !== tbProPrimaryDomain);
};
const onUsernameHelpTextClick = () => {
username.value = suggestedUsername.value;
showUsernameHelpText.value = false;
};
defineProps<{
hidePassword: boolean;
}>();
</script>
<script lang="ts">
export default {
name: 'LoginView',
};
</script>
<template>
<notice-bar :type="NoticeBarTypes.Critical" v-if="firstError" class="notice-bar-login">{{ firstError }}</notice-bar>
<notice-bar :type="NoticeBarTypes.Info" v-else-if="!message?.type" class="notice-bar-login">
<i18n-t keypath="inviteOnly" tag="span">
<a :href="TBPRO_WAIT_LIST" data-testid="go-to-invite-only-url" target="_blank">{{ $t('inviteOnlyAction') }}</a>
</i18n-t>
</notice-bar>
<h2 data-testid="header-text">{{ $t('loginAccountTitle') }}</h2>
<form
id="kc-form-login"
ref="login-form"
method="POST"
:action="formAction"
@submit.prevent="onSubmit"
@keyup.enter="onSubmit"
>
<div class="form-elements">
<div>
<text-input
data-testid="username-input"
id="username"
name="username"
required
autocomplete="username webauthn"
autofocus
:error="usernameError"
v-model="username"
@blur="onUsernameBlur"
>
{{ $t('email') }}
</text-input>
<div aria-live="polite">
<i18n-t v-if="showUsernameHelpText" class="username-help-text" keypath="usernameDomainSuggestion" tag="p">
<button
ref="username-suggestion-btn"
type="button"
data-testid="username-suggestion-btn"
@click="onUsernameHelpTextClick"
>
{{ suggestedUsername }}
</button>
</i18n-t>
</div>
</div>
<text-input
v-if="!hidePassword"
data-testid="password-input"
id="password"
name="password"
required
autocomplete="current-password"
type="password"
:error="passwordError"
>
{{ $t('password') }}
</text-input>
</div>
<a v-if="forgotPasswordUrl && !hidePassword" :href="forgotPasswordUrl" class="forgot-password-link">
{{ $t('doForgotPassword') }}
</a>
<checkbox-input
data-testid="remember-me-input"
name="keep-me-signed-in"
:label="$t('rememberMe')"
v-model="rememberMeChecked"
></checkbox-input>
<div class="buttons">
<brand-button data-testid="submit-btn" class="submit" @click="onSubmit">
{{ $t('doLogIn') }}
<template #iconRight>
<ph-arrow-right size="20" />
</template>
</brand-button>
</div>
</form>
<div class="footer-link-container">
<!--
<template v-if="registerUrl">
<i18n-t keypath="goToRegister" tag="span">
<a :href="registerUrl" data-testid="go-to-register-url">{{ $t('goToRegisterAction') }}</a>
</i18n-t>
</template>
-->
<i18n-t keypath="needHelp" tag="span">
<a :href="supportUrl" data-testid="go-to-support-url">{{ $t('needHelpAction') }}</a>
</i18n-t>
</div>
</template>
<style scoped>
.notice-bar-login {
margin-bottom: 1.5rem;
}
h2 {
font-size: 2.25rem;
font-family: metropolis;
font-weight: normal;
letter-spacing: -0.36px;
line-height: 1.2;
color: var(--colour-primary-default);
margin: 0 0 1.5rem 0;
}
form {
margin-block-end: 2.625rem;
}
.forgot-password-link {
display: inline-block;
font-size: 0.6875rem;
color: var(--colour-ti-muted);
margin-block-end: 2rem;
}
.footer-link-container {
display: flex;
gap: 0.425rem;
flex-wrap: wrap;
justify-content: flex-end;
font-size: 0.75rem;
color: var(--colour-ti-secondary);
a {
color: var(--colour-ti-secondary);
}
}
.form-elements {
display: flex;
flex-direction: column;
gap: 1.5rem;
margin-bottom: 0.5rem;
.username-help-text {
font-size: 0.6875rem;
color: var(--colour-ti-muted);
margin-block: 0.5rem 0;
button {
all: unset;
color: var(--colour-primary-default);
text-decoration: underline;
cursor: pointer;
&:focus-visible {
outline: 2px solid var(--colour-primary-default);
outline-offset: 2px;
}
}
}
}
.buttons {
margin-top: var(--space-24);
width: 100%;
.submit {
margin-right: 0;
margin-left: auto;
}
}
</style>