diff --git a/lib/new_ui/screens/railway_screen/railway_screen.dart b/lib/new_ui/screens/railway_screen/railway_screen.dart index 410c0ea1..4c4b1f82 100644 --- a/lib/new_ui/screens/railway_screen/railway_screen.dart +++ b/lib/new_ui/screens/railway_screen/railway_screen.dart @@ -70,11 +70,10 @@ class _RailwayConcessionScreenState DateTime today = DateTime.now(); DateTime lastPass = lastPassIssued ?? DateTime.now(); DateTime futurePass = lastPass.add( - duration == "Monthly" ? const Duration(days: 30) : Duration(days: 90)); + duration == "Monthly" ? const Duration(days: 27) : Duration(days: 87)); int diff = futurePass.difference(today).inDays; return "You will be able to apply for a new pass after $diff days"; } - @override void didChangeDependencies() { super.didChangeDependencies(); @@ -331,7 +330,7 @@ class _RailwayConcessionScreenState previousPassURL: previousPassURL, from: homeStation, to: toStation, - lastPassIssued: lastPassIssued, + lastPassIssued: null, address: addressController.text, dob: _selectedDate ?? DateTime.now(), phoneNum: int.parse(phoneNumController.text), @@ -346,9 +345,9 @@ class _RailwayConcessionScreenState previousPassPhoto = previousPassPhotoTemp; ref.read(railwayConcessionOpenProvider.state).state = false; - await ref - .watch(concessionProvider.notifier) - .applyConcession(details, idCardPhoto!, previousPassPhoto!, context); + // await ref + // .watch(concessionProvider.notifier) + // .applyConcession(details, idCardPhoto!, previousPassPhoto!, context); } else if (idCardPhotoTemp == null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text("Please add the photo of your ID card")), @@ -456,12 +455,22 @@ class _RailwayConcessionScreenState SizedBox( height: 15, ), + + Container( + width: size.width * 0.68, + child: Text( + "${futurePassMessage()}", + style: TextStyle(fontSize: 18, color: Colors.white), + )), + SizedBox( + height: 15, + ), Container( width: size.width * 0.8, child: Text( "Previous Passes", style: TextStyle(fontSize: 18, color: Colors.white), - )) + )), ], ), ), diff --git a/lib/new_ui/screens/railway_screen/railwayform.dart b/lib/new_ui/screens/railway_screen/railwayform.dart index 4113ae7e..1cc2c689 100644 --- a/lib/new_ui/screens/railway_screen/railwayform.dart +++ b/lib/new_ui/screens/railway_screen/railwayform.dart @@ -68,7 +68,7 @@ class _RailwayForm extends ConsumerState { DateTime today = DateTime.now(); DateTime lastPass = lastPassIssued ?? DateTime.now(); DateTime futurePass = lastPass.add( - duration == "Monthly" ? const Duration(days: 30) : Duration(days: 90)); + duration == "Monthly" ? const Duration(days: 27) : Duration(days: 87)); int diff = futurePass.difference(today).inDays; return "You will be able to apply for a new pass after $diff days"; } @@ -328,7 +328,7 @@ class _RailwayForm extends ConsumerState { previousPassURL: previousPassURL, from: homeStation, to: toStation, - lastPassIssued: lastPassIssued, + lastPassIssued: null, address: addressController.text, dob: _selectedDate ?? DateTime.now(), phoneNum: int.parse(phoneNumController.text), @@ -346,6 +346,8 @@ class _RailwayForm extends ConsumerState { await ref .watch(concessionProvider.notifier) .applyConcession(details, idCardPhoto!, previousPassPhoto!, context); + clearValues(); + Navigator.pop(context); } else if (idCardPhotoTemp == null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text("Please add the photo of your ID card")), diff --git a/lib/provider/concession_provider.dart b/lib/provider/concession_provider.dart index 77824c24..7683c66c 100644 --- a/lib/provider/concession_provider.dart +++ b/lib/provider/concession_provider.dart @@ -66,7 +66,7 @@ class ConcessionProvider extends StateNotifier { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( - content: Text('All the attached photos have been uploaded'), + content: Text('All the attached photos have been uploaded.\n Concession Successfully Applied.'), ), ); } diff --git a/lib/screens/railwayConcession/widgets/railway_edit_modal.dart b/lib/screens/railwayConcession/widgets/railway_edit_modal.dart index 11a8de20..ceb0dc6f 100644 --- a/lib/screens/railwayConcession/widgets/railway_edit_modal.dart +++ b/lib/screens/railwayConcession/widgets/railway_edit_modal.dart @@ -243,9 +243,9 @@ class _RailwayEditModalState extends ConsumerState { if (_formKey.currentState!.validate() && idCardPhoto != null && previousPassPhoto != null) { - await ref - .watch(concessionProvider.notifier) - .applyConcession(details, idCardPhoto!, previousPassPhoto!, context); + // await ref + // .watch(concessionProvider.notifier) + // .applyConcession(details, idCardPhoto!, previousPassPhoto!, context); } } diff --git a/lib/services/concession_service.dart b/lib/services/concession_service.dart index 20428e95..a475a3ad 100644 --- a/lib/services/concession_service.dart +++ b/lib/services/concession_service.dart @@ -121,13 +121,25 @@ class ConcessionService { statusMessage: "", ); + // try { + // await concessionRequestCollection.add(concessionRequest.toJson()); + // print('request created successfully!'); + // } catch (e) { + // print('Error updating or creating document: $e'); + // } try { - await concessionRequestCollection.add(concessionRequest.toJson()); - print('request created successfully!'); + // Add or update the concession request in Firestore + DocumentReference concessionRequestDoc = + concessionRequestCollection.doc(user!.uid); + await concessionRequestDoc.set(concessionRequest.toJson(), + SetOptions(merge: true)); // Use merge to update or create + + print('Concession request updated or created successfully!'); } catch (e) { - print('Error updating or creating document: $e'); + print('Error updating or creating concession request: $e'); } + // concessionDetails.idCardURL = ""; concessionDetails.status = status; concessionDetails.statusMessage = statusMessage;