[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> <div>
{i18n('ERRORS_FOUND')} {i18n('ERRORS_FOUND')}
<ul> <ul>
{result.data.map((error) => <li>{error}</li>)} {result.data.map((error, index) => <li key={`csv-file__key-${index}`} >{error}</li>)}
</ul> </ul>
</div> </div>
) : null ) : null

View File

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