docbrown/app/views/users/_profile.html.erb
Molly Struve e87dead7ad
Use new UserSetting and UserNotificationSettings and Ignore Related User Table Fields (#14121)
* schema file undelete description

* feat: v1 of the script

* Flesh out remaining enums under their categories

* complete UsersSettings data update script

* complete DUS for relevant attributes in users and profiles tables

* complete DUS for users_notification_settings

* alphabetize user_settings sql file

* safeguard against null values for "null: false" settings

* Set up actual UsersSettings DUS and specs files

* fix broken DUS script

* complete specs for UsersSetting DUS

* Address QA of specs

* complete specs for users_notification_settings DUS

* fix the typos (thanks Julianna!)

* begin implementation

* still building

* add missing attribute "email_membership_newsletter"

* complete sync code (except race condition for user profile)

* complete implementation, remains tests

* Address PR review and fix Travis fails

* remove superfluous Profile.new

* fix travis fails

* feat: update the users_notification_setting attributes from the user model

* feat: use the config fonts enums to display the fonts

* feat: loop through the keys

* fix profile = nil blowing up; add specs for notification_setting model

* remove unneeded spec

* remove feed validation until after sync code removed; fixes feed_import spec failures

* remove spec associated with feed_url validation in user_setting model

* fix failing spec 😅

* add TODO

* feat: set the user settings in the user controller  and use it in the customization form

* feat: move some update logic to the users settings controller thats being used from customization

* feat: show the updated values form the users_settingd and not the user instance

* Generalize redirect back to current tab

* still trying to reflect changed theme upon refresh

* customizations take effect on refresh

* remove 'with_feed' scope from user model

Co-authored-by: Jamie Gaskins <jamie@forem.com>

* start with takeover for fields previously in profiles table

* Takeover code for `publishing_from_rss` section in Settings (#13914)

* implement takeover code part 1

* implement takeover code

* fix feed fetch

* need rhymes help

* complete implementation; specs pending

* fix STUPID omission that caused so many headaches 😫

* implement profile fields pointing to users_settings 🎉

* run migrations

* implement inbox type & guidelines takeover code; specs pending (#13911)

* Point changes in notification settings to `users_notification_settings` table (#13910)

* implement takeover code; remains specs

* address PR feedback; remove related sync code

* address PR review feedback

* need help with routing and specs

* address pr review

* addressing pr review

* Treat implementation edge cases and omissions 😅

* fix uncommented comment

* fixing implementation cases

* address more PR review feedback

* fixing notifications use-cases

* refactor settings controller

* more pr review changes

* solving bugs

* fix broken onboarding

* handle eperience_level calls

* more fixes

* remove unneeded mappings

* add To-dos for quety updates

* remove done TODO

* purge done TODOs

* update notification_settings-related queries

* start fixing specs

* fixing specs

* fix notification and lrg_forem specs

* fixing broken specs

* still fixing

* fix line dif and remove reloads from user.rb

* run specs

* silence bullet and other fixes

* remove setting migration scripts and specs, fix more settings for specs

* handle missing user for article builder and fix notification specs

* fix some final controller specs and re-add incorrectly removed specs

* remove deprecated data update scripts and related workers, put travis back

* refactor admin tags mods controller, write/move specs for users notifications settings controller

* schema cleanup and other small refactors for consistency

* set field we can invalidate in spec via active record instead of at the db level

* remove I think an uneccessary hook call from subscribe_to_mailchimp_newsletter

* use bnefore_create to setup settings, please dont blow up the test suite

* mailchimp bot fix

* remove decorator in favor of single model method

Co-authored-by: Arit Amana <msarit@gmail.com>
Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
Co-authored-by: Arit Amana <32520970+msarit@users.noreply.github.com>
Co-authored-by: Jamie Gaskins <jamie@forem.com>
2021-07-08 09:31:34 -05:00

183 lines
8.4 KiB
Text

<%= javascript_packs_with_chunks_tag "colorPreview", "validateFileInputs", "stickySaveFooter", defer: true %>
<%= render "users/additional_authentication" %>
<%= form_with(url: profile_path(@user.profile_id), method: "put", html: { class: "sticky-footer-form" }) do |f| %>
<div class="crayons-card crayons-card--content-rows">
<h2>User</h2>
<div class="crayons-field">
<%= f.label :name, for: "user[name]", class: "crayons-field__label" %>
<%= f.text_field "user[name]", maxlength: 30, class: "crayons-textfield", placeholder: "John Doe", value: @user.name %>
</div>
<div class="crayons-field">
<%= f.label :email, for: "user[email]", class: "crayons-field__label" %>
<%= f.text_field "user[email]", class: "crayons-textfield", placeholder: "john.doe@example.com", value: @user.email %>
</div>
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box "users_setting[display_email_on_profile]", class: "crayons-checkbox", checked: @user.setting.display_email_on_profile %>
<%= f.label :display_email_on_profile, for: "users_setting[display_email_on_profile]", class: "crayons-field__label" %>
</div>
<div class="crayons-field">
<%= f.label :username, for: "user[username]", class: "crayons-field__label" %>
<%= f.text_field "user[username]", maxlength: 30, class: "crayons-textfield", placeholder: "johndoe", value: @user.username %>
</div>
<div class="crayons-field">
<%= f.label :profile_image, for: "user[profile_image]", class: "crayons-field__label" %>
<div class="flex items-center">
<% if @user.profile_image_url.present? %>
<span class="crayons-avatar crayons-avatar--xl mr-2">
<img alt="<%= @user.username %> profile image" src="<%= Images::Profile.call(@user.profile_image_url, length: 50) %>" class="crayons-avatar__image" loading="lazy" />
</span>
<% end %>
<%= f.file_field "user[profile_image]", accept: "image/*", class: "crayons-card crayons-card--secondary p-3 flex items-center flex-1 w-100" %>
</div>
</div>
</div>
<% profile = @user.profile %>
<div class="crayons-card crayons-card--content-rows">
<h2>Basic</h2>
<div class="crayons-field">
<label class="crayons-field__label" for="profile[website_url]">
Website URL
</label>
<%= f.text_field "profile[website_url]",
value: profile.website_url,
placeholder: "https://yoursite.com",
class: "crayons-textfield js-color-field" %>
</div>
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box "profile[display_email_on_profile]",
checked: profile.display_email_on_profile,
class: "crayons-checkbox" %>
<label class="crayons-field__label" for="profile[display_email_on_profile]">
Display email on profile
</label>
</div>
<div class="crayons-field">
<label class="crayons-field__label" for="profile[location]">
Location
</label>
<%= f.text_field "profile[location]",
value: profile.location,
placeholder: "Halifax, Nova Scotia",
class: "crayons-textfield js-color-field" %>
</div>
<div class="crayons-field">
<label class="crayons-field__label" for="profile[summary]">
Bio
</label>
<%= f.text_field "profile[summary]",
value: profile.summary,
placeholder: "A short bio...",
class: "crayons-textfield js-color-field" %>
</div>
</div>
<% ProfileFieldGroup.non_empty_groups.each do |group| %>
<% next if group.name == "Basic" # TODO: @citizen428 Remove this after user settings work (email field) %>
<% next if group.name == "Links" # TODO: [@jacobherrington] Remove this when we drop social links %>
<% next if group.name == "Branding" # TODO: [@msarit @jacobherrington] May be further refactored later as part of Profiles work %>
<div class="crayons-card crayons-card--content-rows">
<h2><%= group.name %></h2>
<% if group.description.present? %>
<div class="color-base-60"><%= group.description %></div>
<% end %>
<% group.profile_fields.each do |field| %>
<% next if field.attribute_name == "display_email_on_profile" %>
<div class="crayons-field <%= "crayons-field--checkbox" if field.input_type == "check_box" %>">
<% if field["input_type"] == "check_box" %>
<%= f.public_send(field["input_type"],
"profile[#{field.attribute_name}]",
checked: profile.public_send(field.attribute_name),
class: "crayons-checkbox") %>
<label class="crayons-field__label" for="<%= "profile[#{field.attribute_name}]" %>">
<%= field.label %>
</label>
<% elsif field["input_type"] == "color_field" %>
<label class="crayons-field__label" for="<%= "profile[#{field.attribute_name}]" %>">
<%= field.label %>
</label>
<div class="flex items-center w-100 m:w-50">
<%= f.public_send("text_field", "profile[#{field.attribute_name}]",
value: profile.public_send(field.attribute_name),
placeholder: field["placeholder_text"],
class: "crayons-textfield js-color-field") %>
<%= f.public_send(field["input_type"],
"profile[#{field.attribute_name}]",
value: profile.public_send(field.attribute_name),
class: "crayons-color-selector js-color-field ml-2") %>
</div>
<% else %>
<label class="crayons-field__label" for="<%= "profile[#{field.attribute_name}]" %>">
<%= field.label %>
</label>
<%= f.public_send(field["input_type"],
"profile[#{field.attribute_name}]",
value: profile.public_send(field.attribute_name),
placeholder: field["placeholder_text"],
class: "crayons-textfield") %>
<% end %>
<% if field.description.present? %>
<p class="crayons-field__description"><%= field.description %></p>
<% end %>
</div>
<% end %>
</div>
<% end %>
<% users_setting = @user.setting %>
<div class="crayons-card crayons-card--content-rows">
<h2>Branding</h2>
<div class="crayons-field ">
<label class="crayons-field__label" for="users_setting[brand_color1]">
Brand color 1
</label>
<div class="flex items-center w-100 m:w-50">
<%= f.public_send("text_field", "users_setting[brand_color1]",
value: users_setting.public_send("brand_color1"),
placeholder: "#000000",
class: "crayons-textfield js-color-field") %>
<%= f.public_send("color_field",
"users_setting[brand_color1]",
value: users_setting.public_send("brand_color1"),
class: "crayons-color-selector js-color-field ml-2") %>
</div>
<p class="crayons-field__description">Used for backgrounds, borders etc.</p>
</div>
<div class="crayons-field ">
<label class="crayons-field__label" for="users_setting[brand_color1]">
Brand color 2
</label>
<div class="flex items-center w-100 m:w-50">
<%= f.public_send("text_field", "users_setting[brand_color2]",
value: users_setting.public_send("brand_color2"),
placeholder: "#000000",
class: "crayons-textfield js-color-field") %>
<%= f.public_send("color_field",
"users_setting[brand_color2]",
value: users_setting.public_send("brand_color2"),
class: "crayons-color-selector js-color-field ml-2") %>
</div>
<p class="crayons-field__description">Used for texts (usually put on Brand color 1).</p>
</div>
</div>
<div class="save-footer crayons-card crayons-card--content-rows">
<button type="submit" class="crayons-btn">Save Profile Information</button>
</div>
<% end %>