small fixes for single payout and big chunck for multiple payouts
This commit is contained in:
53
frontend/pweb/lib/services/payments/csv_input.dart
Normal file
53
frontend/pweb/lib/services/payments/csv_input.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
|
||||
class PickedCsvFile {
|
||||
final String name;
|
||||
final String content;
|
||||
|
||||
const PickedCsvFile({required this.name, required this.content});
|
||||
}
|
||||
|
||||
abstract class CsvInputService {
|
||||
Future<PickedCsvFile?> pickCsv();
|
||||
}
|
||||
|
||||
class WebCsvInputService implements CsvInputService {
|
||||
@override
|
||||
Future<PickedCsvFile?> pickCsv() async {
|
||||
final input = html.FileUploadInputElement()
|
||||
..accept = '.csv,text/csv'
|
||||
..multiple = false;
|
||||
|
||||
final completer = Completer<html.File?>();
|
||||
input.onChange.listen((_) {
|
||||
completer.complete(
|
||||
input.files?.isNotEmpty == true ? input.files!.first : null,
|
||||
);
|
||||
});
|
||||
input.click();
|
||||
|
||||
final file = await completer.future;
|
||||
if (file == null) return null;
|
||||
|
||||
final reader = html.FileReader();
|
||||
final readCompleter = Completer<String>();
|
||||
reader.onError.listen((_) {
|
||||
readCompleter.completeError(StateError('Failed to read file'));
|
||||
});
|
||||
reader.onLoadEnd.listen((_) {
|
||||
final result = reader.result;
|
||||
if (result is String) {
|
||||
readCompleter.complete(result);
|
||||
} else {
|
||||
readCompleter.completeError(StateError('Unsupported file payload'));
|
||||
}
|
||||
});
|
||||
reader.readAsText(file);
|
||||
|
||||
final content = await readCompleter.future;
|
||||
return PickedCsvFile(name: file.name, content: content);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'package:pshared/models/payment/upload_history_item.dart';
|
||||
|
||||
|
||||
abstract class UploadHistoryService {
|
||||
Future<List<UploadHistoryItem>> fetchHistory();
|
||||
}
|
||||
|
||||
class MockUploadHistoryService implements UploadHistoryService {
|
||||
@override
|
||||
Future<List<UploadHistoryItem>> fetchHistory() async {
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
return [
|
||||
UploadHistoryItem(name: "cards_payout_single.csv", status: "Valid", time: "5 hours ago"),
|
||||
UploadHistoryItem(name: "rfba_norm.csv", status: "Valid", time: "Yesterday"),
|
||||
UploadHistoryItem(name: "iban (4).csv", status: "Valid", time: "Yesterday"),
|
||||
UploadHistoryItem(name: "rfba_wrong.csv", status: "Error", time: "2 days ago"),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user