added navigation and selection of workspaces
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
@@ -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.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -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!;
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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,24 +347,28 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
end: Alignment.bottomLeft,
|
end: Alignment.bottomLeft,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: InkWell(
|
||||||
child: Text(
|
child: Center(
|
||||||
initials,
|
child: Text(
|
||||||
style: TextStyle(
|
initials,
|
||||||
fontSize: 12,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontSize: 12,
|
||||||
color: isDark ? Colors.white : Colors.black87,
|
fontWeight: FontWeight.bold,
|
||||||
|
color: isDark ? Colors.white : Colors.black87,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
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(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -1111,4 +1120,4 @@ class _DetailItem {
|
|||||||
this.isWarning = false,
|
this.isWarning = false,
|
||||||
this.trailing,
|
this.trailing,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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),
|
||||||
|
|||||||
@@ -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,68 +144,73 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
|
|||||||
final workspaces = provider.workspaces;
|
final workspaces = provider.workspaces;
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: FadeTransition(
|
child: Center(
|
||||||
opacity: _fadeAnimation,
|
child: FadeTransition(
|
||||||
child: SlideTransition(
|
opacity: _fadeAnimation,
|
||||||
position: _slideAnimation,
|
child: SlideTransition(
|
||||||
child: Padding(
|
position: _slideAnimation,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
child: SizedBox(
|
||||||
child: Column(
|
width: kIsWeb ? 600 : double.infinity,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Padding(
|
||||||
children: [
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
const Spacer(flex: 2),
|
child: Column(
|
||||||
// Header
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Container(
|
children: [
|
||||||
width: 56,
|
const SizedBox(height: 48),
|
||||||
height: 56,
|
// Header
|
||||||
decoration: BoxDecoration(
|
Container(
|
||||||
color: theme.colorScheme.primary.withValues(
|
width: 56,
|
||||||
alpha: 0.1,
|
height: 56,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primary.withValues(
|
||||||
|
alpha: 0.1,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
Icons.business_rounded,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
size: 28,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(16),
|
const SizedBox(height: 24),
|
||||||
),
|
Text(
|
||||||
child: Icon(
|
'Select a workspace',
|
||||||
Icons.business_rounded,
|
style: theme.textTheme.headlineSmall?.copyWith(
|
||||||
color: theme.colorScheme.primary,
|
fontWeight: FontWeight.w700,
|
||||||
size: 28,
|
color: Colors.black87,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Choose the workspace you want to work in.',
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Colors.grey.shade600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
// Workspace list
|
||||||
|
Expanded(
|
||||||
|
child: ListView.separated(
|
||||||
|
itemCount: workspaces.length,
|
||||||
|
separatorBuilder: (_, __) =>
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final ws = workspaces[index];
|
||||||
|
return _WorkspaceCard(
|
||||||
|
name: ws.name,
|
||||||
|
description: ws.description,
|
||||||
|
email: ws.email,
|
||||||
|
phone: ws.phone,
|
||||||
|
onTap: () => _onWorkspaceSelected(ws),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
),
|
||||||
Text(
|
|
||||||
'Select a workspace',
|
|
||||||
style: theme.textTheme.headlineSmall?.copyWith(
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'Choose the workspace you want to work in.',
|
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
// Workspace list
|
|
||||||
Expanded(
|
|
||||||
child: ListView.separated(
|
|
||||||
itemCount: workspaces.length,
|
|
||||||
separatorBuilder: (_, __) =>
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final ws = workspaces[index];
|
|
||||||
return _WorkspaceCard(
|
|
||||||
name: ws.name,
|
|
||||||
description: ws.description,
|
|
||||||
email: ws.email,
|
|
||||||
phone: ws.phone,
|
|
||||||
onTap: () => _onWorkspaceSelected(ws.id),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(flex: 1),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user