-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from freerange/inline-my-account-forms
Inline /account forms
- Loading branch information
Showing
37 changed files
with
349 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class ErrorBoxComponent < ViewComponent::Base | ||
def initialize(title:) | ||
@title = title | ||
|
||
super | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
app/components/error_box_component/error_box_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="w-full border border-red-600 p-4 mb-3"> | ||
<h2 class="font-bold mb-3"> | ||
<%= @title %> | ||
</h2> | ||
|
||
<%= content %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class ModelErrorComponent < ViewComponent::Base | ||
def initialize(model:) | ||
@model = model | ||
|
||
super | ||
end | ||
|
||
def render? | ||
return false unless @model | ||
|
||
@model.errors.any? | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/components/model_error_component/model_error_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= render(ErrorBoxComponent.new( | ||
title: "#{pluralize(@model.errors.count, "error")} prohibited this #{@model.class.name.downcase} from being saved" | ||
)) do %> | ||
<ul> | ||
<% @model.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class SidebarSectionComponent < ViewComponent::Base | ||
def initialize(title:) | ||
@title = title | ||
|
||
super | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
app/components/sidebar_section_component/sidebar_section_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<section class="flex flex-col md:flex-row py-6"> | ||
<div class="md:basis-1/4 mb-3 md:mb-0"> | ||
<h2 class="text-lg font-bold"><%= @title %></h2> | ||
</div> | ||
<div class="md:basis-3/4"> | ||
<%= content %> | ||
</div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class UsersController < ApplicationController | ||
before_action :set_user | ||
|
||
def show | ||
authorize User | ||
authorize @user | ||
end | ||
|
||
private | ||
|
||
def set_user | ||
@user = Current.user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,64 @@ | ||
<%= render('shared/page_header', text: 'My account') %> | ||
|
||
<ul> | ||
<li><%= text_link_to "Change password", edit_password_path %></li> | ||
<li><%= text_link_to "Change email address", edit_identity_email_path %></li> | ||
<% if Current.user.payout_detail %> | ||
<li><%= text_link_to "Edit payout details", edit_payout_detail_path %></li> | ||
<% else %> | ||
<li><%= text_link_to "Add payout details", new_payout_detail_path %></li> | ||
<div class="flex flex-col divide-y divide-slate-300"> | ||
<h1 class="text-2xl font-bold mb-1">My account</h1> | ||
|
||
<%= render(SidebarSectionComponent.new(title: 'Password')) do %> | ||
<%= form_with(url: password_path, method: :patch, builder: TailwindFormBuilder) do |form| %> | ||
<% if flash[:incorrect_password] %> | ||
<%= render ErrorBoxComponent.new(title: 'Incorrect password').with_content(flash[:incorrect_password]) %> | ||
<% end %> | ||
<% if @user.errors.include?(:password) %> | ||
<%= render ModelErrorComponent.new(model: @user) %> | ||
<% end %> | ||
<%= form.password_field :current_password, required: true, autofocus: true, autocomplete: "current-password", class: "w-full mb-3" %> | ||
<%= form.password_field :password, label: { text: "New password"}, required: true, autocomplete: "new-password", class: "w-full mb-3" %> | ||
<%= form.password_field :password_confirmation, label: { text: "Confirm new password"}, required: true, autocomplete: "new-password", class: "w-full mb-3" %> | ||
<div class="flex flex-row justify-end"> | ||
<%= form.submit "Save changes", class: "mt-3" %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<%= render(SidebarSectionComponent.new(title: 'Email address')) do %> | ||
<% unless Current.user.verified? %> | ||
<div class="mb-3 border border-slate-300 p-4"> | ||
<p>We sent a verification email to the address below. Check that email and follow those instructions to confirm it's your email address.</p> | ||
<p><%= button_to "Re-send verification email", identity_email_verification_path, class: 'py-3 px-5 bg-amber-600 hover:bg-amber-500 text-white font-medium cursor-pointer my-3' %></p> | ||
</div> | ||
<% end %> | ||
<%= form_with(url: identity_email_path, method: :patch, builder: TailwindFormBuilder) do |form| %> | ||
<% if flash[:emails_update_password_incorrect] %> | ||
<%= render ErrorBoxComponent.new(title: 'Incorrect password').with_content(flash[:emails_update_password_incorrect]) %> | ||
<% end %> | ||
<% if @user.errors.include?(:email) %> | ||
<%= render ModelErrorComponent.new(model: @user) %> | ||
<% end %> | ||
<%= form.email_field :email, label: { text: "New email" }, required: true, autofocus: true, class: 'w-full mb-3' %> | ||
<%= form.password_field :current_password, required: true, autocomplete: "current-password", class: 'w-full mb-3' %> | ||
<div class="flex flex-row justify-end"> | ||
<%= form.submit "Save changes", class: 'mt-3' %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<%= render(SidebarSectionComponent.new(title: 'Payout details')) do %> | ||
<p class="text-slate-500 mb-6">We use <a class="underline" href="https://wise.com">Wise</a> to make payouts once a month. Wise will email you at <span class="font-bold"><%= Current.user.email %></span> to ask for your bank details. To make the payment we need the following:</p> | ||
|
||
<% payout_detail = @user.payout_detail || PayoutDetail.new(user: @user) %> | ||
<%= form_with(model: payout_detail, class: "contents", builder: TailwindFormBuilder) do |form| %> | ||
<%= render ModelErrorComponent.new(model: payout_detail) %> | ||
<%= form.text_field :name, placeholder: 'Bartholomew J. Simpson', class: 'w-full' %> | ||
<p class="text-slate-500 italic text-sm mb-3">Your full name as used on your bank account.</p> | ||
|
||
<%= form.select :country, options_for_payout_details_country_select, include_blank: true, label: { text: 'Country / Region' }, class: 'w-full' %> | ||
<p class="text-slate-500 italic text-sm mb-3">We support payouts to the regions/countries <a href="https://wise.com/help/articles/2571942/what-countriesregions-can-i-send-to" class="underline">that Wise supports</a>.</p> | ||
|
||
<div class="flex flex-row justify-end"> | ||
<% if payout_detail.persisted? %> | ||
<%= form.submit "Save changes", class: 'mt-3'%> | ||
<% else %> | ||
<%= form.submit "Add payout details", class: 'mt-3'%> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</ul> |
Oops, something went wrong.