Skip to content

Commit

Permalink
Merge pull request #769 from webitel/fix/members-uploading
Browse files Browse the repository at this point in the history
fix/member uploading from csv file[WTEL-4865]
  • Loading branch information
dlohvinov authored Sep 11, 2024
2 parents 151e0a0 + ef8ea5e commit 4b4d970
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ const normalizeCSVData = ({ data, mappings }) => {
};
}, {});

// We need to filter empty values and check required fields for validation purposes
const filteredEmptyValues = Object.entries(normalized).reduce(
(filtered, [name, { required, value }]) => {
let filteredValue;
let filteredValue; // Filter empty values in validation purposes
if (Array.isArray(value)) {
// Becouse required field can be combined from many fields in multipple select, so we need to check all values.
// For example, if we have 3 fields and they are empty, we will get empty array.
filteredValue = value.filter((item) => !isEmpty(item));
} else {
filteredValue = value;
}

const isValueEmpty = isEmpty(filteredValue);

// This check is only for required fields
if (required && isValueEmpty) {
throw new Error(`Required field is empty: ${name} on row ${index + 1}`);
}
Expand All @@ -48,7 +51,7 @@ const normalizeCSVData = ({ data, mappings }) => {
? filtered
: {
...filtered,
[name]: filteredValue,
[name]: value, // Need to return value, not filteredValue for proper maping (for example variables in members)
};
},
{},
Expand Down

0 comments on commit 4b4d970

Please sign in to comment.