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
Add user profile page content #2445
Conversation
Sorry, I think me merging #2438 caused some conflicts. There's also some js lint causing the build to fail. |
f1f649c
to
a13d6c1
Compare
Rebased on the latest |
I'm also taking a look at this. |
I reset the user_profile table with the defaults given above, but am getting this error when filling out the profile again:
I'll drop all rows and try again. |
Hmm after dropping the rows, I'm getting this:
I may have borked the database. Will flush and recreate. |
Not a database thing. That code is just wrong. It should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, works well. Leaving some style comments on the code, but overall this looks really good.
src/mmw/js/src/account/views.js
Outdated
}, | ||
|
||
initialize: function(){ | ||
this.listenTo(this.model, 'change', this.render); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with the Marionette modelEvents
hash, like so:
events: {
'click @ui.saveChanges': 'saveChanges',
},
modelEvents: {
'change': 'render',
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup 2259d26
src/mmw/js/src/account/views.js
Outdated
|
||
onRender: function() { | ||
var self = this; | ||
function addOptions(model, field, selectedValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For stylistic consistency, prefer defining this as a variable:
var self = this,
addOptions = function(model, field, selectedValue) {
...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup 2259d26
src/mmw/js/src/account/views.js
Outdated
saving: true | ||
}, | ||
{ | ||
success: function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For stylistic consistency, prefer defining this using done
, fail
, and always
:
var model = this.model;
model.save({ ... })
.done(function() {
App.user.set('profile_is_complete', true);
})
.fail(function() {
model.set('error', 'There was a problem saving your profile.');
})
.always(function() {
model.set('saving', false);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup 2259d26
src/mmw/js/src/account/views.js
Outdated
@@ -125,14 +183,17 @@ var AccountContainerView = Marionette.LayoutView.extend({ | |||
|
|||
initialize: function() { | |||
this.tokenModel = new models.ApiTokenModel(); | |||
this.profileModel = new userModels.UserProfileModel(App.user.attributes.profile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer App.user.get('profile')
rather than directly accessing the attributes
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup 2259d26
src/mmw/js/src/user/models.js
Outdated
@@ -60,6 +60,14 @@ var UserModel = Backbone.Model.extend({ | |||
var UserProfileModel = Backbone.Model.extend({ | |||
defaults: { | |||
was_skipped: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this was_skipped
still used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup db7e61d
src/mmw/js/src/user/models.js
Outdated
last_name: null, | ||
organization: null, | ||
user_type: 'Unspecified', | ||
country: 'US', | ||
was_skipped: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup db7e61d
Thanks for the excellent feedback. I have implemented all the suggestions and I have simplified the serializer to avoid the 500 errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/mmw/js/src/account/views.js
Outdated
onRender: function() { | ||
var self = this, | ||
addOptions = function(model, field, selectedValue) { | ||
$.each(window.clientSettings.choices[model][field], function(index, choice) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider prepending an unselected value, or defaulting to the US. It currently displays "Afghanistan" if you haven't given a country.
Also, consider importing core/settings
instead of pulling it off the window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a specific set of steps that resulted in the country defaulting to Afghanistan
? US
is specified as the default in both the backend and frontend and when I registered a new account it did show US as the default.
default=countries.US) |
{{ select(country, 'country', 'UserProfile', 'country', 'US', 'Country') }} |
I will switch to an import for client settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran the query in your testing instructions and refreshed /account
. I think we're setting the default for the modal, but not the profile page:
{{ select(country, 'country', 'UserProfile', 'country', country, 'Country') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll dig into that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup 098ea6f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still uses window.clientSettings
, but I think that's okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Lost commit. Actually fixed in the last rebase.
src/mmw/js/src/account/views.js
Outdated
}); | ||
self.$el.find('#' + field).selectpicker(); | ||
}; | ||
addOptions('UserProfile', 'country', self.model.attributes.country); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another spot where you might consider using .get('country')
like we do for the rest of the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fixup 098ea6f
Thanks again for all the help. I think this is ready to go. |
Tested this out again and am seeing United States as the default. |
098ea6f
to
b2c0a72
Compare
Just realized something while trying to recreate #2460: If you have a "fresh" user with This is an edge case if you'd like to spin it off to a new card. |
This commit adds a form on the "profile" tab of `/account` to display and edit user profile details. - I moved the saving of the profile to a Django REST Framework serializer to keep the persistence details out of the view. - I styled the text fields on the form to match the wireframes but I did not style the bootstrap-select dropdown menus. We will be restyling them across the app in a future commit.
b2c0a72
to
81db33f
Compare
Overview
This commit adds a form on the "profile" tab of
/account
to display and edit user profile details.Connects #2365
Demo
Notes
Testing Instructions
Save changed
. Verify that a spinner briefly appears.vagrant ssh app -c 'sudo stop mmw-app'
Save changes
and verify that an error message is displayed.