Skip to content

Commit

Permalink
Merge pull request #1085 from givtnl/feature/kids-1421-create-donatio…
Browse files Browse the repository at this point in the history
…n-flow

Feature: Create donation flow (kids-1421)
  • Loading branch information
Daniela510 authored Sep 23, 2024
2 parents 9afdc9a + 997a416 commit 411262f
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 109 deletions.
2 changes: 2 additions & 0 deletions lib/core/enums/amplitude_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ enum AmplitudeEvents {
familyReflectSummaryQuestionsAskedClicked(
'family_reflect_summary_questions_asked_clicked',
),
parentReflectionFlowOrganisationClicked(
'parent_reflection_flow_organisation_clicked'),
familyReflectSummaryGenerousDeedsClicked(
'family_reflect_summary_generous_deeds_clicked',
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ChooseAmountSliderPage extends StatefulWidget {

class _ChooseAmountSliderPageState extends State<ChooseAmountSliderPage> {
bool _isLoading = false;

final give = getIt<GiveBloc>();
String _createAssignmentDescription(String organisationName, double amount) {
final intAmount = amount.toInt();
return 'You gave $intAmount dollar${intAmount > 1 ? 's' : ''} to the $organisationName. Awesome!';
Expand All @@ -52,6 +52,7 @@ class _ChooseAmountSliderPageState extends State<ChooseAmountSliderPage> {
CreateChallengeDonationState>(
builder: (context, state) {
return BlocListener<GiveBloc, GiveState>(
bloc: give,
listener: (context, giveState) async {
if (giveState.status == GiveStatus.processed) {
_setLoading(false);
Expand Down Expand Up @@ -186,7 +187,7 @@ class _ChooseAmountSliderPageState extends State<ChooseAmountSliderPage> {
final decodedMediumId =
utf8.decode(base64.decode(widget.organisation.mediumId!));

context.read<GiveBloc>()
give
..add(
GiveAmountChanged(
firstCollectionAmount: state.amount,
Expand All @@ -211,7 +212,7 @@ class _ChooseAmountSliderPageState extends State<ChooseAmountSliderPage> {
if (e is StripeException && e.error.code == FailureCode.Canceled) {
// do nothing
} else {
context.read<GiveBloc>().add(const GiveStripeRegistrationError());
give.add(const GiveStripeRegistrationError());
LoggingInfo.instance.info(
e.toString(),
methodName: stackTrace.toString(),
Expand Down
26 changes: 1 addition & 25 deletions lib/features/family/app/family_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import 'package:givt_app/features/family/features/impact_groups/cubit/impact_gro
import 'package:givt_app/features/family/features/impact_groups/model/goal.dart';
import 'package:givt_app/features/family/features/impact_groups/model/impact_group.dart';
import 'package:givt_app/features/family/features/impact_groups/pages/impact_group_details_page.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/give_from_list_page.dart';
import 'package:givt_app/features/family/features/parent_giving_flow/presentation/pages/parent_giving_page.dart';
import 'package:givt_app/features/family/features/profiles/cubit/profiles_cubit.dart';
Expand All @@ -73,7 +72,6 @@ import 'package:givt_app/features/family/features/recommendation/tags/cubit/tags
import 'package:givt_app/features/family/features/recommendation/tags/screens/location_selection_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/reflect_intro_screen.dart';
import 'package:givt_app/features/family/features/scan_nfc/nfc_scan_screen.dart';
import 'package:givt_app/features/give/bloc/give/give_bloc.dart';
import 'package:givt_app/features/give/models/organisation.dart';
import 'package:givt_app/features/permit_biometric/cubit/permit_biometric_cubit.dart';
import 'package:givt_app/features/permit_biometric/models/permit_biometric_request.dart';
Expand Down Expand Up @@ -222,14 +220,6 @@ class FamilyAppRoutes {

return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => GiveBloc(
getIt(),
getIt(),
getIt(),
getIt(),
),
),
BlocProvider(
create: (context) => CreateChallengeDonationCubit(),
),
Expand Down Expand Up @@ -286,17 +276,6 @@ class FamilyAppRoutes {
final user = context.read<AuthCubit>().state.user;
return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => GiveBloc(
getIt(),
getIt(),
getIt(),
getIt(),
),
),
BlocProvider(
create: (_) => MediumCubit(),
),
BlocProvider(
create: (_) => OrganisationBloc(
getIt(),
Expand All @@ -316,10 +295,7 @@ class FamilyAppRoutes {
GoRoute(
path: FamilyPages.parentGive.path,
name: FamilyPages.parentGive.name,
builder: (context, state) => BlocProvider.value(
value: state.extra! as GiveBloc,
child: const ParentGivingPage(),
),
builder: (context, state) => const ParentGivingPage(),
),
GoRoute(
path: FamilyPages.wallet.path,
Expand Down
11 changes: 11 additions & 0 deletions lib/features/family/app/injection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:givt_app/features/family/features/giving_flow/collectgroup_detai
import 'package:givt_app/features/family/features/giving_flow/create_transaction/repositories/create_transaction_repository.dart';
import 'package:givt_app/features/family/features/history/history_repository/history_repository.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/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';
import 'package:givt_app/features/family/features/recommendation/organisations/repositories/organisations_repository.dart';
Expand All @@ -22,6 +23,7 @@ import 'package:givt_app/features/family/features/reflect/domain/grateful_recomm
import 'package:givt_app/features/family/features/reflect/domain/reflect_and_share_repository.dart';
import 'package:givt_app/features/family/helpers/svg_manager.dart';
import 'package:givt_app/features/family/network/api_service.dart';
import 'package:givt_app/features/give/bloc/bloc.dart';

final getIt = GetIt.instance;

Expand Down Expand Up @@ -53,6 +55,15 @@ void initCubits() {
..registerLazySingleton<CameraCubit>(
CameraCubit.new,
)
..registerLazySingleton<MediumCubit>(MediumCubit.new)
..registerLazySingleton<GiveBloc>(
() => GiveBloc(
getIt(),
getIt(),
getIt(),
getIt(),
),
)
..registerFactory<FamilyRolesCubit>(
() => FamilyRolesCubit(
getIt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:givt_app/app/injection/injection.dart';
import 'package:givt_app/core/enums/amplitude_events.dart';
import 'package:givt_app/core/enums/collect_group_type.dart';
import 'package:givt_app/features/auth/cubit/auth_cubit.dart';
Expand All @@ -23,22 +24,22 @@ class GiveFromListPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final locals = context.l10n;

final give = getIt<GiveBloc>();
return BlocConsumer<GiveBloc, GiveState>(
bloc: give,
listener: (context, state) {
final userGUID = context.read<AuthCubit>().state.user.guid;
if (state.status == GiveStatus.success) {
context.read<GiveBloc>().add(
GiveOrganisationSelected(
nameSpace: context.read<MediumCubit>().state.mediumId,
userGUID: userGUID,
),
);
give.add(
GiveOrganisationSelected(
nameSpace: getIt<MediumCubit>().state.mediumId,
userGUID: userGUID,
),
);
}
if (state.status == GiveStatus.readyToGive) {
context.pushReplacementNamed(
FamilyPages.parentGive.name,
extra: context.read<GiveBloc>(),
);
}
if (state.status == GiveStatus.error) {
Expand Down Expand Up @@ -73,7 +74,7 @@ class GiveFromListPage extends StatelessWidget {
},
),
);
context.read<MediumCubit>().setMediumId(collectGroup.nameSpace);
getIt<MediumCubit>().setMediumId(collectGroup.nameSpace);
final dynamic result = await Navigator.push(
context,
ParentAmountPage(
Expand All @@ -94,13 +95,13 @@ class GiveFromListPage extends StatelessWidget {
},
),
);
context.read<GiveBloc>().add(
GiveAmountChanged(
firstCollectionAmount: result.toDouble(),
secondCollectionAmount: 0,
thirdCollectionAmount: 0,
),
);
getIt<GiveBloc>().add(
GiveAmountChanged(
firstCollectionAmount: result.toDouble(),
secondCollectionAmount: 0,
thirdCollectionAmount: 0,
),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ class _ParentAmountPageState extends State<ParentAmountPage> {
),
),
),
floatingActionButton: FunButton(
onTap: () {
Navigator.of(context).pop(_amount);
},
text: 'Give',
analyticsEvent: AnalyticsEvent(
AmplitudeEvents.parentGiveClicked,
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: FunButton(
onTap: () {
Navigator.of(context).pop(_amount);
},
text: 'Give',
analyticsEvent: AnalyticsEvent(
AmplitudeEvents.parentGiveClicked,
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ParentGivingPage extends StatefulWidget {
class _ParentGivingPageState extends State<ParentGivingPage> {
late CustomInAppBrowser _customInAppBrowser;
bool browserIsOpened = false;
final give = getIt<GiveBloc>();

@override
void initState() {
Expand Down Expand Up @@ -63,8 +64,7 @@ class _ParentGivingPageState extends State<ParentGivingPage> {
context.read<ImpactGroupsCubit>().fetchImpactGroups(),
);

final afterGivingRedirection =
context.read<GiveBloc>().state.afterGivingRedirection;
final afterGivingRedirection = give.state.afterGivingRedirection;
context.pop();

if (afterGivingRedirection.isNotEmpty) {
Expand All @@ -82,28 +82,27 @@ class _ParentGivingPageState extends State<ParentGivingPage> {
Map<String, dynamic> _buildGivt(
BuildContext context,
) {
final giveBlocState = context.read<GiveBloc>().state;
final user = context.read<AuthCubit>().state.user;
final format = NumberFormat.simpleCurrency(
name: giveBlocState.organisation.currency,
name: give.state.organisation.currency,
);
var orgName = giveBlocState.organisation.organisationName!;
final instanceName = giveBlocState.instanceName;
if (giveBlocState.instanceName.isNotEmpty && instanceName != orgName) {
var orgName = give.state.organisation.organisationName!;
final instanceName = give.state.instanceName;
if (give.state.instanceName.isNotEmpty && instanceName != orgName) {
orgName = '$orgName: $instanceName';
}
return WebViewInput(
currency: format.currencySymbol,
apiUrl: Uri.https(getIt<RequestHelper>().apiURL).toString(),
guid: user.guid,
organisation: orgName,
givtObj: GivtTransaction.toJsonList(giveBlocState.givtTransactions),
givtObj: GivtTransaction.toJsonList(give.state.givtTransactions),
confirmBtn: context.l10n.next,
cancel: context.l10n.cancel,
areYouSureToCancelGivts: context.l10n.areYouSureToCancelGivts,
message: context.l10n.safariGivtTransaction,
thanks: context.l10n.givtIsBeingProcessed(
giveBlocState.organisation.organisationName.toString(),
give.state.organisation.organisationName.toString(),
),
yesSuccess: context.l10n.yesSuccess,
close: context.l10n.close,
Expand Down
12 changes: 10 additions & 2 deletions lib/features/family/features/reflect/bloc/grateful_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class GratefulCubit extends CommonCubit<GratefulUIModel, GratefulCustom> {
_profiles
..sort((a, b) => a.isChild ? -1 : 1)
..removeWhere(
(element) => !element.isChild || element.gratitude == null,
); //in the future we don't need to remove the adults
(element) => element.gratitude == null,
);

if (_profiles.isEmpty) {
_onEveryoneDonated();
Expand Down Expand Up @@ -123,6 +123,14 @@ class GratefulCubit extends CommonCubit<GratefulUIModel, GratefulCustom> {
}
}

Future<void> onParentDonated(String userId) async {
final parent = _profiles.firstWhere(
(e) => e.userId == userId,
orElse: () => throw Exception('Parent profile not found for userId: $userId'),
);
await onDonated(parent);
}

Future<void> onDonated(GameProfile profile) async {
_reflectAndShareRepository.incrementGenerousDeeds();
_profilesThatDonated.add(profile);
Expand Down
Loading

0 comments on commit 411262f

Please sign in to comment.