Browse Source

Merge pull request #2651 from nocodb/feat/signup

feat(gui-v2): update signup form
pull/2718/head
Braks 2 years ago committed by GitHub
parent
commit
737b48b223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui-v2/composables/useGlobalState.ts
  2. 32
      packages/nc-gui-v2/pages/signin.vue
  3. 139
      packages/nc-gui-v2/pages/signup.vue

2
packages/nc-gui-v2/composables/useGlobalState.ts

@ -132,7 +132,7 @@ export const useGlobalState = (): GlobalState => {
watch( watch(
() => !!(payload && payload.exp && payload.exp - 5 * 60 < timestamp / 1000), () => !!(payload && payload.exp && payload.exp - 5 * 60 < timestamp / 1000),
async (expiring) => { async (expiring) => {
if (payload && expiring) { if (signedIn.value && payload && expiring) {
await refreshToken() await refreshToken()
} }
}, },

32
packages/nc-gui-v2/pages/signin.vue

@ -74,23 +74,21 @@ const resetError = () => {
<v-form <v-form
ref="formValidator" ref="formValidator"
v-model="valid" v-model="valid"
class="h-full md:h-3/4 min-h-[600px] flex justify-center items-center" class="h-full min-h-[600px] flex justify-center items-center"
@submit.prevent="signIn" @submit.prevent="signIn"
> >
<div class="h-full w-full flex flex-col flex-wrap justify-center items-center"> <div class="h-full w-full flex flex-col flex-wrap justify-center items-center">
<div <div
class="md:relative flex flex-col justify-center gap-2 w-full max-w-[500px] mx-auto p-8 md:(rounded-lg border-1 border-gray-200 shadow-lg)" class="bg-white dark:(!bg-gray-900 !text-white) md:relative flex flex-col justify-center gap-2 w-full max-w-[500px] mx-auto p-8 md:(rounded-lg border-1 border-gray-200 shadow-xl)"
> >
<div <div
style="left: -moz-calc(50% - 45px); left: -webkit-calc(50% - 45px); left: calc(50% - 45px)" style="left: -moz-calc(50% - 45px); left: -webkit-calc(50% - 45px); left: calc(50% - 45px)"
class="absolute top-12 md:top-[-65px] rounded-lg bg-primary" class="absolute top-12 md:top-[-10%] rounded-lg bg-primary"
> >
<img width="90" height="90" src="~/assets/img/icons/512x512-trans.png" /> <img width="90" height="90" src="~/assets/img/icons/512x512-trans.png" />
</div> </div>
<h1 class="prose-xl self-center">{{ $t('general.signIn') }}</h1> <h1 class="prose-2xl font-bold self-center my-4">{{ $t('general.signIn') }}</h1>
<v-divider class="mb-4" />
<Transition name="layout"> <Transition name="layout">
<div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 p-1"> <div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 p-1">
@ -101,8 +99,11 @@ const resetError = () => {
<v-text-field <v-text-field
id="email" id="email"
v-model="form.email" v-model="form.email"
class="bg-white dark:!bg-gray-900"
:rules="formRules.email" :rules="formRules.email"
:label="$t('labels.email')" :label="$t('labels.email')"
:placeholder="$t('labels.email')"
:persistent-placeholder="true"
type="text" type="text"
@focus="resetError" @focus="resetError"
/> />
@ -110,8 +111,11 @@ const resetError = () => {
<v-text-field <v-text-field
id="password" id="password"
v-model="form.password" v-model="form.password"
class="bg-white dark:!bg-gray-900"
:rules="formRules.password" :rules="formRules.password"
:label="$t('labels.password')" :label="$t('labels.password')"
:placeholder="$t('labels.password')"
:persistent-placeholder="true"
type="password" type="password"
@focus="resetError" @focus="resetError"
/> />
@ -125,7 +129,11 @@ const resetError = () => {
<div class="self-center flex items-center justify-between w-100"> <div class="self-center flex items-center justify-between w-100">
<button <button
:disabled="!valid" :disabled="!valid"
:class="[!valid ? '!opacity-50 !cursor-default' : 'shadow-md hover:(text-primary bg-primary/25)']" :class="[
!valid
? '!opacity-50 !cursor-default'
: 'shadow-md hover:(text-primary bg-primary/10 dark:text-white dark:!bg-primary/50)',
]"
class="ml-1 border-1 border-solid border-gray-300 transition-color duration-100 ease-in rounded-lg p-4 bg-gray-100/50" class="ml-1 border-1 border-solid border-gray-300 transition-color duration-100 ease-in rounded-lg p-4 bg-gray-100/50"
type="submit" type="submit"
> >
@ -141,3 +149,13 @@ const resetError = () => {
</v-form> </v-form>
</NuxtLayout> </NuxtLayout>
</template> </template>
<style lang="scss">
.v-field__field {
@apply bg-white dark:(!bg-gray-900 text-white);
input {
@apply bg-white dark:(!bg-gray-700) !appearance-none my-1 border-1 border-solid border-primary/50 rounded;
}
}
</style>

139
packages/nc-gui-v2/pages/signup.vue

@ -1,64 +1,147 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
import { navigateTo } from '#app' import { navigateTo } from '#app'
import { isEmail } from '~/utils/validation'
import MaterialSymbolsWarning from '~icons/material-symbols/warning'
import MaterialSymbolsRocketLaunchOutline from '~icons/material-symbols/rocket-launch-outline'
const { $api, $state } = useNuxtApp() const { $api, $state } = useNuxtApp()
const { t } = useI18n()
definePageMeta({ definePageMeta({
requiresAuth: false, requiresAuth: false,
}) })
const error = ref() const valid = ref()
let error = $ref<string | null>(null)
const form = reactive({ const form = reactive({
email: '', email: '',
password: '', password: '',
passwordRepeat: '',
}) })
const formRules = {
email: [
// E-mail is required
(v: string) => !!v || t('msg.error.signUpRules.emailReqd'),
// E-mail must be valid format
(v: string) => isEmail(v) || t('msg.error.signUpRules.emailInvalid'),
],
password: [
// Password is required
(v: string) => !!v || t('msg.error.signUpRules.passwdRequired'),
(v: string) => v.length >= 8 || t('msg.error.signUpRules.passwdLength'),
],
passwordRepeat: [
// Passwords match
(v: string) => v === form.password || t('msg.error.signUpRules.passwdMismatch'),
],
}
const signUp = async () => { const signUp = async () => {
error.value = null error = null
try { try {
const { token } = await $api.auth.signup(form) const { token } = await $api.auth.signup(form)
$state.token.value = token! $state.signIn(token!)
navigateTo('/projects') await navigateTo('/projects')
} catch (e: any) { } catch (e: any) {
error.value = await extractSdkResponseErrorMsg(e) error = await extractSdkResponseErrorMsg(e)
}
}
const resetError = () => {
if (error) {
error = null
} }
} }
</script> </script>
<template> <template>
<div> <NuxtLayout>
<!-- Enter your work email --> <v-form
<v-card class="pa-10 mx-auto mt-10" style="max-width: 500px"> ref="formValidator"
<v-card-text> v-model="valid"
<v-alert v-if="error" class="mb-4" type="error"> class="h-full min-h-[600px] flex justify-center items-center"
{{ error }} @submit.prevent="signUp"
</v-alert> >
<div class="h-full w-full flex flex-col flex-wrap justify-center items-center">
<div
class="bg-white dark:(!bg-gray-900 !text-white) md:relative flex flex-col justify-center gap-2 w-full max-w-[500px] mx-auto p-8 md:(rounded-lg border-1 border-gray-200 shadow-xl)"
>
<div
style="left: -moz-calc(50% - 45px); left: -webkit-calc(50% - 45px); left: calc(50% - 45px)"
class="absolute top-12 md:top-[-10%] rounded-lg bg-primary"
>
<img width="90" height="90" src="~/assets/img/icons/512x512-trans.png" />
</div>
<div class="p-float-label"> <h1 class="prose-2xl font-bold self-center my-4">{{ $t('general.signUp') }}</h1>
<v-text-field id="email" v-model="form.email" :label="$t('labels.email')" type="text" style="width: 100%" />
</div> <Transition name="layout">
<div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 p-1">
<div class="flex items-center gap-2 justify-center"><MaterialSymbolsWarning /> {{ error }}</div>
</div>
</Transition>
<v-text-field
id="email"
v-model="form.email"
class="bg-white dark:!bg-gray-900"
:rules="formRules.email"
:label="$t('labels.email')"
:placeholder="$t('labels.email')"
:persistent-placeholder="true"
type="text"
@focus="resetError"
/>
<!-- Enter your password -->
<div class="p-float-label">
<v-text-field <v-text-field
id="password" id="password"
v-model="form.password" v-model="form.password"
class="bg-white dark:!bg-gray-900"
:rules="formRules.password"
:label="$t('labels.password')" :label="$t('labels.password')"
:placeholder="$t('labels.password')"
:persistent-placeholder="true"
type="password" type="password"
style="width: 100%" @focus="resetError"
/> />
</div>
<div class="text-center"> <v-text-field
<v-btn class="" @click="signUp"> id="password_repeat"
<b>{{ $t('general.signUp') }}</b> v-model="form.password"
</v-btn> class="bg-white dark:!bg-gray-900"
:rules="formRules.passwordRepeat"
:label="`Repeat ${$t('labels.password')}`"
:placeholder="`Repeat ${$t('labels.password')}`"
:persistent-placeholder="true"
type="password"
@focus="resetError"
/>
<div class="self-center flex items-center justify-between w-full">
<button
:disabled="!valid"
:class="[
!valid
? '!opacity-50 !cursor-default'
: 'shadow-md hover:(text-primary bg-primary/10 dark:text-white dark:!bg-primary/50)',
]"
class="ml-1 border-1 border-solid border-gray-300 transition-color duration-100 ease-in rounded-lg p-4 bg-gray-100/50"
type="submit"
>
<span class="flex items-center gap-2"><MaterialSymbolsRocketLaunchOutline /> {{ $t('general.signUp') }}</span>
</button>
<div class="text-end prose-sm">
{{ $t('msg.info.signUp.alreadyHaveAccount') }}
<nuxt-link class="text-primary underline hover:opacity-75" to="/signin">{{ $t('general.signIn') }}</nuxt-link>
</div>
</div>
</div> </div>
</v-card-text> </div>
</v-card> </v-form>
</div> </NuxtLayout>
</template> </template>
<style scoped></style>

Loading…
Cancel
Save