Skip to content

Commit

Permalink
feat: deny request (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 committed Oct 23, 2024
1 parent 83cb6e7 commit 0222b5e
Showing 1 changed file with 34 additions and 9 deletions.
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);
});

LoggerService.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

0 comments on commit 0222b5e

Please sign in to comment.