Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor profile edit form #632

Merged
merged 3 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions src/lancie-my-area/lancie-profile-edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../../bower_components/neon-animation/web-animations.html">
<link rel="import" href="../../bower_components/paper-item/paper-item.html">
<link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
<link rel="import" href="../../bower_components/lancie-form/lancie-form.html">

<link rel="import" href="../lancie-icons.html">

<dom-module id="lancie-profile-edit">
<template>
<style>
:host {
display: block;
max-width: 500px;
--input-width: 200px;
}

.input-groups > div {
display: flex;
flex: 1;
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;
}
.group {
display: flex;
flex: 1;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}

iron-icon {
padding: 8px;
margin: 24px 8px 0 0;
}

paper-dropdown-menu {
width: var(--input-width);
}

.dropdown-content {
min-width: 120px;
}

/*
Workaround for a bug that causes paper-input
with type="date" not being editable when empty
(PolymerElements/paper-input/issues/352).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is no longer needed when updating paper-input to 2.2.0 according to this.

Copy link
Member Author

@elarb elarb Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We updated to 2.2.0 before the issue this fix is for appeared (#585)

*/
paper-input[type="date"] {
--paper-input-container-input: {
min-height: 1px;
};
width: var(--input-width);
}
</style>

<lancie-form id="form" refurl="users/current/profile" on-response="onProfileUpdate" no-reset on-enter="_submit">
<div class="input-groups">
<div>
<iron-icon icon="lancie:account-circle"></iron-icon>
<div class="group">
<paper-input label="First Name" name="firstName" type="text" value="{{profile.firstName}}" required></paper-input>
<paper-input label="Last Name" name="lastName" type="text" value="{{profile.lastName}}" required></paper-input>
<paper-input label="Display Name" name="displayName" type="text" value="{{profile.displayName}}" required></paper-input>
<paper-dropdown-menu label="Gender" name="gender" required>
<paper-listbox class="dropdown-content" slot="dropdown-content" selected="{{profile.gender}}" attr-for-selected="data-value">
<paper-item data-value="MALE">MALE</paper-item>
<paper-item data-value="FEMALE">FEMALE</paper-item>
<paper-item data-value="OTHER">OTHER</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</div>
</div>
<div>
<iron-icon icon="lancie:cake"></iron-icon>
<paper-input label="Birthday" name="birthday" type="date" value="{{profile.birthday}}" required></paper-input>
</div>
<div>
<iron-icon icon="lancie:phone"></iron-icon>
<paper-input label="Phone Number" name="phoneNumber" type="text" value="{{profile.phoneNumber}}" required></paper-input>
</div>
<div>
<iron-icon icon="lancie:location-on"></iron-icon>
<div class="group">
<paper-input label="Address" name="address" type="text" value="{{profile.address}}" required></paper-input>
<paper-input label="Zipcode" name="zipcode" type="text" value="{{profile.zipcode}}" required></paper-input>
<paper-input label="City" name="city" type="text" value="{{profile.city}}" required></paper-input>
</div>
</div>
</div>
</lancie-form>

</template>
<script>
class LancieProfileEdit extends Polymer.Element {
static get is() {
return 'lancie-profile-edit';
}
static get properties() {
return {
user: Object,
profile: Object,
profileChanged: Boolean,
};
}
static get observers() {
return ['_userChanged(user)', '_profileChanged(profile.*)'];
}
connectedCallback() {
super.connectedCallback();
this.profileChanged = false;
}
validateAndSubmit() {
if (this.profileChanged) {
return this.$.form.validateAndSubmit();
}
this._fireToast('There are no profile changes');
}
validate() {
return this.$.form.validate();
}
onProfileUpdate(e, req) {
if (req.succeeded) {
this.set('user.profile', req.response.object);
this._submit();
this.dispatchEvent(new CustomEvent('profile-submitted', {
bubbles: true,
composed: true
}));
this._fireToast('Profile successfully updated!');
this.profileChanged = false;
} else {
if (req.request.status === 409) {
this._fireToast('Display name already in use');
} else {
this._fireToast('Profile update failed');
}
this.set('profile', this.user.profile);
}
}
_userChanged(user) {
if (!!user && !this.profile) {
this.profile = user.profile;
}
}
_profileChanged(profile) {
this.profileChanged = true;
}
_submit() {
this.dispatchEvent(new CustomEvent('profile-form-submit', {
bubbles: true,
composed: true
}));
}
_fireToast(text) {
this.dispatchEvent(new CustomEvent('toast', {
detail: {text},
bubbles: true,
composed: true
}));
}
}
customElements.define(LancieProfileEdit.is, LancieProfileEdit);

</script>
</dom-module>
4 changes: 2 additions & 2 deletions src/lancie-my-area/my-area-profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="import" href="../../bower_components/lancie-ajax/lancie-ajax.html">
<link rel="import" href="../../bower_components/lancie-login-form/lancie-passwords.html">
<link rel="import" href="../lancie-icons.html">
<link rel="import" href="profile-edit-form.html">
<link rel="import" href="lancie-profile-edit.html">

<dom-module id="my-area-profile">
<template>
Expand Down Expand Up @@ -89,7 +89,7 @@
</div>
</div>
</div>
<profile-edit-form id="profileForm" hidden$="[[!editingProfile]]" user={{user}} on-profile-form-submit="submitEdit"></profile-edit-form>
<lancie-profile-edit id="profileForm" hidden$="[[!editingProfile]]" user={{user}} on-profile-form-submit="submitEdit"></lancie-profile-edit>

<hr>
<div class="layout horizontal center">
Expand Down
148 changes: 0 additions & 148 deletions src/lancie-my-area/profile-edit-form.html

This file was deleted.

8 changes: 6 additions & 2 deletions src/lancie-ticket-page/lancie-ticket-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="import" href="lancie-tickets.html">
<link rel="import" href="lancie-ticket-basket.html">
<link rel="import" href="lancie-terms-of-service-text.html">
<link rel="import" href="../lancie-my-area/profile-edit-form.html">
<link rel="import" href="../lancie-my-area/lancie-profile-edit.html">
<link rel="import" href="../lancie-storage/lancie-order-storage.html">
<link rel="import" href="../lancie-login/lancie-login.html">

Expand Down Expand Up @@ -78,6 +78,10 @@
pointer-events: none;
}

lancie-profile-edit {
margin: 0 auto;
}

@media(max-width: 500px) {
:host{
padding: 0;
Expand Down Expand Up @@ -131,7 +135,7 @@

<div>
<h2>Fill in your profile</h2>
<profile-edit-form id="profileForm" user="{{user}}" on-profile-submitted="profileConfirmed"></profile-edit-form>
<lancie-profile-edit id="profileForm" user="{{user}}" on-profile-submitted="profileConfirmed"></lancie-profile-edit>
</div>

<div>
Expand Down