Skip to content

Commit

Permalink
MSCO-22: add users to company directory (#54)
Browse files Browse the repository at this point in the history
* MSCO-22: add users to company directory

* MSCO-22: add option to opt-in to adding users to main directory

* add options object to formatUserData
  • Loading branch information
mavriciomart authored Aug 12, 2022
1 parent af7d25f commit c80c36f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 4 deletions.
139 changes: 135 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,22 +449,25 @@ define(function(require) {

if (resultCheck.isValid) {
var hasCustomizations = template.find('.has-customizations').prop('checked');
var addToMainDirectory = template.find('.add-to-main-directory').prop('checked');

if (hasCustomizations) {
self.renderCustomizations(args, formattedData.data, function(customizations) {
self.startProcess(_.merge({}, _.pick(args, ['container', 'parent']), {
data: {
reviewData: formattedData.data,
customizations: customizations,
isDevices: isDevices
isDevices: isDevices,
addToMainDirectory: addToMainDirectory
}
}));
});
} else {
self.startProcess(_.merge({}, _.pick(args, ['container', 'parent']), {
data: {
reviewData: formattedData.data,
isDevices: isDevices
isDevices: isDevices,
addToMainDirectory: addToMainDirectory
}
}));
}
Expand Down Expand Up @@ -531,6 +534,7 @@ define(function(require) {
data = args.data,
reviewData = data.reviewData,
isDevices = data.isDevices,
addToMainDirectory = data.addToMainDirectory,
template = $(self.getTemplate({
name: 'progress',
data: {
Expand All @@ -545,7 +549,12 @@ define(function(require) {
.append(template);

_.each(reviewData, function(userData) {
var newData = self.formatUserData(userData, data.customizations ? data.customizations : {});
var formatOptions = {
customizations: data.customizations ? data.customizations : {},
addToMainDirectory: addToMainDirectory
};

var newData = self.formatUserData(userData, formatOptions);

if (isDevices) { // users and devices
listUserCreate.push(function(callback) {
Expand Down Expand Up @@ -808,6 +817,23 @@ define(function(require) {
waterfallCallback(true, parsedError);
}
);
},
function(_data, waterfallCallback) {
if (!data.addToMainDirectory) {
waterfallCallback(null, _data);
} else {
self.addUserToMainDirectory(
resultData.user,
resultData.callflow.id,
function() {
waterfallCallback(null, _data);
},
function(parsedError) {
resultData.err = parsedError;
waterfallCallback(true, parsedError);
}
);
}
}
], function(err, result) {
if (err) {
Expand Down Expand Up @@ -868,6 +894,23 @@ define(function(require) {
waterfallCallback(true, parsedError);
}
);
},
function(_data, waterfallCallback) {
if (!data.addToMainDirectory) {
waterfallCallback(null, _data);
} else {
self.addUserToMainDirectory(
resultData.user,
resultData.callflow.id,
function() {
waterfallCallback(null, _data);
},
function(parsedError) {
resultData.err = parsedError;
waterfallCallback(true, parsedError);
}
);
}
}
], function(err, result) {
if (err) {
Expand Down Expand Up @@ -1060,12 +1103,14 @@ define(function(require) {
return formattedData;
},

formatUserData: function(data, customizations) {
formatUserData: function(data, options) {
var self = this,
customizations = options.customizations,
fullName = data.first_name + ' ' + data.last_name,
callerIdName = fullName.substring(0, 15),
formattedData = {
rawData: data,
addToMainDirectory: options.addToMainDirectory,
user: $.extend(true, {}, customizations.user, {
first_name: data.first_name,
last_name: data.last_name,
Expand Down Expand Up @@ -1230,6 +1275,92 @@ define(function(require) {
err && err(parsedError);
}
});
},

updateUser: function(userData, callback) {
var self = this;

self.callApi({
resource: 'user.update',
data: {
accountId: self.accountId,
userId: userData.id,
data: userData
},
success: function(userData) {
callback && callback(userData);
}
});
},

listAccountDirectories: function(callback) {
var self = this;

self.callApi({
resource: 'directory.list',
data: {
accountId: self.accountId,
filters: {
paginate: 'false'
}
},
success: function(data) {
callback && callback(data.data);
}
});
},

usersCreateMainDirectory: function(callback) {
var self = this,
dataDirectory = {
confirm_match: false,
max_dtmf: 0,
min_dtmf: 3,
name: 'SmartPBX Directory',
sort_by: 'last_name'
};

self.callApi({
resource: 'directory.create',
data: {
accountId: self.accountId,
data: dataDirectory
},
success: function(data) {
callback && callback(data.data);
}
});
},

getMainDirectory: function(callback) {
var self = this;

self.listAccountDirectories(function(listDirectories) {
var mainDirectory = _.find(listDirectories, { name: 'SmartPBX Directory' });

if (mainDirectory) {
callback(mainDirectory);
} else {
self.usersCreateMainDirectory(function(data) {
callback(data);
});
}
});
},

addUserToMainDirectory: function(user, callflowId, callback, callbackErr) {
var self = this;

self.getMainDirectory(function(directory) {
user.directories = user.directories || {};
user.directories[directory.id] = callflowId;

self.updateUser(user, function(data) {
callback && callback(data);
}, function(error) {
callbackErr && callbackErr(error);
});
});
}
};

Expand Down
1 change: 1 addition & 0 deletions i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"others": "OTHERS"
},
"hasCustomizations": "Do you want to add JSON configs?",
"addToMainDirectory": "Do you want to add users to Company Directory?",
"tooltips": {
"proceed": "Please map all required fields before proceeding"
},
Expand Down
3 changes: 3 additions & 0 deletions views/reviewUsers.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
</div>

<div class="actions">
{{#monsterCheckbox i18n.csvOnboarding.review.addToMainDirectory}}
<input type="checkbox" class="add-to-main-directory"></input>
{{/monsterCheckbox}}
{{#monsterCheckbox i18n.csvOnboarding.review.hasCustomizations}}
<input type="checkbox" class="has-customizations"></input>
{{/monsterCheckbox}}
Expand Down

0 comments on commit c80c36f

Please sign in to comment.