2021-08-14 19:43:19 +02:00
|
|
|
<template>
|
|
|
|
<div id="login-form">
|
|
|
|
<div id="user-form">
|
|
|
|
<div class="form-box">
|
|
|
|
<form @submit.prevent="onSubmit(action)">
|
|
|
|
<div class="form-items">
|
|
|
|
<input
|
|
|
|
v-if="action === 'register'"
|
|
|
|
id="username"
|
|
|
|
required
|
|
|
|
v-model="formData.username"
|
|
|
|
:placeholder="t('user.USERNAME')"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
id="email"
|
|
|
|
required
|
|
|
|
type="email"
|
|
|
|
v-model="formData.email"
|
|
|
|
:placeholder="t('user.EMAIL')"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
id="password"
|
|
|
|
required
|
|
|
|
type="password"
|
|
|
|
v-model="formData.password"
|
|
|
|
:placeholder="t('user.PASSWORD')"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
v-if="action === 'register'"
|
|
|
|
id="confirm-password"
|
|
|
|
type="password"
|
|
|
|
required
|
|
|
|
v-model="formData.password_conf"
|
|
|
|
:placeholder="t('user.PASSWORD-CONFIRM')"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-08-15 08:33:03 +02:00
|
|
|
<button type="submit">{{ t(buttonText) }}</button>
|
2021-08-14 19:43:19 +02:00
|
|
|
</form>
|
2021-08-15 10:50:39 +02:00
|
|
|
<ErrorMessage :message="errorMessages" v-if="errorMessages" />
|
2021-08-14 19:43:19 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-08-15 08:33:03 +02:00
|
|
|
import { ComputedRef, computed, defineComponent, reactive } from 'vue'
|
2021-08-14 19:43:19 +02:00
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
|
|
import { IFormData } from '@/interfaces'
|
|
|
|
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
|
|
|
import { useStore } from '@/use/useStore'
|
2021-08-15 10:50:39 +02:00
|
|
|
import ErrorMessage from '@/components/Common/ErrorMessage.vue'
|
2021-08-14 19:43:19 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'LoginForm',
|
2021-08-15 10:50:39 +02:00
|
|
|
components: {
|
|
|
|
ErrorMessage,
|
|
|
|
},
|
2021-08-14 19:43:19 +02:00
|
|
|
props: {
|
|
|
|
action: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2021-08-15 08:33:03 +02:00
|
|
|
setup(props) {
|
2021-08-14 19:43:19 +02:00
|
|
|
const formData: IFormData = reactive({
|
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
password: '',
|
|
|
|
password_conf: '',
|
|
|
|
})
|
|
|
|
const { t } = useI18n()
|
|
|
|
const store = useStore()
|
2021-08-15 08:33:03 +02:00
|
|
|
|
|
|
|
const buttonText: ComputedRef<string> = computed(() =>
|
|
|
|
props.action === 'register' ? 'buttons.REGISTER' : 'buttons.LOGIN'
|
|
|
|
)
|
2021-08-15 10:50:39 +02:00
|
|
|
const errorMessages: ComputedRef<string | string[] | null> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
|
2021-08-15 08:33:03 +02:00
|
|
|
)
|
|
|
|
|
2021-08-14 19:43:19 +02:00
|
|
|
function onSubmit(actionType: string) {
|
|
|
|
return store.dispatch(USER_STORE.ACTIONS.LOGIN_OR_REGISTER, {
|
|
|
|
actionType,
|
|
|
|
formData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
t,
|
2021-08-15 08:33:03 +02:00
|
|
|
buttonText,
|
2021-08-15 10:50:39 +02:00
|
|
|
errorMessages,
|
2021-08-14 19:43:19 +02:00
|
|
|
formData,
|
|
|
|
onSubmit,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~@/scss/base';
|
|
|
|
|
|
|
|
#login-form {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
margin: $default-margin 0;
|
2021-08-15 09:24:10 +02:00
|
|
|
height: 100%;
|
2021-08-14 19:43:19 +02:00
|
|
|
|
|
|
|
#user-form {
|
|
|
|
width: 60%;
|
|
|
|
|
|
|
|
button {
|
|
|
|
margin: $default-margin;
|
|
|
|
}
|
|
|
|
@media screen and (max-width: $medium-limit) {
|
|
|
|
margin-top: $default-margin;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-width: $medium-limit) {
|
|
|
|
height: auto;
|
2021-08-15 10:50:39 +02:00
|
|
|
margin-bottom: 50px;
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|