Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/member uploading from csv file[WTEL-4865] #769

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading