From f19baaf22a27084b90676d88d5a4b449c443d4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Tue, 4 Apr 2023 12:28:32 +0200 Subject: [PATCH] Add new user settings pages for Chat and Wallet --- app/controllers/settings_controller.rb | 16 +++++++++++- app/views/icons/_message-circle.html.erb | 2 +- app/views/settings/_lightning.html.erb | 27 +++++++++++++++++++++ app/views/settings/_xmpp.html.erb | 18 ++++++++++++++ app/views/shared/_sidenav_settings.html.erb | 12 +++++++-- 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 app/views/settings/_lightning.html.erb create mode 100644 app/views/settings/_xmpp.html.erb diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index b083543..f50235a 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -12,6 +12,13 @@ class SettingsController < ApplicationController end def update + @user = current_user + @user.preferences.merge! user_params[:preferences] + @user.save! + + redirect_to setting_path(@settings_section), flash: { + success: 'Settings saved.' + } end def reset_password @@ -29,10 +36,17 @@ class SettingsController < ApplicationController def set_settings_section @settings_section = params[:section] - allowed_sections = [:profile, :account, :notifications] + allowed_sections = [:profile, :account, :lightning, :xmpp] unless allowed_sections.include?(@settings_section.to_sym) redirect_to setting_path(:profile) end end + + def user_params + params.require(:user).permit(preferences: [ + lightning: [:notify_sats_received], + xmpp: [:exchange_contacts_with_invitees] + ]) + end end diff --git a/app/views/icons/_message-circle.html.erb b/app/views/icons/_message-circle.html.erb index 4b21b32..5ff6406 100644 --- a/app/views/icons/_message-circle.html.erb +++ b/app/views/icons/_message-circle.html.erb @@ -1 +1 @@ - \ No newline at end of file + diff --git a/app/views/settings/_lightning.html.erb b/app/views/settings/_lightning.html.erb new file mode 100644 index 0000000..b7ad6e2 --- /dev/null +++ b/app/views/settings/_lightning.html.erb @@ -0,0 +1,27 @@ +<%= form_for @user, url: setting_path(:lightning), html: { :method => :put } do |f| %> +
+

Notifications

+ +
+
+

+ <%= f.submit 'Save', class: "btn-md btn-blue w-full md:w-auto" %> +

+
+<% end %> diff --git a/app/views/settings/_xmpp.html.erb b/app/views/settings/_xmpp.html.erb new file mode 100644 index 0000000..3ce4e91 --- /dev/null +++ b/app/views/settings/_xmpp.html.erb @@ -0,0 +1,18 @@ +<%= form_for @user, url: setting_path(:xmpp), html: { :method => :put } do |f| %> +
+

Contacts

+ +
+
+

+ <%= f.submit 'Save', class: "btn-md btn-blue w-full md:w-auto" %> +

+
+<% end %> diff --git a/app/views/shared/_sidenav_settings.html.erb b/app/views/shared/_sidenav_settings.html.erb index 625e08c..3d6c17e 100644 --- a/app/views/shared/_sidenav_settings.html.erb +++ b/app/views/shared/_sidenav_settings.html.erb @@ -6,7 +6,15 @@ name: "Account", path: setting_path(:account), icon: "key", active: current_page?(setting_path(:account)) ) %> +<% if Setting.ejabberd_enabled %> <%= render SidenavLinkComponent.new( - name: "Notifications", path: setting_path(:notifications), icon: "bell", - active: current_page?(setting_path(:notifications)) + name: "Chat", path: setting_path(:xmpp), icon: "message-circle", + active: current_page?(setting_path(:xmpp)) ) %> +<% end %> +<% if Setting.lndhub_enabled %> +<%= render SidenavLinkComponent.new( + name: "Wallet", path: setting_path(:lightning), icon: "zap", + active: current_page?(setting_path(:lightning)) +) %> +<% end %>