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

feat: deny request #4

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
43 changes: 34 additions & 9 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ class HomeScreenState extends State<HomeScreen> {
},
),
TextButton(
child: const Text('Cancel'),
child: const Text('Reject'),
onPressed: () {
Navigator.of(context).pop();
_rejectRequest(index);
},
),
],
Expand Down Expand Up @@ -317,10 +318,10 @@ class HomeScreenState extends State<HomeScreen> {
},
),
TextButton(
child: const Text('Cancel'),
child: const Text('Reject'),
onPressed: () {
Navigator.of(dialogContext).pop();
_cancelRequest(index);
_rejectRequest(index);
},
),
],
Expand Down Expand Up @@ -367,12 +368,36 @@ class HomeScreenState extends State<HomeScreen> {
}
}

void _cancelRequest(int index) {
setState(() {
_cancellationCount++;
_approvedStatus[index] = true;
});
LoggerService.info('Request cancelled');
Future<void> _rejectRequest(int index) async {
try {
await FirebaseFirestore.instance
.collection('bookings')
.doc(_requests[index]['docId'])
.update({
'status': 'rejected',
});

setState(() {
_cancellationCount++;
_approvedStatus[index] = true;
_requests.removeAt(index);
});

LoggerServe.info('Request denied');

if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Request denied')),
);
}
} catch (e) {
LoggerService.error('Error rejecting request', e);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error rejecting request: ${e.toString()}')),
);
}
}
}

void _showEvLogs() {
Expand Down
Loading