Skip to content

Commit

Permalink
Sort hr request
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Jul 14, 2023
1 parent dfd8fb4 commit 348fec5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/data/core/utils/const/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FireStoreConst {
static const String session = 'session';
static const String uid = 'uid';

static const String id = 'uid';
static const String requestedAt = 'requested_at';
static const String status = 'status';

static const String receiverEmail = 'receiver_email';
Expand Down
8 changes: 5 additions & 3 deletions lib/data/services/hr_request_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class HrRequestService {
String get generateNewId => _hrRequestDB().doc().id;

Future<List<HrRequest>> getHrRequests() async {
final hrDeskRequestsCollection = await _hrRequestDB().get();
final hrDeskRequestsCollection =
await _hrRequestDB().get();
return hrDeskRequestsCollection.docs.map((e) => e.data()).toList();
}

Future<List<HrRequest>> getHrRequestsOfUser(String uid) async {
final hrDeskRequestsCollection =
await _hrRequestDB().where(FireStoreConst.uid, isEqualTo: uid).get();
final hrDeskRequestsCollection = await _hrRequestDB()
.where(FireStoreConst.uid, isEqualTo: uid)
.get();
return hrDeskRequestsCollection.docs.map((e) => e.data()).toList();
}

Expand Down
10 changes: 10 additions & 0 deletions lib/ui/shared/appbar_drawer/drawer/app_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ class DrawerOptionList extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
ValidateWidget(
isValid: !isAdminOrHr,
child: DrawerOption(
icon: Icons.help_outline_rounded,
title: "HR Service Desk",
onTap: () {
context.pop();
context.pushNamed(Routes.hrRequests);
}),
),
ValidateWidget(
isValid: isAdmin,
child: DrawerOption(
Expand Down
3 changes: 0 additions & 3 deletions lib/ui/user/home/home_screen/user_home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ class _UserHomeScreenState extends State<UserHomeScreen> {
padding: const EdgeInsets.all(primaryHorizontalSpacing),
children: [
const WhoIsOutCard(),
ElevatedButton(onPressed: (){
context.goNamed(Routes.hrRequests);
}, child: Text(locale.hr_requests_title)),
BlocConsumer<UserHomeBloc, UserHomeState>(
buildWhen: (previous, current) =>
current is! UserHomeErrorState,
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/user/hr_requests/bloc/hr_requests_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class HrRequestsBloc
try {
final hrServiceDeskRequests = await _hrRequestService
.getHrRequestsOfUser(_userStateNotifier.employeeId);
hrServiceDeskRequests.sort((a, b) => b.requestedAt.compareTo(a.requestedAt));
emit(state.copyWith(
status: Status.success,
hrServiceDeskRequests: hrServiceDeskRequests));
} on Exception {
emit(
state.copyWith(status: Status.error, error: firestoreFetchDataError));
emit(state.copyWith(status: Status.error, error: firestoreFetchDataError));
}
}
}

0 comments on commit 348fec5

Please sign in to comment.