From 3edc0542cc0f5e3a91e53412c8fa208e09ab77e6 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Thu, 5 Dec 2024 04:32:29 +0530 Subject: [PATCH] fix: Fix issue with profile picture not updating (#10532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR resolves the issue with updating the profile picture in the profile settings. **Cause of issue** The issue can be reproduced with the old `ProfileAvatar.vue` component. While the exact reason is unclear, it seems related to cases where the file might be `null`. **Solution** Replaced the old `ProfileAvatar.vue` with `Avatar.vue` and tested it. It works fine. I’ve attached a loom video below. Fixes https://linear.app/chatwoot/issue/CW-3768/profile-picture-bug Co-authored-by: Pranav Co-authored-by: Pranav --- app/controllers/api/v1/profiles_controller.rb | 2 +- .../components-next/avatar/Avatar.vue | 2 +- .../dashboard/settings/profile/Index.vue | 1 - .../settings/profile/UserProfilePicture.vue | 18 ++-- .../dashboard/store/modules/auth.js | 5 +- .../v3/components/Form/ProfileAvatar.vue | 85 ------------------- .../api/v1/profiles/avatar.json.jbuilder | 1 + .../api/v1/profiles_controller_spec.rb | 2 + 8 files changed, 16 insertions(+), 100 deletions(-) delete mode 100644 app/javascript/v3/components/Form/ProfileAvatar.vue create mode 100644 app/views/api/v1/profiles/avatar.json.jbuilder diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index bd3c2673c..ae1a1fe30 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -17,7 +17,7 @@ class Api::V1::ProfilesController < Api::BaseController def avatar @user.avatar.attachment.destroy! if @user.avatar.attached? - head :ok + @user.reload end def auto_offline diff --git a/app/javascript/dashboard/components-next/avatar/Avatar.vue b/app/javascript/dashboard/components-next/avatar/Avatar.vue index ab87e33c9..fb23b3cff 100644 --- a/app/javascript/dashboard/components-next/avatar/Avatar.vue +++ b/app/javascript/dashboard/components-next/avatar/Avatar.vue @@ -132,7 +132,7 @@ const iconStyles = computed(() => ({ })); const initialsStyles = computed(() => ({ - fontSize: `${props.size > 32 ? 16 : props.size / 2}px`, + fontSize: `${Math.min(props.size / 2.5, 24)}px`, })); const invalidateCurrentImage = () => { diff --git a/app/javascript/dashboard/routes/dashboard/settings/profile/Index.vue b/app/javascript/dashboard/routes/dashboard/settings/profile/Index.vue index be1d166ab..a38046580 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/profile/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/profile/Index.vue @@ -190,7 +190,6 @@ export default { diff --git a/app/javascript/dashboard/routes/dashboard/settings/profile/UserProfilePicture.vue b/app/javascript/dashboard/routes/dashboard/settings/profile/UserProfilePicture.vue index 87ac25efa..d86329b76 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/profile/UserProfilePicture.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/profile/UserProfilePicture.vue @@ -1,8 +1,6 @@ - - diff --git a/app/views/api/v1/profiles/avatar.json.jbuilder b/app/views/api/v1/profiles/avatar.json.jbuilder new file mode 100644 index 000000000..0a4b4f9fa --- /dev/null +++ b/app/views/api/v1/profiles/avatar.json.jbuilder @@ -0,0 +1 @@ +json.partial! 'api/v1/models/user', formats: [:json], resource: @user diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 28b4c5ed5..50404ad55 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -180,6 +180,8 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) + json_response = response.parsed_body + expect(json_response['avatar_url']).to be_empty end end end