Skip to content

Commit

Permalink
handle invite parent case
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikelStuivenberg committed Nov 13, 2024
1 parent 7af399a commit be30ca5
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/features/family/app/injection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void initCubits() {
() => FamilyLoginCubit(getIt()),
)
..registerFactory<UsSignupCubit>(
() => UsSignupCubit(getIt()),
() => UsSignupCubit(getIt(), getIt()),
)
..registerFactory<SplashCubit>(
() => SplashCubit(getIt(), getIt()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class NavigationBarHomeCubit
}

Future<void> _onProfilesChanged(List<Profile> profiles) async {
_familyInviteGroup = await _impactGroupsRepository.isInvitedToGroup();
_profiles = profiles;
unawaited(_getProfilePictureUrl());
await doInitialChecks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:givt_app/core/enums/country.dart';
import 'package:givt_app/features/family/features/auth/data/family_auth_repository.dart';
import 'package:givt_app/features/family/features/registration/cubit/us_signup_custom.dart';
import 'package:givt_app/features/impact_groups/repo/impact_groups_repository.dart';
import 'package:givt_app/shared/bloc/base_state.dart';
import 'package:givt_app/shared/bloc/common_cubit.dart';
import 'package:givt_app/shared/models/temp_user.dart';
Expand All @@ -10,16 +11,17 @@ import 'package:givt_app/utils/util.dart';

class UsSignupCubit extends CommonCubit<UserExt, UsSignupCustom> {
UsSignupCubit(
FamilyAuthRepository authRepository,
) : _authRepository = authRepository,
super(const BaseState.loading());
this._authRepository,
this._impactGroupsRepository,
) : super(const BaseState.loading());

final FamilyAuthRepository _authRepository;
final ImpactGroupsRepository _impactGroupsRepository;

Future<void> init() async {
try {
await _authRepository.refreshToken();
} catch (e, s) {
} catch (_) {
// do nothing, failing is fine
}
final user = _authRepository.getCurrentUser();
Expand Down Expand Up @@ -71,7 +73,14 @@ class UsSignupCubit extends CommonCubit<UserExt, UsSignupCustom> {
isNewUser: false,
);

emitCustom(const UsSignupCustomSuccess());
final invitedGroup = await _impactGroupsRepository.isInvitedToGroup();

if (invitedGroup != null) {
emitCustom(const UsSignupRedirectToHome());
return;
}

emitCustom(const UsSignupRedirectToAddMembers());
} catch (e) {
emitSnackbarMessage(e.toString(), isError: true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
sealed class UsSignupCustom {
const UsSignupCustom();

const factory UsSignupCustom.succes() = UsSignupCustomSuccess;
const factory UsSignupCustom.redirectToAddMembers() =
UsSignupRedirectToAddMembers;
const factory UsSignupCustom.redirectToHome() =
UsSignupRedirectToHome;
}

class UsSignupCustomSuccess extends UsSignupCustom {
const UsSignupCustomSuccess();
class UsSignupRedirectToAddMembers extends UsSignupCustom {
const UsSignupRedirectToAddMembers();
}

class UsSignupRedirectToHome extends UsSignupCustom {
const UsSignupRedirectToHome();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:givt_app/core/enums/enums.dart';
import 'package:givt_app/features/children/utils/add_member_util.dart';
import 'package:givt_app/features/family/app/family_pages.dart';
import 'package:givt_app/features/family/app/injection.dart';
import 'package:givt_app/features/family/features/avatars/cubit/avatars_cubit.dart';
import 'package:givt_app/features/family/features/registration/cubit/us_signup_cubit.dart';
Expand All @@ -28,6 +29,7 @@ import 'package:givt_app/shared/widgets/outlined_text_form_field.dart';
import 'package:givt_app/utils/analytics_helper.dart';
import 'package:givt_app/utils/app_theme.dart';
import 'package:givt_app/utils/util.dart';
import 'package:go_router/go_router.dart';

class UsSignUpPage extends StatefulWidget {
const UsSignUpPage({
Expand Down Expand Up @@ -149,8 +151,10 @@ class _UsSignUpPageState extends State<UsSignUpPage> {

void handleCustom(BuildContext context, UsSignupCustom custom) {
switch (custom) {
case UsSignupCustomSuccess():
case UsSignupRedirectToAddMembers():
AddMemberUtil.addFamilyPushPages(context);
case UsSignupRedirectToHome():
context.goNamed(FamilyPages.profileSelection.name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:givt_app/features/impact_groups/cubit/impact_groups_cubit.dart';
import 'package:givt_app/features/impact_groups/models/impact_group.dart';
import 'package:givt_app/l10n/l10n.dart';
import 'package:givt_app/shared/models/analytics_event.dart';
import 'package:givt_app/shared/widgets/fun_scaffold.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';

Expand All @@ -20,41 +21,36 @@ class ImpactGroupReceiveInviteSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 32, 24, 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${context.l10n.youHaveBeenInvitedToImpactGroup}${invitdImpactGroup.name}',
textAlign: TextAlign.center,
style: GoogleFonts.mulish(
textStyle: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w700,
),
),
),
SvgPicture.asset('assets/images/family_superheroes.svg'),
FunButton(
text: context.l10n.acceptInviteKey,
onTap: () {
context
.read<ImpactGroupsCubit>()
.acceptGroupInvite(groupId: invitdImpactGroup.id);
context.pop();
},
analyticsEvent: AnalyticsEvent(
AmplitudeEvents.inviteToImpactGroupAccepted,
parameters: {
'group_name': invitdImpactGroup.name,
},
),
),
],
return FunScaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${context.l10n.youHaveBeenInvitedToImpactGroup}${invitdImpactGroup.name}',
textAlign: TextAlign.center,
style: GoogleFonts.mulish(
textStyle: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w700,
),
),
),
),
SvgPicture.asset('assets/images/family_superheroes.svg'),
FunButton(
text: context.l10n.acceptInviteKey,
onTap: () {
context
.read<ImpactGroupsCubit>()
.acceptGroupInvite(groupId: invitdImpactGroup.id);
context.pop();
},
analyticsEvent: AnalyticsEvent(
AmplitudeEvents.inviteToImpactGroupAccepted,
parameters: {
'group_name': invitdImpactGroup.name,
},
),
),
],
),
);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/features/splash/cubit/splash_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import 'package:givt_app/shared/bloc/common_cubit.dart';

class SplashCubit extends CommonCubit<void, SplashCustom> {
SplashCubit(
FamilyAuthRepository authRepository,
ProfilesRepository profilesRepository,
) : _authRepository = authRepository,
_profilesRepository = profilesRepository,
super(const BaseState.loading());
this._authRepository,
this._profilesRepository,
) : super(const BaseState.loading());

final FamilyAuthRepository _authRepository;
final ProfilesRepository _profilesRepository;
Expand Down

0 comments on commit be30ca5

Please sign in to comment.