Skip to content

Commit 24509ec

Browse files
committed
Fix update avatar logic
1 parent c01049a commit 24509ec

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

templates/v3/user_profile_edit.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@
105105
</span>
106106
{# Invisible input, toggles the edit box appearing #}
107107
<input type="checkbox" id="user-profile__avatar-row-checkbox" name="avatar-row-checkbox" class="badge-button__radio" />
108-
{# File input, shown in the empty state #}
109-
{% include 'v3/includes/_field_file.html' with name=user_profile_form.avatar.name extra_class='user-profile__empty-avatar-input' accept='image/png,image/jpeg' only %}
108+
{% include 'v3/includes/_field_file.html' with id="field-avatar-modal-new" name=user_profile_form.avatar.name extra_class='user-profile__empty-avatar-input' accept='image/png,image/jpeg' only %}
110109
<div class="user-profile__default-space-col user-profile__default-avatar-buttons">
111110
{# Delete and replace buttons, shown in filled state #}
112111
<label id="user-profile__avatar-replace-button" for="user-profile__avatar-row-checkbox" class="btn btn-secondary">Replace Avatar<span class="btn-icon" aria-hidden>{% include 'includes/icon.html' with icon_name='pixel-pencil' icon_size=16 icon_viewbox='0 0 16 16' only %}</span></label>
@@ -420,7 +419,8 @@
420419
const SLACK_PROFILE_URL_PREFIX = '{{ SLACK_PROFILE_URL_PREFIX|escapejs }}';
421420
const SLACK_MEMBER_ID_PATTERN = /^[A-Z0-9]{9,11}$/i;
422421

423-
const avatarInput = document.querySelector("input[name='{{user_profile_form.avatar.name}}']");
422+
const avatarInput = document.querySelector("input[id='field-avatar-modal']")
423+
const avatarInputNew = document.querySelector("input[id='field-avatar-modal-new']")
424424
const avatarDelete = document.querySelector('#user-profile__avatar-delete-checkbox')
425425
const avatarComponent = document.querySelector('#user-profile-editable-avatar')
426426
const avatarImg = avatarComponent.querySelector('img')
@@ -522,14 +522,15 @@
522522
if(avatarDelete.checked) {
523523
avatar = null;
524524
}
525+
525526
if(avatarInput.files.length > 0) formData.append('profile_image', avatarInput.files[0])
527+
else if(avatarInputNew.files.length > 0) formData.append('profile_image', avatarInputNew.files[0])
526528
formData.append('delete_profile_image', avatarDelete.checked)
527529

528530
this.saving = true;
529531
this.saveStatus = '';
530532
this.saveError = '';
531533

532-
533534
try {
534535
const res = await fetch('/api/v1/users/me/', {
535536
method: 'PATCH',

0 commit comments

Comments
 (0)