Added import tier to members import modal (#17492)

refs https://github.com/TryGhost/Product/issues/3629
This commit is contained in:
Michael Barrett 2023-07-26 09:19:09 +01:00 committed by GitHub
parent dc5cc28036
commit 2fe392c312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';
const FIELD_MAPPINGS = [
@ -14,7 +15,13 @@ const FIELD_MAPPINGS = [
];
export default class extends Component {
@tracked availableFields = FIELD_MAPPINGS;
@service feature;
@tracked availableFields = [
...FIELD_MAPPINGS,
...(
this.feature.importMemberTier ? [{label: 'Tier', value: 'import_tier'}] : []
)
];
get mapTo() {
return this.args.mapTo;

View File

@ -6,6 +6,7 @@ import {isEmpty} from '@ember/utils';
@classic
export default class MemberImportValidatorService extends Service {
@service ajax;
@service feature;
@service membersUtils;
@service ghostPaths;
@ -22,6 +23,7 @@ export default class MemberImportValidatorService extends Service {
* If the data contains 30 rows or fewer, all rows should be validated.
*
* @param {Array} data JSON objects mapped from CSV file
* @param {number} validationSampleSize number of rows to sample
*/
_sampleData(data, validationSampleSize = 30) {
let validatedSet = [{}];
@ -86,13 +88,17 @@ export default class MemberImportValidatorService extends Service {
'created_at'
];
if (this.feature.importMemberTier) {
supportedTypes.push('import_tier');
}
const autoDetectedTypes = [
'email'
];
let mapping = {};
let i = 0;
// loopping through all sampled data until needed data types are detected
// looping through all sampled data until needed data types are detected
while (i <= (data.length - 1)) {
if (mapping.email && mapping.stripe_customer_id) {
break;

View File

@ -55,6 +55,7 @@ const unparse = (members, columns = DEFAULT_COLUMNS.slice()) => {
deleted_at: member.deleted_at,
labels: labels,
tiers: tiers,
import_tier: member.import_tier || null,
error: member.error || null
};
});

View File

@ -21,7 +21,8 @@ const DEFAULT_CSV_HEADER_MAPPING = {
created_at: 'created_at',
complimentary_plan: 'complimentary_plan',
stripe_customer_id: 'stripe_customer_id',
labels: 'labels'
labels: 'labels',
import_tier: 'import_tier'
};
module.exports = class MembersCSVImporter {