Commit 1502dda7 authored by Nikolai R Kristiansen's avatar Nikolai R Kristiansen

馃悰 Fix some bugs moving to lodash

parent 9dd713a9
import * as $ from 'jquery';
import moment from 'moment';
import nunjucks from 'nunjucks';
import _ from 'lodash';
import debounce from 'lodash.debounce';
import sortBy from 'lodash.sortby';
import fromPairs from 'lodash.frompairs';
//
import 'bootstrap-sass/assets/javascripts/bootstrap/tooltip';
import 'bootstrap-sass/assets/javascripts/bootstrap/popover';
......@@ -70,7 +71,7 @@ function formatPhoneNumber(str) {
}
function sortSearchResults(results) {
return _.sortBy(results, (x) => {
return sortBy(results, (x) => {
if (x.last_membership) {
if (x.last_membership.end_date) {
return 0 - moment(x.last_membership.end_date).unix();
......@@ -167,7 +168,7 @@ function setSelectedUser(user, updateSearchResult) {
const staleSearchResult = _dom.results.find('.search-result').removeClass('selected');
staleSearchResult.find('input').prop('checked', false);
/* User is still in search result, mark selected */
if (user && _.findWhere(users, { id: user.id })) {
if (user && users.find(({ id }) => id === user.id)) {
const searchResult = _dom.results.find(`[data-user-id="${user.id}"]`).toggleClass('selected');
searchResult.find('input').prop('checked', true);
}
......@@ -243,7 +244,7 @@ function resetSearchForm(resetNative) {
}
function cardFormIsValid() {
return _.values(cardForm.fields).every((v) => v);
return Object.values(cardForm.fields).every((v) => v);
}
function updateSubmitButton() {
......@@ -287,8 +288,8 @@ function validateCardNumber(val) {
function getFormData(formElement) {
let formData = formElement.serializeArray();
formData = _.object(
_.map(formData, (x) => {
formData = fromPairs(
formData.map((x) => {
return [x.name, x.value || null];
})
);
......@@ -378,7 +379,7 @@ $(document).ready(function() {
membershipTrialCheckBox: $('#id_membership_trial')
};
const lazyCheckPhoneNumber = _.debounce(checkPhoneNumber, 250);
const lazyCheckPhoneNumber = debounce(checkPhoneNumber, 250);
_dom.phoneNumberField.on('input', (e) => {
const val = e.target.value.trim();
const validationMsg = validatePhoneNumber(val);
......@@ -482,7 +483,7 @@ $(document).ready(function() {
$('.search-result').removeClass('selected');
label.toggleClass('selected');
setSelectedUser(_.findWhere(users, { id: userId }));
setSelectedUser(users.find(({ id }) => id === userId));
/* Update phone number field */
if (number === '-') {
......
......@@ -6261,7 +6261,23 @@
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"dev": true
},
"lodash.debounce": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
"integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168="
},
"lodash.frompairs": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/lodash.frompairs/-/lodash.frompairs-4.0.1.tgz",
"integrity": "sha1-vE5SB/onV8E25XNhTpZkUGsrG9I="
},
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
},
"loglevel": {
"version": "1.6.6",
......
......@@ -12,7 +12,9 @@
"bootstrap-sass": "^3.4.1",
"jquery": "^3.4.1",
"list.js": "^1.5.0",
"lodash": "^4.17.15",
"lodash.debounce": "^4.0.8",
"lodash.frompairs": "^4.0.1",
"lodash.sortby": "^4.7.0",
"moment": "^2.24.0",
"nunjucks": "^3.2.0"
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment