added navigation and selection of workspaces

This commit is contained in:
2026-06-23 00:22:30 +02:00
parent ae2705363a
commit e89c711d00
11 changed files with 118 additions and 107 deletions

View File

@@ -161,7 +161,10 @@ GoRouter buildRouter() {
return ScaffoldWithNavBar(child: child); return ScaffoldWithNavBar(child: child);
}, },
routes: [ routes: [
GoRoute(path: '/workspace', builder: (context, state) => const WorkspaceScreen()), GoRoute(
path: '/workspace',
builder: (context, state) => const WorkspaceScreen(),
),
GoRoute(path: '/', builder: (context, state) => const HomeScreen()), GoRoute(path: '/', builder: (context, state) => const HomeScreen()),
GoRoute( GoRoute(
path: '/home', path: '/home',
@@ -249,11 +252,10 @@ GoRouter buildRouter() {
}, },
), ),
GoRoute( GoRoute(
path: '/groups/:groupId/batches/:batchId', path: '/groups/batches/:batchId',
builder: (context, state) { builder: (context, state) {
final batchId = state.pathParameters['batchId']!; final batchId = state.pathParameters['batchId']!;
final groupId = state.pathParameters['groupId']!; return BatchDetailScreen(batchId: batchId);
return BatchDetailScreen(batchId: batchId, groupId: groupId);
}, },
), ),
GoRoute( GoRoute(

View File

@@ -122,7 +122,7 @@ class _BatchCreateScreenState extends State<BatchCreateScreen> {
} }
if (!mounted) return; if (!mounted) return;
context.pushReplacement('/groups/${widget.group.id}/batches/${batch.id}'); context.pushReplacement('/groups/batches/${batch.id}');
} else { } else {
AppSnackBar.showError(context, result.error ?? 'Failed to create batch.'); AppSnackBar.showError(context, result.error ?? 'Failed to create batch.');
} }

View File

@@ -15,12 +15,10 @@ import 'package:url_launcher/url_launcher.dart';
class BatchDetailScreen extends StatefulWidget { class BatchDetailScreen extends StatefulWidget {
final String batchId; final String batchId;
final String groupId;
const BatchDetailScreen({ const BatchDetailScreen({
super.key, super.key,
required this.batchId, required this.batchId,
required this.groupId,
}); });
@override @override

View File

@@ -1142,7 +1142,7 @@ class _GroupDetailScreenState extends State<GroupDetailScreen>
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
onTap: inSelectMode onTap: inSelectMode
? () => batchController.toggleBatchSelection(batch.id!) ? () => batchController.toggleBatchSelection(batch.id!)
: () => context.push('/groups/${group.id}/batches/${batch.id}'), : () => context.push('/groups/batches/${batch.id}'),
child: Padding( child: Padding(
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Row( child: Row(

View File

@@ -108,11 +108,11 @@ class HistoryController extends ChangeNotifier {
Future<void> searchTransactions( Future<void> searchTransactions(
String workspaceId, { String workspaceId, {
String? search, String? billName,
String? status, String? status,
String? type, String? type,
}) async { }) async {
model.searchQuery = search ?? ''; model.searchQuery = billName ?? '';
model.statusFilter = status; model.statusFilter = status;
model.typeFilter = type; model.typeFilter = type;
final params = <String, String>{ final params = <String, String>{
@@ -121,13 +121,8 @@ class HistoryController extends ChangeNotifier {
'size': '20', 'size': '20',
'sort': 'createdAt,desc', 'sort': 'createdAt,desc',
}; };
if (search != null && search.isNotEmpty) { if (billName != null && billName.isNotEmpty) {
params['creditAccount'] = search; params['billName'] = billName;
params['creditEmail'] = search;
params['creditPhone'] = search;
params['creditName'] = search;
params['billName'] = search;
params['amount'] = search;
} }
if (status != null && status.isNotEmpty) { if (status != null && status.isNotEmpty) {
params['status'] = status; params['status'] = status;
@@ -149,12 +144,7 @@ class HistoryController extends ChangeNotifier {
'sort': 'createdAt,desc', 'sort': 'createdAt,desc',
}; };
if (model.searchQuery.isNotEmpty) { if (model.searchQuery.isNotEmpty) {
params['creditAccount'] = model.searchQuery;
params['creditEmail'] = model.searchQuery;
params['creditPhone'] = model.searchQuery;
params['creditName'] = model.searchQuery;
params['billName'] = model.searchQuery; params['billName'] = model.searchQuery;
params['amount'] = model.searchQuery;
} }
if (model.statusFilter != null && model.statusFilter!.isNotEmpty) { if (model.statusFilter != null && model.statusFilter!.isNotEmpty) {
params['status'] = model.statusFilter!; params['status'] = model.statusFilter!;

View File

@@ -231,7 +231,7 @@ class _HistoryScreenState extends State<HistoryScreen>
prefs.getString("workspaceId") ?? ''; prefs.getString("workspaceId") ?? '';
controller.searchTransactions( controller.searchTransactions(
workspaceId, workspaceId,
search: _searchController.text.isNotEmpty billName: _searchController.text.isNotEmpty
? _searchController.text ? _searchController.text
: null, : null,
status: controller.model.statusFilter, status: controller.model.statusFilter,
@@ -356,7 +356,7 @@ class _HistoryScreenState extends State<HistoryScreen>
final workspaceId = prefs.getString("workspaceId") ?? ''; final workspaceId = prefs.getString("workspaceId") ?? '';
controller.searchTransactions( controller.searchTransactions(
workspaceId, workspaceId,
search: value.isNotEmpty ? value : null, billName: value.isNotEmpty ? value : null,
status: controller.model.statusFilter, status: controller.model.statusFilter,
type: controller.model.typeFilter, type: controller.model.typeFilter,
); );
@@ -501,7 +501,7 @@ class _HistoryScreenState extends State<HistoryScreen>
final workspaceId = prefs.getString("workspaceId") ?? ''; final workspaceId = prefs.getString("workspaceId") ?? '';
controller.searchTransactions( controller.searchTransactions(
workspaceId, workspaceId,
search: _searchController.text.isNotEmpty billName: _searchController.text.isNotEmpty
? _searchController.text ? _searchController.text
: null, : null,
type: controller.model.typeFilter, type: controller.model.typeFilter,
@@ -514,7 +514,7 @@ class _HistoryScreenState extends State<HistoryScreen>
final workspaceId = prefs.getString("workspaceId") ?? ''; final workspaceId = prefs.getString("workspaceId") ?? '';
controller.searchTransactions( controller.searchTransactions(
workspaceId, workspaceId,
search: _searchController.text.isNotEmpty billName: _searchController.text.isNotEmpty
? _searchController.text ? _searchController.text
: null, : null,
status: controller.model.statusFilter, status: controller.model.statusFilter,

View File

@@ -123,7 +123,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
if (prefs.getString("token") != null) { if (prefs.getString("token") != null) {
setState(() { setState(() {
_isLoggedIn = true; _isLoggedIn = true;
initials = prefs.getString("initials")!; initials = prefs.getString("workspaceInitials")!;
}); });
} }
@@ -347,6 +347,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
end: Alignment.bottomLeft, end: Alignment.bottomLeft,
), ),
), ),
child: InkWell(
child: Center( child: Center(
child: Text( child: Text(
initials, initials,
@@ -357,14 +358,17 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
), ),
), ),
), ),
onTap: () => context.go('/workspace'),
), ),
),
SizedBox(width: 5),
IconButton( IconButton(
icon: Icon( icon: Icon(
Icons.logout_rounded, Icons.logout,
color: isDark ? Colors.white54 : Colors.black54, color: isDark ? Colors.white54 : Colors.black54,
size: 20, size: 20,
), ),
onPressed: _showLogoutDialog, onPressed: () => _showLogoutDialog(),
), ),
], ],
]; ];

View File

@@ -533,6 +533,15 @@ class _ReceiptScreenState extends State<ReceiptScreen>
isLoading: false, isLoading: false,
onPressed: _captureImage, onPressed: _captureImage,
), ),
if (_transaction?.batchId != null)
_modernActionButton(
icon: Icons.batch_prediction_rounded,
label: "View Batch",
color: const Color.fromARGB(255, 60, 99, 10),
isLoading: false,
onPressed: () =>
context.push('/groups/batches/${_transaction?.batchId}'),
),
if (integrationStatus != "SUCCESS" && paymentStatus == "SUCCESS") ...[ if (integrationStatus != "SUCCESS" && paymentStatus == "SUCCESS") ...[
_modernActionButton( _modernActionButton(
icon: Icons.refresh_rounded, icon: Icons.refresh_rounded,

View File

@@ -51,6 +51,8 @@ class TransactionModel {
final String? id; final String? id;
final DateTime? createdAt; final DateTime? createdAt;
final String userId; final String userId;
final String workspaceId;
final String? batchId;
final String trace; final String trace;
final Decimal amount; final Decimal amount;
final Decimal charge; final Decimal charge;
@@ -99,6 +101,8 @@ class TransactionModel {
this.id, this.id,
this.createdAt, this.createdAt,
required this.userId, required this.userId,
required this.workspaceId,
this.batchId,
required this.trace, required this.trace,
required this.amount, required this.amount,
required this.charge, required this.charge,

View File

@@ -14,6 +14,8 @@ TransactionModel _$TransactionModelFromJson(Map<String, dynamic> json) =>
const DateTimeJsonConverter().fromJson, const DateTimeJsonConverter().fromJson,
), ),
userId: json['userId'] as String, userId: json['userId'] as String,
workspaceId: json['workspaceId'] as String,
batchId: json['batchId'] as String?,
trace: json['trace'] as String, trace: json['trace'] as String,
amount: const DecimalJsonConverter().fromJson(json['amount'] as num), amount: const DecimalJsonConverter().fromJson(json['amount'] as num),
charge: const DecimalJsonConverter().fromJson(json['charge'] as num), charge: const DecimalJsonConverter().fromJson(json['charge'] as num),
@@ -74,6 +76,8 @@ Map<String, dynamic> _$TransactionModelToJson(
const DateTimeJsonConverter().toJson, const DateTimeJsonConverter().toJson,
), ),
'userId': instance.userId, 'userId': instance.userId,
'workspaceId': instance.workspaceId,
'batchId': instance.batchId,
'trace': instance.trace, 'trace': instance.trace,
'amount': const DecimalJsonConverter().toJson(instance.amount), 'amount': const DecimalJsonConverter().toJson(instance.amount),
'charge': const DecimalJsonConverter().toJson(instance.charge), 'charge': const DecimalJsonConverter().toJson(instance.charge),

View File

@@ -1,6 +1,8 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:qpay/screens/workspaces/workspace_model.dart';
import 'package:qpay/screens/workspaces/workspace_provider.dart'; import 'package:qpay/screens/workspaces/workspace_provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
@@ -27,7 +29,6 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
late Animation<Offset> _slideAnimation; late Animation<Offset> _slideAnimation;
AuthState authState = AuthState(); AuthState authState = AuthState();
bool _navigated = false;
@override @override
void initState() { void initState() {
@@ -86,8 +87,6 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
} }
void _evaluateNavigation(WorkspaceProvider provider) { void _evaluateNavigation(WorkspaceProvider provider) {
if (_navigated) return;
final workspaces = provider.workspaces; final workspaces = provider.workspaces;
if (workspaces.length == 1) { if (workspaces.length == 1) {
@@ -104,20 +103,16 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
// 2+ workspaces: stay on this screen so the user can pick one. // 2+ workspaces: stay on this screen so the user can pick one.
} }
void _onWorkspaceSelected(String workspaceId) async { void _onWorkspaceSelected(WorkspaceModel ws) async {
if (_navigated) return;
_navigated = true;
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
await prefs.setString('workspaceId', workspaceId); await prefs.setString('workspaceId', ws.id);
await prefs.setString('workspaceInitials', ws.name[0]);
if (!mounted) return; if (!mounted) return;
_navigateToHome(); _navigateToHome();
} }
void _navigateToHome() { void _navigateToHome() {
if (_navigated) return;
_navigated = true;
context.go('/'); context.go('/');
} }
@@ -149,16 +144,19 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
final workspaces = provider.workspaces; final workspaces = provider.workspaces;
return SafeArea( return SafeArea(
child: Center(
child: FadeTransition( child: FadeTransition(
opacity: _fadeAnimation, opacity: _fadeAnimation,
child: SlideTransition( child: SlideTransition(
position: _slideAnimation, position: _slideAnimation,
child: SizedBox(
width: kIsWeb ? 600 : double.infinity,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24), padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Spacer(flex: 2), const SizedBox(height: 48),
// Header // Header
Container( Container(
width: 56, width: 56,
@@ -204,17 +202,19 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
description: ws.description, description: ws.description,
email: ws.email, email: ws.email,
phone: ws.phone, phone: ws.phone,
onTap: () => _onWorkspaceSelected(ws.id), onTap: () => _onWorkspaceSelected(ws),
); );
}, },
), ),
), ),
const Spacer(flex: 1), const SizedBox(height: 24),
], ],
), ),
), ),
), ),
), ),
),
),
); );
}, },
), ),