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

fix: menu screens, leave and coupon logic #250

Merged
merged 16 commits into from
Sep 24, 2023
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
3 changes: 3 additions & 0 deletions assets/icons/coupon_taken_tick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/data/constants/api_endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApiEndpoints {
static const String checkVersion =
'/panel/version/expire/{platform}/{versionNumber}';

static const String coupon = '/api/coupon';
static const String coupon = '/api/coupon/';
static const String couponWithId = '/api/coupon/{couponId}';
static const String allCoupons = '/api/coupon/all';

Expand Down
3 changes: 1 addition & 2 deletions lib/data/services/remote/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:appetizer/domain/models/leaves/paginated_leaves.dart';
import 'package:appetizer/domain/models/menu/week_menu_tmp.dart';
import 'package:appetizer/domain/models/transaction/faq.dart';
import 'package:appetizer/domain/models/transaction/paginated_yearly_rebate.dart';
import 'package:appetizer/domain/models/user/notification.dart';
import 'package:appetizer/domain/models/user/oauth_user.dart';
import 'package:appetizer/domain/models/user/user.dart';
import 'package:appetizer/domain/repositories/leave/leave_repository.dart';
Expand Down Expand Up @@ -181,5 +180,5 @@ abstract class ApiService {
);

@GET(ApiEndpoints.notifications)
Future<List<Notification>> getNotifications();
Future getNotifications();
}
8 changes: 4 additions & 4 deletions lib/domain/repositories/coupon_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class CouponRepository {

CouponRepository(this._apiService);

Future<CouponStatus> applyForCoupon(Coupon coupon) async {
Future<CouponStatus> applyForCoupon(int mealId) async {
Map<String, dynamic> map = {
'meal': coupon.mealId,
'meal': mealId,
'is_active': true,
};
try {
Expand All @@ -23,12 +23,12 @@ class CouponRepository {
}
}

Future<CouponStatus> cancelCoupon(Coupon coupon) async {
Future<CouponStatus> cancelCoupon(CouponStatus coupon) async {
Map<String, dynamic> map = {
'is_active': false,
};
try {
return await _apiService.cancelCoupon(coupon.mealId, map);
return await _apiService.cancelCoupon(coupon.id!, map);
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
Expand Down
4 changes: 4 additions & 0 deletions lib/domain/repositories/leave/leave_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:appetizer/data/services/remote/api_service.dart';
import 'package:appetizer/domain/models/failure_model.dart';
import 'package:appetizer/domain/models/leaves/paginated_leaves.dart';
import 'package:appetizer/domain/models/menu/week_menu_tmp.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart';

Expand Down Expand Up @@ -73,6 +74,9 @@ class LeaveRepository {
};
try {
return await _apiService.leave(map);
} on DioException catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
Expand Down
8 changes: 7 additions & 1 deletion lib/domain/repositories/user/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ class UserRepository {

Future<List<Notification>> getNotifications() async {
try {
return await _apiService.getNotifications();
// TODO: test with some notification data
final response = await _apiService.getNotifications();
List<Notification> notifications = [];
for (var notification in response["results"]) {
notifications.add(Notification.fromJson(notification));
}
return notifications;
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appetizer/data/core/router/intrinsic_router/intrinsic_router.gr.dart';
import 'package:appetizer/domain/repositories/coupon_repository.dart';
import 'package:appetizer/domain/repositories/leave/leave_repository.dart';
import 'package:appetizer/domain/repositories/menu_repository.dart';
import 'package:appetizer/presentation/app/bloc/app_bloc.dart';
Expand Down Expand Up @@ -41,6 +42,7 @@ class BottomNavigatorScreen extends StatelessWidget {
create: (context) => WeekMenuBlocBloc(
menuRepository: context.read<MenuRepository>(),
leaveRepository: context.read<LeaveRepository>(),
couponRepository: context.read<CouponRepository>(),
)..add(const FetchWeekMenuData()),
),
BlocProvider(
Expand Down
13 changes: 6 additions & 7 deletions lib/presentation/components/shadow_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import 'package:flutter/material.dart';

class ShadowContainer extends StatelessWidget {
const ShadowContainer({
super.key,
required this.child,
required this.height,
required this.width,
required this.offset,
// required this.padding
this.height,
this.width,
super.key,
});
final double height, width, offset;
// final EdgeInsetsGeometry padding;

final double? height, width;
final double offset;
final Widget child;

@override
Widget build(BuildContext context) {
return Container(
height: height,
width: width,
// padding: padding,
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(
Expand Down
47 changes: 30 additions & 17 deletions lib/presentation/leaves_and_rebate/leaves_and_rebate.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appetizer/app_theme.dart';
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/app/bloc/app_bloc.dart';
import 'package:appetizer/presentation/components/loading_indicator.dart';
import 'package:appetizer/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart';
import 'package:appetizer/presentation/leaves_and_rebate/components/custom_divider.dart';
import 'package:appetizer/presentation/leaves_and_rebate/components/leave_history.dart';
Expand Down Expand Up @@ -43,7 +44,7 @@ class LeavesAndRebateScreen extends StatelessWidget {
if (state.loading) ...[
const Expanded(
child: Center(
child: CircularProgressIndicator(),
child: LoadingIndicator(),
),
),
],
Expand Down Expand Up @@ -95,27 +96,39 @@ class LeavesAndRebateScreen extends StatelessWidget {
children: [
Row(
children: [
Text("Remaining Leaves : ",
style: AppTheme.subtitle1.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.black2e)),
Text(state.remainingLeaves.toString(),
style: AppTheme.headline2.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.primary))
Text(
"Remaining Leaves : ",
style: AppTheme.subtitle1.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.black2e,
),
),
Text(
state.remainingLeaves.toString(),
style: AppTheme.headline2.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.primary,
),
)
],
),
12.toVerticalSizedBox,
Row(
children: [
Text("Meals Skipped : ",
style: AppTheme.subtitle1.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.black2e)),
Text(state.mealsSkipped.toString(),
style: AppTheme.headline2.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.primary))
Text(
"Meals Skipped : ",
style: AppTheme.subtitle1.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.black2e,
),
),
Text(
state.mealsSkipped.toString(),
style: AppTheme.headline2.copyWith(
fontSize: 14.toAutoScaledFont,
color: AppTheme.primary,
),
)
],
),
20.toVerticalSizedBox,
Expand Down
8 changes: 1 addition & 7 deletions lib/presentation/login/bloc/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {

FutureOr<void> _onForgotPasswordPressed(event, emit) async {
emit(Loading());
try {
await userRepository.sendResetPasswordLink(event.emailId);
// TODO: show dialog box that link has been sent
} catch (e) {
// TODO: show dialog box with error message
emit(const LoginInitial(error: AppConstants.GENERIC_FAILURE));
}
emit(const ForgotPasswordState());
}

FutureOr<void> _onShowPasswordPressed(event, emit) {
Expand Down
5 changes: 1 addition & 4 deletions lib/presentation/login/bloc/login_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ class SendPasswordResetInstructions extends LoginEvent {
SendPasswordResetInstructions({required this.emailId});
}

class ForgotPasswordPressed extends LoginEvent {
final String emailId;
ForgotPasswordPressed({required this.emailId});
}
class ForgotPasswordPressed extends LoginEvent {}

class CreatedPasswordNewUser extends LoginEvent {
final OAuthUser user;
Expand Down
5 changes: 2 additions & 3 deletions lib/presentation/login/bloc/login_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ class EnterPassword extends LoginState {
}

class ForgotPasswordState extends LoginState {
const ForgotPasswordState({required this.emailID});
final String emailID;
const ForgotPasswordState();

@override
List<Object?> get props => [emailID];
List<Object?> get props => [];
}

class LoginSuccess extends LoginState {
Expand Down
17 changes: 11 additions & 6 deletions lib/presentation/login/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/app/bloc/app_bloc.dart';
import 'package:appetizer/presentation/components/loading_indicator.dart';
import 'package:appetizer/presentation/components/made_by_mdg.dart';
import 'package:appetizer/presentation/components/raise_query_button.dart';
import 'package:appetizer/presentation/login/components/channeli_button.dart';
Expand Down Expand Up @@ -66,9 +67,6 @@ class LoginScreen extends StatelessWidget {
EdgeInsets.symmetric(horizontal: 25.toAutoScaledWidth),
child: BlocConsumer<LoginBloc, LoginState>(
listener: (context, state) {
if (state is EnterPassword) {
_controller.clear();
}
if (state is LoginSuccess) {
context.read<AppBloc>().add(const GetUser());
}
Expand All @@ -78,11 +76,13 @@ class LoginScreen extends StatelessWidget {
content: Text(state.error!),
),
);
_controller.clear();
}
},
builder: (context, state) {
if (state is Loading) {
return const Center(child: CircularProgressIndicator());
_controller.clear();
return const Center(child: LoadingIndicator());
}
if (state is CreatePassword) {
return Column(
Expand Down Expand Up @@ -232,7 +232,12 @@ class LoginScreen extends StatelessWidget {
),
if (state is! ForgotPasswordState)
TextButton(
onPressed: () {},
onPressed: () {
// TODO: send to fogot password screen
context
.read<LoginBloc>()
.add(ForgotPasswordPressed());
},
child: Text(
'Forgot Password?',
style: GoogleFonts.lato(
Expand Down Expand Up @@ -261,7 +266,7 @@ class LoginScreen extends StatelessWidget {
: state is ForgotPasswordState
? context.read<LoginBloc>().add(
SendPasswordResetInstructions(
emailId: state.emailID))
emailId: _controller.text))
: context
.read<LoginBloc>()
.add(NextPressed(_controller.text));
Expand Down
32 changes: 32 additions & 0 deletions lib/presentation/notifications/components/notification_banner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:appetizer/app_theme.dart';
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/components/app_banner.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';

class NotificationBanner extends StatelessWidget {
const NotificationBanner({super.key});

@override
Widget build(BuildContext context) {
return AppBanner(
height: 140.toAutoScaledHeight,
child: Row(
children: [
IconButton(
onPressed: context.router.pop,
icon: const Icon(
Icons.arrow_back,
color: Colors.white,
),
),
Text(
"Notifications",
style: AppTheme.headline1,
),
],
),
// ),
);
}
}
Loading