storj/web/satellite/src/components/account/EditProfilePopup.vue

252 lines
7.0 KiB
Vue
Raw Normal View History

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
2019-07-09 16:04:51 +01:00
<div class="edit-profile-popup-container">
<div class="edit-profile-popup">
<div class="edit-profile-popup__form-container">
<div class="edit-profile-row-container">
<div class="edit-profile-popup__form-container__avatar">
<h1 class="edit-profile-popup__form-container__avatar__letter">{{avatarLetter}}</h1>
2019-07-09 16:04:51 +01:00
</div>
<h2 class="edit-profile-popup__form-container__main-label-text">Edit Profile</h2>
2019-07-09 16:04:51 +01:00
</div>
<HeaderedInput
class="full-input"
label="Full Name"
2019-07-09 16:04:51 +01:00
placeholder="Enter Full Name"
width="100%"
ref="fullNameInput"
:error="fullNameError"
:init-value="userInfo.fullName"
@setData="setFullName"
/>
2019-07-09 16:04:51 +01:00
<HeaderedInput
class="full-input"
label="Nickname"
placeholder="Enter Nickname"
2019-07-09 16:04:51 +01:00
width="100%"
ref="shortNameInput"
:init-value="userInfo.shortName"
@setData="setShortName"
/>
2019-07-09 16:04:51 +01:00
<div class="edit-profile-popup__form-container__button-container">
<VButton
label="Cancel"
width="205px"
height="48px"
:on-press="onCloseClick"
is-white="true"
/>
<VButton
label="Update"
width="205px"
height="48px"
:on-press="onUpdateClick"
/>
2019-07-09 16:04:51 +01:00
</div>
</div>
<div class="edit-profile-popup__close-cross-container" @click="onCloseClick">
<CloseCrossIcon/>
2019-07-09 16:04:51 +01:00
</div>
</div>
</div>
</template>
<script lang="ts">
2019-09-09 11:33:39 +01:00
import { Component, Vue } from 'vue-property-decorator';
2019-09-09 11:33:39 +01:00
import HeaderedInput from '@/components/common/HeaderedInput.vue';
import VButton from '@/components/common/VButton.vue';
import CloseCrossIcon from '@/../static/images/common/closeCross.svg';
2019-09-09 11:33:39 +01:00
import { USER_ACTIONS } from '@/store/modules/users';
import { UpdatedUser } from '@/types/users';
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
2019-09-09 11:33:39 +01:00
@Component({
components: {
CloseCrossIcon,
2019-09-09 11:33:39 +01:00
HeaderedInput,
VButton,
},
2019-09-09 11:33:39 +01:00
})
export default class EditProfilePopup extends Vue {
private fullNameError: string = '';
2019-09-09 11:33:39 +01:00
private readonly userInfo: UpdatedUser =
new UpdatedUser(this.$store.getters.user.fullName, this.$store.getters.user.shortName);
2019-09-09 11:33:39 +01:00
public setFullName(value: string): void {
this.userInfo.setFullName(value);
this.fullNameError = '';
}
2019-09-09 11:33:39 +01:00
public setShortName(value: string): void {
this.userInfo.setShortName(value);
}
/**
* Validates name and tries to update user info and close popup.
*/
2019-09-09 11:33:39 +01:00
public async onUpdateClick(): Promise<void> {
if (!this.userInfo.isValid()) {
this.fullNameError = 'Full name expected';
2019-09-09 11:33:39 +01:00
return;
}
2019-09-09 11:33:39 +01:00
try {
await this.$store.dispatch(USER_ACTIONS.UPDATE, this.userInfo);
} catch (error) {
await this.$notify.error(error.message);
2019-09-09 11:33:39 +01:00
return;
}
2019-09-09 11:33:39 +01:00
await this.$notify.success('Account info successfully updated!');
2019-09-09 11:33:39 +01:00
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_EDIT_PROFILE_POPUP);
}
/**
* Closes popup.
*/
2019-09-09 11:33:39 +01:00
public onCloseClick(): void {
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_EDIT_PROFILE_POPUP);
}
/**
* Returns first letter of user name.
*/
2019-09-09 11:33:39 +01:00
public get avatarLetter(): string {
return this.$store.getters.userName.slice(0, 1).toUpperCase();
}
2019-09-09 11:33:39 +01:00
}
</script>
<style scoped lang="scss">
2019-07-10 10:55:40 +01:00
.edit-profile-row-container {
width: 100%;
display: flex;
flex-direction: row;
align-content: center;
justify-content: flex-start;
}
2019-07-10 10:55:40 +01:00
.edit-profile-popup-container {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(134, 134, 148, 0.4);
z-index: 1000;
display: flex;
justify-content: center;
align-items: center;
font-family: 'font_regular', sans-serif;
2019-07-10 10:55:40 +01:00
}
2019-07-10 10:55:40 +01:00
.input-container.full-input {
width: 100%;
}
2019-07-10 10:55:40 +01:00
.edit-profile-popup {
width: 100%;
max-width: 440px;
background-color: #fff;
2019-07-10 10:55:40 +01:00
border-radius: 6px;
display: flex;
flex-direction: row;
align-items: flex-start;
position: relative;
justify-content: center;
padding: 80px;
2019-07-10 10:55:40 +01:00
&__info-panel-container {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
margin-right: 100px;
margin-top: 20px;
}
2019-07-10 10:55:40 +01:00
&__form-container {
width: 100%;
max-width: 440px;
margin-top: 10px;
2019-07-10 10:55:40 +01:00
&__avatar {
width: 60px;
height: 60px;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
background: #e8eaf2;
2019-07-10 10:55:40 +01:00
margin-right: 20px;
&__letter {
font-family: 'font_medium', sans-serif;
2019-07-10 10:55:40 +01:00
font-size: 16px;
line-height: 23px;
color: #354049;
}
}
2019-07-10 10:55:40 +01:00
&__main-label-text {
font-family: 'font_bold', sans-serif;
2019-07-10 10:55:40 +01:00
font-size: 32px;
line-height: 60px;
color: #384b65;
2019-07-10 10:55:40 +01:00
margin-top: 0;
}
2019-07-10 10:55:40 +01:00
&__button-container {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 40px;
}
}
2019-07-10 10:55:40 +01:00
&__close-cross-container {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
right: 30px;
top: 40px;
height: 24px;
width: 24px;
cursor: pointer;
&:hover .close-cross-svg-path {
fill: #2683ff;
2019-07-10 10:55:40 +01:00
}
}
}
2019-07-10 10:55:40 +01:00
@media screen and (max-width: 720px) {
2019-07-10 10:55:40 +01:00
.edit-profile-popup {
2019-07-10 10:55:40 +01:00
&__info-panel-container {
display: none;
}
2019-07-10 10:55:40 +01:00
&__form-container {
2019-07-10 10:55:40 +01:00
&__button-container {
width: 100%;
}
}
}
}
</style>