Skip to content

Commit

Permalink
Join space with invitation code (#13)
Browse files Browse the repository at this point in the history
* temp

* join space with invitation code and get invitation of selected space

* live data streaming

* remove unwanted code

* stream member live data

* temp

* revert stream

* manage selection with id

* add snack bar error and show selected id always at 1st index

* show congratulation prompt on joining space
  • Loading branch information
cp-ishita-g authored Jun 5, 2024
1 parent dc2f32d commit 50d4a1b
Show file tree
Hide file tree
Showing 20 changed files with 1,080 additions and 238 deletions.
18 changes: 18 additions & 0 deletions app/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
"app_title": "YourSpace",
"app_tag_line": "Stay Close, Anywhere!",

"alert_confirm_default_title": "Are you sure",

"@_COMMON": {
},
"common_get_started": "Get Started",
"common_next": "Next",
"common_yes": "Yes",
"common_cancel": "Cancel",
"common_delete": "Delete",
"common_okay": "Okay",
"common_verify": "Verify","commonMembers": "{memberCount} {memberCount, plural, =1{Member} other{Members}}",
"@commonMembers": {
"placeholders": {
Expand Down Expand Up @@ -48,6 +54,7 @@
}
}
},
"home_select_space_text": "Select a space",

"create_space_give_your_space_name_title": "Give your space name",
"create_space_tip_text": "Tips: You create dedicated spaces for work, family, friends, and more.",
Expand All @@ -67,6 +74,17 @@
"join_space_title": "Join space",
"join_space_invite_code_title": "Enter the invite code",
"join_space_get_code_from_space_text": "Get the code from the space creator to join.",
"join_space_already_joined_error_text": "You are already member of this space",
"join_space_invalid_code_error_text": "It appears the code is no longer valid or has expired. please review and enter valid code.",
"join_space_congratulation_title": "Congratulation",
"join_space_congratulation_subtitle": "You’re are now member of {spaceName} group for sharing your real-time location.",
"@join_space_congratulation_subtitle": {
"placeholders": {
"spaceName": {
"type": "String"
}
}
},

"invite_code_title": "Invite code",
"invite_code_invite_member_title": "Invite members to the {spaceName}",
Expand Down
32 changes: 21 additions & 11 deletions app/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions app/lib/ui/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,8 @@ class AppRoute {
static AppRoute get createSpace =>
AppRoute(pathCreateSpace, builder: (_) => const CreateSpace());

static AppRoute joinSpace({
required String invitationCode, required String spaceName}) {
return AppRoute(
pathJoinSpace,
builder: (_) => JoinSpace(invitationCode: invitationCode, spaceName: spaceName),
);
}
static AppRoute get joinSpace =>
AppRoute(pathJoinSpace, builder: (_) => const JoinSpace());

static AppRoute inviteCode({
required String code, required String spaceName}) {
Expand Down
122 changes: 122 additions & 0 deletions app/lib/ui/components/alert.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:style/extenstions/context_extenstions.dart';
import 'package:yourspace_flutter/domain/extenstions/context_extenstions.dart';


Future<void> showConfirmation(
BuildContext context, {
String? title,
String? message,
String? confirmBtnText,
required VoidCallback onConfirm,
bool isDestructiveAction = true,
String? cancelButtonText,
VoidCallback? onCancel,
}) {
HapticFeedback.mediumImpact();
return showAdaptiveDialog(
context: context,
builder: (context) {
return AlertDialog.adaptive(
surfaceTintColor: context.colorScheme.containerNormalOnSurface,
title: (title != null) ? Text(title) : null,
content: Text(message ?? context.l10n.alert_confirm_default_title),
actions: [
adaptiveAction(
context: context,
onPressed: () async {
context.pop();
onCancel?.call();
},
child: Text(cancelButtonText ?? context.l10n.common_cancel),
),
adaptiveAction(
context: context,
isDestructiveAction: isDestructiveAction,
onPressed: () async {
context.pop();
onConfirm();
},
child: Text(
confirmBtnText ?? context.l10n.common_yes,
),
),
],
);
},
);
}

Future<void> showOkayConfirmation(
BuildContext context, {
required String title,
required String message,
bool isDestructiveAction = true,
VoidCallback? onOkay,
}) {
HapticFeedback.mediumImpact();
return showAdaptiveDialog(
context: context,
builder: (context) {
return AlertDialog.adaptive(
surfaceTintColor: context.colorScheme.containerNormalOnSurface,
title: Text(title),
content: Text(message),
actions: [
adaptiveAction(
context: context,
onPressed: () async {
context.pop();
onOkay?.call();
},
child: Text(context.l10n.common_okay),
),
],
);
},
);
}

Widget adaptiveAction({
required BuildContext context,
required VoidCallback onPressed,
required Widget child,
bool isDestructiveAction = false,
}) {
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return TextButton(
onPressed: onPressed,
child: DefaultTextStyle(
style: TextStyle(
inherit: true,
color: isDestructiveAction
? context.colorScheme.alert
: context.colorScheme.textSecondary,
),
child: child,
),
);
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return CupertinoDialogAction(
onPressed: onPressed,
isDestructiveAction: isDestructiveAction,
textStyle: isDestructiveAction
? null
: TextStyle(
color: isDestructiveAction
? context.colorScheme.textPrimary
: context.colorScheme.textSecondary,
),
child: child,
);
}
}
10 changes: 10 additions & 0 deletions app/lib/ui/components/error_snakebar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

void showErrorSnackBar(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Colors.red,
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:style/text/app_text_dart.dart';
import 'package:yourspace_flutter/domain/extenstions/context_extenstions.dart';
import 'package:yourspace_flutter/domain/extenstions/widget_extensions.dart';
import 'package:yourspace_flutter/ui/components/app_page.dart';
import 'package:yourspace_flutter/ui/components/error_snakebar.dart';
import 'package:yourspace_flutter/ui/flow/auth/sign_in/phone/verification/phone_verification_view_model.dart';

import '../../../../../components/app_logo.dart';
Expand Down Expand Up @@ -38,16 +39,6 @@ class _PhoneVerificationScreenState
super.initState();
}

void _navBackAfterVerification() {
ref.listen(
phoneVerificationStateProvider
.select((value) => value.verificationSucceed), (previous, next) {
if (next) {
context.pop([true, ref.read(phoneVerificationStateProvider).isNewUser]);
}
});
}

@override
void dispose() {
_otpController.dispose();
Expand All @@ -64,6 +55,7 @@ class _PhoneVerificationScreenState
);

_navBackAfterVerification();
_observeError();

return AppPage(
title: '',
Expand Down Expand Up @@ -178,4 +170,22 @@ class _PhoneVerificationScreenState
),
),
);

void _navBackAfterVerification() {
ref.listen(
phoneVerificationStateProvider
.select((value) => value.verificationSucceed), (previous, next) {
if (next) {
context.pop([true, ref.read(phoneVerificationStateProvider).isNewUser]);
}
});
}

void _observeError() {
ref.listen(phoneVerificationStateProvider.select((state) => state.error), (previous, next) {
if (next != null) {
showErrorSnackBar(context, next.toString());
}
});
}
}
11 changes: 11 additions & 0 deletions app/lib/ui/flow/auth/sign_in/sign_in_method_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:style/extenstions/context_extenstions.dart';
import 'package:yourspace_flutter/domain/extenstions/context_extenstions.dart';
import 'package:yourspace_flutter/ui/components/app_logo.dart';
import 'package:yourspace_flutter/ui/components/app_page.dart';
import 'package:yourspace_flutter/ui/components/error_snakebar.dart';
import 'package:yourspace_flutter/ui/flow/auth/sign_in/sign_in_method_viewmodel.dart';

import '../../../../gen/assets.gen.dart';
Expand All @@ -31,6 +32,8 @@ class _SignInMethodScreenState extends ConsumerState<SignInMethodScreen> {
@override
Widget build(BuildContext context) {
_listenSignInSuccess();
_observeError();

final bgDecoration = BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
Expand Down Expand Up @@ -115,4 +118,12 @@ class _SignInMethodScreenState extends ConsumerState<SignInMethodScreen> {
}
});
}

void _observeError() {
ref.listen(signInMethodsStateProvider.select((state) => state.error), (previous, next) {
if (next != null) {
showErrorSnackBar(context, next.toString());
}
});
}
}
Loading

0 comments on commit 50d4a1b

Please sign in to comment.