Fix account page on fresh install #684

Merged
rmarescu merged 1 commits from fix-profile-page-fresh-install into main 2024-04-27 20:59:02 +08:00
rmarescu commented 2024-04-27 05:41:38 +08:00 (Migrated from github.com)

What

  • Fix /settings/profile on a fresh install
  • Consolidate logic around displaying name on the UI
  • Consolidate logic around user initial on the UI

Why

I did a fresh install on Render (it worked great!) and I got an error when I tried accessing the Account page.

CleanShot 2024-04-26 at 14 26 31@2x

### What - [x] Fix `/settings/profile` on a fresh install - [x] Consolidate logic around displaying name on the UI - [x] Consolidate logic around user initial on the UI ### Why I did a fresh install on Render (it worked great!) and I got an error when I tried accessing the Account page. ![CleanShot 2024-04-26 at 14 26 31@2x](https://github.com/maybe-finance/maybe/assets/399663/997f59f7-a77c-450b-be52-24a1c2df57b2)
rmarescu (Migrated from github.com) reviewed 2024-04-27 05:53:51 +08:00
rmarescu (Migrated from github.com) left a comment

Here is an attempt to resolve an issue I encountered after doing a fresh installation.

Here is an attempt to resolve an issue I encountered after doing a fresh installation.
@@ -7,12 +7,22 @@ class User < ApplicationRecord
validates :email, presence: true, uniqueness: true
normalizes :email, with: ->(email) { email.strip.downcase }
normalizes :first_name, :last_name, with: ->(value) { value.strip.presence }
rmarescu (Migrated from github.com) commented 2024-04-27 05:46:16 +08:00

By default, the columns have a nil value. When the form is saved on the UI (without values), then empty strings are saved in the database.
Generally, I think it's best to normalize String values to have sanitized data (i.e. nils instead of empty strings).

By default, the columns have a `nil` value. When the form is saved on the UI (without values), then empty strings are saved in the database. Generally, I think it's best to normalize `String` values to have sanitized data (i.e. `nil`s instead of empty strings).
@@ -14,2 +16,4 @@
end
def display_name
[ first_name, last_name ].compact.join(" ").presence || email
rmarescu (Migrated from github.com) commented 2024-04-27 05:47:11 +08:00

This falls back to email because is also used on the list of members, and it looks odd without some sort of identifier. I've added a screenshot below for reference.

This falls back to email because is also used on the list of members, and it looks odd without some sort of identifier. I've added a screenshot below for reference.
@@ -15,2 +15,4 @@
<span class="text-gray-500 text-sm"><%= Current.user.email %></span>
<% end %>
</div>
</div>
rmarescu (Migrated from github.com) commented 2024-04-27 05:50:53 +08:00

Until at least one name is provided, there is no point rendering the email twice.

Until at least one name is provided, there is no point rendering the email twice.
@@ -40,3 +40,3 @@
<div class="flex gap-2 items-center bg-white p-4 border border-alpha-black-25 rounded-lg">
<div class="mr-1 flex justify-center items-center bg-gray-50 w-8 h-8 rounded-full border border-alpha-black-25">
<p class="uppercase text-xs text-gray-500"><%= Current.user.first_name.first %></p>
<p class="uppercase text-xs text-gray-500"><%= Current.user.initial %></p>
rmarescu (Migrated from github.com) commented 2024-04-27 05:51:16 +08:00

This was causing the page crash, when first_name was nil on fresh install.

This was causing the page crash, when `first_name` was `nil` on fresh install.
@@ -43,3 +43,3 @@
</div>
<p class="text-gray-900 font-medium text-sm"><%= Current.user.first_name %> <%= Current.user.last_name %></p>
<p class="text-gray-900 font-medium text-sm"><%= Current.user.display_name %></p>
<div class="rounded-md bg-gray-100 px-1.5 py-0.5">
rmarescu (Migrated from github.com) commented 2024-04-27 05:51:45 +08:00

Before was like this -

CleanShot 2024-04-26 at 14 48 01@2x

Before was like this - ![CleanShot 2024-04-26 at 14 48 01@2x](https://github.com/maybe-finance/maybe/assets/399663/18f0b1a1-a682-4e70-893a-ed14a4ab35d1)
zachgoll (Migrated from github.com) approved these changes 2024-04-27 20:58:34 +08:00
zachgoll (Migrated from github.com) left a comment

This is great, thanks for the fixes and comments on this!

This is great, thanks for the fixes and comments on this!
Sign in to join this conversation.