@@ -30,13 +30,17 @@ public function index(Request $request): View
3030 $ validationPassed = $ request ->session ()->get (self ::SESSION_VALIDATION_PASSED , false );
3131 $ filePath = $ request ->session ()->get (self ::SESSION_FILE_PATH );
3232 $ tempDisk = config ('filesystems.bulk_upload_temp_disk ' , 'local ' );
33- $ importPayload = '' ;
34- if ($ validationPassed && $ filePath ) {
35- $ importPayload = Crypt::encryptString (json_encode ([
36- 'path ' => $ filePath ,
37- 'default_creator_email ' => $ request ->session ()->get (self ::SESSION_DEFAULT_CREATOR ),
38- 'disk ' => $ tempDisk ,
39- ]));
33+ $ importPayload = $ request ->session ()->get ('bulk_upload_import_payload ' );
34+ if ($ importPayload === null || $ importPayload === '' ) {
35+ if ($ validationPassed && $ filePath ) {
36+ $ importPayload = Crypt::encryptString (json_encode ([
37+ 'path ' => $ filePath ,
38+ 'default_creator_email ' => $ request ->session ()->get (self ::SESSION_DEFAULT_CREATOR ),
39+ 'disk ' => $ tempDisk ,
40+ ]));
41+ } else {
42+ $ importPayload = '' ;
43+ }
4044 }
4145
4246 return view ('admin.bulk-upload.index ' , [
@@ -125,8 +129,60 @@ function ($attribute, $value, $fail) {
125129 $ request ->session ()->put (self ::SESSION_VALIDATION_PASSED , true );
126130 $ request ->session ()->forget (self ::SESSION_VALIDATION_MISSING );
127131
128- return redirect ()->route ('admin.bulk-upload.index ' )
129- ->with ('success ' , 'File uploaded. All required columns are present. Click Import to run the import. ' );
132+ $ defaultCreatorEmail = $ validated ['default_creator_email ' ] ?? null ;
133+ $ importPayload = Crypt::encryptString (json_encode ([
134+ 'path ' => $ path ,
135+ 'default_creator_email ' => $ defaultCreatorEmail ,
136+ 'disk ' => $ tempDisk ,
137+ ]));
138+
139+ $ result = new BulkEventImportResult ;
140+ $ import = new GenericEventsImport ($ defaultCreatorEmail , $ result , true );
141+ Excel::import ($ import , $ path , $ tempDisk );
142+
143+ $ rowStatuses = [];
144+ foreach ($ result ->valid as $ row => $ _ ) {
145+ $ rowStatuses [$ row ] = ['row ' => $ row , 'valid ' => true ];
146+ }
147+ foreach ($ result ->failures as $ row => $ reason ) {
148+ $ rowStatuses [$ row ] = ['row ' => $ row , 'valid ' => false , 'message ' => $ reason ];
149+ }
150+ ksort ($ rowStatuses );
151+
152+ return redirect ()->route ('admin.bulk-upload.preview ' )
153+ ->with ('bulk_upload_import_payload ' , $ importPayload )
154+ ->with ('bulk_upload_row_statuses ' , array_values ($ rowStatuses ));
155+ }
156+
157+ /**
158+ * Show validation preview: row-by-row green/red status. Payload from flash or session.
159+ */
160+ public function preview (Request $ request ): View |RedirectResponse
161+ {
162+ $ importPayload = $ request ->session ()->get ('bulk_upload_import_payload ' );
163+ $ rowStatuses = $ request ->session ()->get ('bulk_upload_row_statuses ' , []);
164+
165+ if ($ importPayload === null || $ importPayload === '' ) {
166+ $ filePath = $ request ->session ()->get (self ::SESSION_FILE_PATH );
167+ $ tempDisk = config ('filesystems.bulk_upload_temp_disk ' , 'local ' );
168+ if ($ filePath ) {
169+ $ importPayload = Crypt::encryptString (json_encode ([
170+ 'path ' => $ filePath ,
171+ 'default_creator_email ' => $ request ->session ()->get (self ::SESSION_DEFAULT_CREATOR ),
172+ 'disk ' => $ tempDisk ,
173+ ]));
174+ }
175+ }
176+
177+ if ($ importPayload === null || $ importPayload === '' ) {
178+ return redirect ()->route ('admin.bulk-upload.index ' )
179+ ->withErrors (['import ' => 'No validated file found. Please upload and validate a file first. ' ]);
180+ }
181+
182+ return view ('admin.bulk-upload.preview ' , [
183+ 'import_payload ' => $ importPayload ,
184+ 'row_statuses ' => $ rowStatuses ,
185+ ]);
130186 }
131187
132188 /**
0 commit comments