[DEV-239] Remove unexpected error in upload csv file (#1151)

* Remove unexpected error in upload csv file

* Fix bug when render csv file error list

* csv files without eof line work OK

* [DEV-239] Prettify code
This commit is contained in:
LautaroCesso 2022-02-18 18:33:34 -03:00 committed by GitHub
parent d5552c0f73
commit 54a5a9803d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -333,7 +333,7 @@ class AdminPanelAdvancedSettings extends React.Component {
<div>
{i18n('ERRORS_FOUND')}
<ul>
{result.data.map((error) => <li>{error}</li>)}
{result.data.map((error, index) => <li key={`csv-file__key-${index}`} >{error}</li>)}
</ul>
</div>
) : null

View File

@ -42,17 +42,15 @@ class CSVImportController extends Controller {
$file = fopen($fileUploader->getFullFilePath(),'r');
$errors = [];
while(!feof($file)) {
$userList = fgetcsv($file);
Controller::setDataRequester(function ($key) use ($userList) {
while(($user = fgetcsv($file)) != false) {
Controller::setDataRequester(function ($key) use ($user) {
switch ($key) {
case 'email':
return $userList[0];
return $user[0];
case 'password':
return $userList[1];
return $user[1];
case 'name':
return $userList[2];
return $user[2];
}
return null;
@ -64,7 +62,7 @@ class CSVImportController extends Controller {
$signupController->validate();
$signupController->handler();
} catch (\Exception $exception) {
$errors[] = $exception->getMessage() . ' in email ' . $userList[0];
$errors[] = $exception->getMessage() . ' in email ' . $user[0];
}
}