Skip to content

Commit

Permalink
Merge pull request #1235 from givtnl/feature/kids-1499-move-to-new-gi…
Browse files Browse the repository at this point in the history
…ving-endpoint-for-us-parents

Move to new giving cubit and endpoint for US adults (kids-1499 & kids-1501)
  • Loading branch information
Daniela510 authored Nov 7, 2024
2 parents 451ed7f + 2bfc4c0 commit eea74b2
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 484 deletions.
18 changes: 1 addition & 17 deletions lib/app/routes/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import 'package:givt_app/features/give/pages/organization_list_page.dart';
import 'package:givt_app/features/give/pages/qr_code_scan_page.dart';
import 'package:givt_app/features/give/pages/select_giving_way_page.dart';
import 'package:givt_app/features/give/pages/success_donation_page.dart';
import 'package:givt_app/features/impact_groups/models/impact_group.dart';
import 'package:givt_app/features/impact_groups/pages/impact_group_details_page.dart';
import 'package:givt_app/features/overview/bloc/givt_bloc.dart';
import 'package:givt_app/features/overview/pages/overview_page.dart';
import 'package:givt_app/features/permit_biometric/cubit/permit_biometric_cubit.dart';
Expand Down Expand Up @@ -142,21 +140,7 @@ class AppRouter {
child: const LoadingPage(),
),
),
GoRoute(
path: Pages.impactGroupDetails.path,
name: Pages.impactGroupDetails.name,
builder: (context, state) => BlocProvider(
create: (_) => GiveBloc(
getIt(),
getIt(),
getIt(),
getIt(),
),
child: ImpactGroupDetailsPage(
impactGroup: state.extra! as ImpactGroup,
),
),
),

GoRoute(
path: Pages.home.path,
name: Pages.home.name,
Expand Down
5 changes: 0 additions & 5 deletions lib/app/routes/pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ enum Pages {
name: 'EDIT-CREDIT-CARD-DETAILS',
),
permitBiometric(path: 'permit-biometric', name: 'PERMIT-BIOMETRIC'),

impactGroupDetails(
path: '/impact-group-details',
name: 'IMPACT-GROUP-DETAILS',
),
;

const Pages({
Expand Down
3 changes: 1 addition & 2 deletions lib/core/enums/amplitude_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ enum AmplitudeEvents {
nextPermissionsDialogClicked('next_permissions_dialog_clicked'),
closePermissionsDialog('close_permissions_dialog'),
navigationBarPressed('navigation_bar_pressed'),
impactGroupDetailsReadMoreClicked('impact_group_details_read_more_clicked'),
impactGroupDetailsGiveClicked('impact_group_details_give_clicked'),
manageFamilyPressed('manage_family_pressed'),
registerWithoutChallengeClicked('register_without_challenge_clicked'),
goToChallengeFromRegistrationClicked(
Expand Down Expand Up @@ -255,6 +253,7 @@ enum AmplitudeEvents {
parentGiveWithAmountClicked('parent_give_with_amount_clicked'),
parentGiveClicked('parent_give_clicked'),
parentGiveFilterTileClicked('parent_give_filter_tile_clicked'),
parentGaveSuccessfully('parent_gave_successfully'),

// Reflect and Share
reflectandShareAssignRolesClicked('reflect_and_share_assign_roles_clicked'),
Expand Down
4 changes: 0 additions & 4 deletions lib/features/family/app/family_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ enum FamilyPages {
path: 'school-event-organisations',
name: 'SCHOOL_EVENT_ORGANISATIONS',
),
impactGroupDetails(
path: 'kids-impact-group-details',
name: 'KIDS_IMPACT_GROUP_DETAILS',
),

//reflect and share:
reflectIntro(path: 'reflect-intro', name: 'REFLECT-INTRO'),
Expand Down
8 changes: 3 additions & 5 deletions lib/features/family/app/injection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:givt_app/features/family/features/history/history_repository/his
import 'package:givt_app/features/family/features/home_screen/cubit/family_home_screen_cubit.dart';
import 'package:givt_app/features/family/features/home_screen/cubit/navigation_bar_home_cubit.dart';
import 'package:givt_app/features/family/features/impact_groups/repository/impact_groups_repository.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/cubit/give_cubit.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/cubit/medium_cubit.dart';
import 'package:givt_app/features/family/features/profiles/repository/profiles_repository.dart';
import 'package:givt_app/features/family/features/qr_scanner/cubit/camera_cubit.dart';
Expand Down Expand Up @@ -66,11 +67,8 @@ void initCubits() {
CameraCubit.new,
)
..registerLazySingleton<MediumCubit>(MediumCubit.new)
..registerLazySingleton<GiveBloc>(
() => GiveBloc(
getIt(),
getIt(),
getIt(),
..registerLazySingleton<GiveCubit>(
() => GiveCubit(
getIt(),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ class Transaction {
required this.mediumId,
required this.amount,
this.goalId,
this.isActOfService = false,
});

final String userId;
final String mediumId;
final double amount;
final String? goalId;
final bool isActOfService;

Map<String, dynamic> toJson() {
return {
'userId': userId,
'mediumId': mediumId,
'amount': amount,
'goalId': goalId,
'isActOfService': isActOfService,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class ChooseAmountSliderScreen extends StatelessWidget {
const ChooseAmountSliderScreen({
super.key,
this.onCustomSuccess,
this.isActOfService = false,
});

final void Function()? onCustomSuccess;

final bool isActOfService;
@override
Widget build(BuildContext context) {
final flow = context.read<FlowsCubit>().state;
Expand Down Expand Up @@ -106,6 +107,7 @@ class ChooseAmountSliderScreen extends StatelessWidget {
userId: profilesCubit.state.activeProfile.id,
mediumId: mediumId,
amount: state.amount,
isActOfService: isActOfService,
);

await context
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'dart:convert';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:givt_app/core/enums/amplitude_events.dart';
import 'package:givt_app/core/logging/logging_service.dart';
import 'package:givt_app/features/family/features/giving_flow/create_transaction/models/transaction.dart';
import 'package:givt_app/features/family/features/giving_flow/create_transaction/repositories/create_transaction_repository.dart';
import 'package:givt_app/features/give/models/givt_transaction.dart';
import 'package:givt_app/utils/analytics_helper.dart';

part 'give_state.dart';

class GiveCubit extends Cubit<GiveState> {
GiveCubit(
this._createTransactionRepository,
) : super(GiveInitial());
final CreateTransactionRepository _createTransactionRepository;

Future<void> createTransaction({
required String userId,
required int amount,
required String orgName,
required String mediumId,
bool isGratitude = false,
}) async {
emit(GiveLoading());
final transaction = Transaction(
userId: userId,
amount: amount.toDouble(),
mediumId: base64Encode(utf8.encode(mediumId)),
isActOfService: isGratitude,
);
try {
await _createTransactionRepository.createTransaction(
transaction: transaction,
);

await AnalyticsHelper.logEvent(
eventName: AmplitudeEvents.parentGaveSuccessfully,
eventProperties: {
'amount': transaction.amount,
'organisation': orgName,
'mediumid': mediumId,
},
);
emit(GiveFromBrowser(GivtTransaction.fromTransaction(transaction),
transaction, orgName, mediumId));
} catch (error, stackTrace) {
LoggingInfo.instance.error(
'Error while creating transaction: $error',
methodName: stackTrace.toString(),
);
emit(const GiveError('Error creating transaction.'));
}
}

void reset() {
emit(GiveInitial());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
part of 'give_cubit.dart';

sealed class GiveState extends Equatable {
const GiveState();

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

final class GiveInitial extends GiveState {}

final class GiveLoading extends GiveState {}

final class GiveFromBrowser extends GiveState {
const GiveFromBrowser(
this.givtTransactionObject,
this.transaction,
this.orgName,
this.mediumId,
);

// this is legacy for the browser page
final GivtTransaction givtTransactionObject;
// this is the object we use for parent giving in US
final Transaction transaction;
final String orgName;
final String mediumId;

@override
List<Object> get props =>
[givtTransactionObject, transaction, orgName, mediumId];
}

final class GiveError extends GiveState {
const GiveError(this.error);

final String error;

@override
List<Object> get props => [error];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'package:givt_app/core/enums/collect_group_type.dart';
import 'package:givt_app/features/auth/cubit/auth_cubit.dart';
import 'package:givt_app/features/family/app/family_pages.dart';
import 'package:givt_app/features/family/extensions/extensions.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/cubit/give_cubit.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/cubit/medium_cubit.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/presentation/pages/organisation_list_family_page.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/presentation/pages/parent_amount_page.dart';
import 'package:givt_app/features/family/shared/widgets/loading/custom_progress_indicator.dart';
import 'package:givt_app/features/give/bloc/give/give_bloc.dart';
import 'package:givt_app/l10n/l10n.dart';
import 'package:givt_app/shared/models/collect_group.dart';
import 'package:givt_app/utils/analytics_helper.dart';
Expand All @@ -24,35 +24,24 @@ class GiveFromListPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final locals = context.l10n;
final give = getIt<GiveBloc>();
return BlocConsumer<GiveBloc, GiveState>(
final give = getIt<GiveCubit>();
return BlocConsumer<GiveCubit, GiveState>(
bloc: give,
listener: (context, state) {
final userGUID = context.read<AuthCubit>().state.user.guid;
if (state.status == GiveStatus.success) {
give.add(
GiveOrganisationSelected(
nameSpace: getIt<MediumCubit>().state.mediumId,
userGUID: userGUID,
),
);
}
if (state.status == GiveStatus.readyToGive) {
if (state is GiveFromBrowser) {
context.pushReplacementNamed(
FamilyPages.parentGive.name,
);
}
if (state.status == GiveStatus.error) {
if (state is GiveError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(locals.somethingWentWrong),
),
);
}
},
builder: (context, giveState) => giveState.status == GiveStatus.loading ||
giveState.status == GiveStatus.processed ||
giveState.status == GiveStatus.success
builder: (context, giveState) => giveState is GiveLoading
? const Scaffold(body: CustomCircularProgressIndicator())
: OrganisationListFamilyPage(
onTap: (CollectGroup collectGroup) {
Expand Down Expand Up @@ -95,12 +84,11 @@ class GiveFromListPage extends StatelessWidget {
},
),
);
getIt<GiveBloc>().add(
GiveAmountChanged(
firstCollectionAmount: result.toDouble(),
secondCollectionAmount: 0,
thirdCollectionAmount: 0,
),
await getIt<GiveCubit>().createTransaction(
userId: context.read<AuthCubit>().state.user.guid,
amount: result,
orgName: collectGroup.orgName,
mediumId: collectGroup.nameSpace,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:givt_app/core/enums/amplitude_events.dart';
import 'package:givt_app/features/auth/cubit/auth_cubit.dart';
import 'package:givt_app/features/family/shared/widgets/buttons/givt_back_button_flat.dart';
import 'package:givt_app/features/registration/pages/credit_card_details.dart';
import 'package:givt_app/shared/models/color_combo.dart';
import 'package:givt_app/features/family/shared/design/components/components.dart';
import 'package:givt_app/features/family/shared/widgets/buttons/givt_back_button_flat.dart';
import 'package:givt_app/features/family/shared/widgets/texts/shared_texts.dart';
import 'package:givt_app/features/family/utils/family_auth_utils.dart';
import 'package:givt_app/features/registration/pages/credit_card_details.dart';
import 'package:givt_app/shared/models/analytics_event.dart';
import 'package:givt_app/shared/models/color_combo.dart';
import 'package:givt_app/shared/widgets/common_icons.dart';

class ParentAmountPage extends StatefulWidget {
Expand All @@ -32,7 +32,7 @@ class ParentAmountPage extends StatefulWidget {
}

class _ParentAmountPageState extends State<ParentAmountPage> {
final initialamount = 5;
final initialamount = 25;
late int _amount;
@override
void initState() {
Expand Down
Loading

0 comments on commit eea74b2

Please sign in to comment.