Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved railway backend #151

Merged
merged 6 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/new_ui/screens/railway_screen/railway_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand All @@ -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")),
Expand Down Expand Up @@ -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),
))
)),
],
),
),
Expand Down
6 changes: 4 additions & 2 deletions lib/new_ui/screens/railway_screen/railwayform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _RailwayForm extends ConsumerState<RailwayForm> {
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";
}
Expand Down Expand Up @@ -328,7 +328,7 @@ class _RailwayForm extends ConsumerState<RailwayForm> {
previousPassURL: previousPassURL,
from: homeStation,
to: toStation,
lastPassIssued: lastPassIssued,
lastPassIssued: null,
address: addressController.text,
dob: _selectedDate ?? DateTime.now(),
phoneNum: int.parse(phoneNumController.text),
Expand All @@ -346,6 +346,8 @@ class _RailwayForm extends ConsumerState<RailwayForm> {
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")),
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/concession_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ConcessionProvider extends StateNotifier<bool> {

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.'),
),
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/railwayConcession/widgets/railway_edit_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ class _RailwayEditModalState extends ConsumerState<RailwayEditModal> {
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);
}
}

Expand Down
18 changes: 15 additions & 3 deletions lib/services/concession_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading