diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a240925ed..a3b19d456 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -77,7 +77,7 @@ class ApplicationController < ActionController::Base # terms of service :tos_agreement, # profile stuff - :bio, :location, :latitude, :longitude, + :bio, # email settings :show_email, :send_notification_email, :send_planting_reminder, :send_harvest_reminder) end @@ -88,7 +88,7 @@ class ApplicationController < ActionController::Base # terms of service :tos_agreement, # profile stuff - :bio, :location, :latitude, :longitude, + :bio, :website_url, :instagram_handle, :facebook_handle, :bluesky_handle, :other_url, # email settings :show_email, :send_notification_email, :send_planting_reminder, :send_harvest_reminder, diff --git a/app/views/devise/registrations/_edit_profile.html.haml b/app/views/devise/registrations/_edit_profile.html.haml index e3251cdc1..b00d8f149 100644 --- a/app/views/devise/registrations/_edit_profile.html.haml +++ b/app/views/devise/registrations/_edit_profile.html.haml @@ -4,11 +4,19 @@ %br/ = render 'devise/shared/error_messages', resource: resource + -# Only places we found can be saved, so the location is set in its dialog, + -# not typed here. Choosing a place saves it and reloads the page. .row.mb-3 - = f.label :location, 'Your location', class: 'col-form-label col-md-2' + %span.col-form-label.col-md-2 Your location .col-md-8 - = f.text_field :location, autocomplete: "off", class: 'form-control' - %span.form-text This will be displayed on a map. You can be as detailed or vague as you like. + - link = 'btn btn-link p-0 align-baseline' + %p.mb-0 + - if resource.location.present? + %strong= resource.location + = render 'home/dashboard/location_picker', label: 'Change', button_class: link + - else + = render 'home/dashboard/location_picker', label: 'Set your location', button_class: link + %span.form-text Pick from the places we find, so you're in the right spot on the map. A region is fine. .row.mb-3 = f.label :bio, class: 'col-form-label col-md-2' diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 7a6c9829c..0807e3617 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -3,6 +3,10 @@ - content_for :breadcrumbs do %li.breadcrumb-item= link_to 'My Profile', member_path(current_member) +-# The location link opens a dialog, which is a React island. +- content_for :scripts do + = javascript_include_tag 'react_islands', defer: true + %h1 = member_icon Settings for #{current_member.login_name} diff --git a/spec/requests/registrations_controller_update_spec.rb b/spec/requests/registrations_controller_update_spec.rb new file mode 100644 index 000000000..282d33297 --- /dev/null +++ b/spec/requests/registrations_controller_update_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe RegistrationsController, '#update' do + let(:member) { create(:member, bio: 'Hello') } + + before do + sign_in member + put member_registration_path, params: { member: { bio: 'Hello again', location: 'somewhere over the rainbow' } } + end + + it 'saves the rest of the profile' do + expect(member.reload.bio).to eq('Hello again') + end + + it 'does not take a location typed in' do + expect(member.reload.location).to be_blank + end +end diff --git a/spec/views/devise/registrations/edit_spec.rb b/spec/views/devise/registrations/edit_spec.rb index 6254c65e2..9e499be90 100644 --- a/spec/views/devise/registrations/edit_spec.rb +++ b/spec/views/devise/registrations/edit_spec.rb @@ -50,8 +50,17 @@ describe 'devise/registrations/edit.html.haml', type: "view" do assert_select "textarea[id=member_bio]" end - it 'shows location field' do - assert_select "input[id=member_location][type=text]" + it 'has no location text field' do + assert_select "input[id=member_location]", count: 0 + end + + it 'loads the script that makes the location link work' do + render + expect(view.content_for(:scripts)).to include('react_islands') + end + + it 'has a link to set the location in its dialog' do + assert_select "[data-react-component=LocationPicker]" end end