From fe6a61a18cb0fce08d732f4579d18253be53157d Mon Sep 17 00:00:00 2001 From: Jade Stewart <114014697+jadekstewart3@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:57:14 -0700 Subject: [PATCH] Org profile theme (#341) * Add instance variables that will be used in the dashboard view * Add template html and begin inital formatting to utilize instance variables scoped to organization * Add components needed to utilize geeksui theme. Added avatar section- not yet functional * Play around with understanding avatarable, and look at orf_profiles edit view * standardrb * Add delegate to org_profile model to gain access to name attribute * Edit header to look more like Geeks UI theme, and add current org name * Edit card to have two columns as requested, comment code to make it clear and readable * Standardrb * Begin testing for organization profile edit * add translation * Add delegation back in * Tinker with views to see if nested attributes will start updating * Continue working on test to ensure full functionality on profile update * Create happy path testing for organization_profile edit page * Remove html formatting in update action, update profile params * Add and remove pry multiple times * Add delgate so we have access to organization name in the edit action * Remove name field and add in about us * Standard rb * Remove bang from update so flash messages appear correctly * Add email validation so users cannot enter an invalid email * Add sad path testing to ensure full functionality * Standard rb * Add tests for new and previous validations * Add Organization Details header and move avatar section out of card body * Add horizontal rule * Add condition to set organization, and remove set organization from org profil test suit * standardrb --- .../organization_profiles_controller.rb | 14 +- app/models/organization_profile.rb | 4 +- .../organization_profiles/_form.html.erb | 131 ++++++++++++------ .../organization_profiles/edit.html.erb | 8 +- config/locales/en.yml | 1 + test/controllers/root_controller_test.rb | 3 + .../organization_profile_edit_test.rb | 99 +++++++++++++ test/models/organization_profile_test.rb | 9 ++ test/test_helper.rb | 7 +- 9 files changed, 218 insertions(+), 58 deletions(-) create mode 100644 test/integration/organization_profile/organization_profile_edit_test.rb diff --git a/app/controllers/organizations/organization_profiles_controller.rb b/app/controllers/organizations/organization_profiles_controller.rb index e337dc43e..e101d5ccd 100644 --- a/app/controllers/organizations/organization_profiles_controller.rb +++ b/app/controllers/organizations/organization_profiles_controller.rb @@ -7,13 +7,10 @@ def edit def update @organization_profile = Current.organization.profile - - respond_to do |format| - if @organization_profile.update(organization_profile_params) - format.html { redirect_to dashboard_index_path, notice: "Profile updated" } - else - format.html { render :edit, status: :unprocessable_entity } - end + if @organization_profile.update(organization_profile_params) + redirect_to dashboard_index_path, notice: "Your profile has been updated!" + else + render :edit, status: :unprocessable_entity end end @@ -23,7 +20,8 @@ def organization_profile_params params.require(:organization_profile).permit( :phone_number, :email, - location_attributes: %i[city_town country province_state id] + :about_us, + location_attributes: %i[city_town country province_state] ) end end diff --git a/app/models/organization_profile.rb b/app/models/organization_profile.rb index 56c602604..2acc92eab 100644 --- a/app/models/organization_profile.rb +++ b/app/models/organization_profile.rb @@ -24,13 +24,15 @@ class OrganizationProfile < ApplicationRecord belongs_to :location belongs_to :organization, inverse_of: :profile - accepts_nested_attributes_for :location validates_associated :location before_save :normalize_phone validates :phone_number, phone: {possible: true, allow_blank: true} + validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + + delegate :name, to: :organization private diff --git a/app/views/organizations/organization_profiles/_form.html.erb b/app/views/organizations/organization_profiles/_form.html.erb index acf226982..10a87e07b 100644 --- a/app/views/organizations/organization_profiles/_form.html.erb +++ b/app/views/organizations/organization_profiles/_form.html.erb @@ -4,57 +4,96 @@ <%= t '.please_fix_the_errors' %> <% end %> +
PNG or JPG, size must be between 10kb and 1Mb
+Edit your organization's information.
+ <%= t('.manage_your_own_account_settings') %> +