diff --git a/ghost/admin/app/components/modal-import-members.js b/ghost/admin/app/components/modal-import-members.js index 7ff509968e..55c6db0f44 100644 --- a/ghost/admin/app/components/modal-import-members.js +++ b/ghost/admin/app/components/modal-import-members.js @@ -15,24 +15,13 @@ import {inject as service} from '@ember/service'; import {tracked} from '@glimmer/tracking'; class MembersFieldMapping { - _supportedImportFields = [ - 'email', - 'name', - 'note', - 'subscribed_to_emails', - 'stripe_customer_id', - 'complimentary_plan', - 'labels', - 'created_at' - ]; - @tracked _mapping = {}; constructor(mapping) { - // NOTE: there are only 2 distinguishable fields that could be automatically matched, which is the reason why code is just simple assignments if (mapping) { - this.set(mapping.email, 'email'); - this.set(mapping.stripe_customer_id, 'stripe_customer_id'); + for (const [key, value] of Object.entries(mapping)) { + this.set(value, key); + } } } diff --git a/ghost/admin/app/services/member-import-validator.js b/ghost/admin/app/services/member-import-validator.js index 14b90d9ec6..987b6b1f83 100644 --- a/ghost/admin/app/services/member-import-validator.js +++ b/ghost/admin/app/services/member-import-validator.js @@ -126,7 +126,7 @@ export default Service.extend({ }, /** - * Detects validated data types: + * Detects supported data types and auto-detects following two needed for validation: * 1. email * 2. stripe_customer_id * @@ -135,6 +135,22 @@ export default Service.extend({ * @param {Array} data sampled data containing non empty values */ _detectDataTypes(data) { + const supportedTypes = [ + 'email', + 'name', + 'note', + 'subscribed_to_emails', + 'stripe_customer_id', + 'complimentary_plan', + 'labels', + 'created_at' + ]; + + const autoDetectedTypes = [ + 'email', + 'stripe_customer_id' + ]; + let mapping = {}; let i = 0; // loopping through all sampled data until needed data types are detected @@ -154,6 +170,10 @@ export default Service.extend({ mapping.stripe_customer_id = key; continue; } + + if (!mapping[key] && supportedTypes.includes(key) && !(autoDetectedTypes.includes(key))) { + mapping[key] = key; + } } i += 1;