feat: Add additional attributes in setUser method (#3958)
This commit is contained in:
@@ -52,12 +52,11 @@ class ContactIdentifyAction
|
||||
end
|
||||
|
||||
def update_contact
|
||||
custom_attributes = params[:custom_attributes] ? @contact.custom_attributes.merge(params[:custom_attributes]) : @contact.custom_attributes
|
||||
# blank identifier or email will throw unique index error
|
||||
# TODO: replace reject { |_k, v| v.blank? } with compact_blank when rails is upgraded
|
||||
@contact.update!(params.slice(:name, :email, :identifier, :phone_number).reject do |_k, v|
|
||||
v.blank?
|
||||
end.merge({ custom_attributes: custom_attributes }))
|
||||
end.merge({ custom_attributes: custom_attributes, additional_attributes: additional_attributes }))
|
||||
ContactAvatarJob.perform_later(@contact, params[:avatar_url]) if params[:avatar_url].present?
|
||||
end
|
||||
|
||||
@@ -68,4 +67,16 @@ class ContactIdentifyAction
|
||||
mergee_contact: merge_contact
|
||||
).perform
|
||||
end
|
||||
|
||||
def custom_attributes
|
||||
params[:custom_attributes] ? @contact.custom_attributes.deep_merge(params[:custom_attributes].stringify_keys) : @contact.custom_attributes
|
||||
end
|
||||
|
||||
def additional_attributes
|
||||
if params[:additional_attributes]
|
||||
@contact.additional_attributes.deep_merge(params[:additional_attributes].stringify_keys)
|
||||
else
|
||||
@contact.additional_attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,6 +46,7 @@ class Api::V1::Widget::ContactsController < Api::V1::Widget::BaseController
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:website_token, :identifier, :identifier_hash, :email, :name, :avatar_url, :phone_number, custom_attributes: {})
|
||||
params.permit(:website_token, :identifier, :identifier_hash, :email, :name, :avatar_url, :phone_number, custom_attributes: {},
|
||||
additional_attributes: {})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,17 +24,38 @@ export const actions = {
|
||||
},
|
||||
update: async ({ dispatch }, { identifier, user: userObject }) => {
|
||||
try {
|
||||
const {
|
||||
email,
|
||||
name,
|
||||
avatar_url,
|
||||
identifier_hash,
|
||||
phone_number,
|
||||
company_name,
|
||||
city,
|
||||
country_code,
|
||||
description,
|
||||
custom_attributes,
|
||||
social_profiles,
|
||||
} = userObject;
|
||||
const user = {
|
||||
email: userObject.email,
|
||||
name: userObject.name,
|
||||
avatar_url: userObject.avatar_url,
|
||||
identifier_hash: userObject.identifier_hash,
|
||||
phone_number: userObject.phone_number,
|
||||
email,
|
||||
name,
|
||||
avatar_url,
|
||||
identifier_hash,
|
||||
phone_number,
|
||||
additional_attributes: {
|
||||
company_name,
|
||||
city,
|
||||
description,
|
||||
country_code,
|
||||
social_profiles,
|
||||
},
|
||||
custom_attributes,
|
||||
};
|
||||
await ContactsAPI.update(identifier, user);
|
||||
|
||||
dispatch('get');
|
||||
if (userObject.identifier_hash) {
|
||||
if (identifier_hash) {
|
||||
dispatch('conversation/clearConversations', {}, { root: true });
|
||||
dispatch('conversation/fetchOldConversations', {}, { root: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user