Skip to content

Commit

Permalink
refresh user once coming back from onboarding link
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlipa91 committed Nov 5, 2023
1 parent 8bfe40d commit 54a24e0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
14 changes: 5 additions & 9 deletions lib/screens/BottomBarMatch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:nutmeg/state/UserState.dart';
import 'package:nutmeg/utils/UiUtils.dart';
import 'package:nutmeg/utils/Utils.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../state/MatchesState.dart';
Expand Down Expand Up @@ -58,7 +57,8 @@ class BottomBarMatch extends StatelessWidget {
break;
case MatchStatus.unpublished:
if (match.organizerId == context.read<UserState>().currentUserId)
bottomBar = NotPublishedBottomBar(matchId: matchId);
bottomBar = NotPublishedBottomBar(matchId: matchId,
isTest: match.isTest);
}

return bottomBar;
Expand Down Expand Up @@ -211,24 +211,20 @@ class RatePlayersBottomBar extends StatelessWidget {

class NotPublishedBottomBar extends StatelessWidget {
final String matchId;
final bool isTest;

const NotPublishedBottomBar({Key? key, required this.matchId})
const NotPublishedBottomBar({Key? key, required this.matchId, required this.isTest})
: super(key: key);

@override
Widget build(BuildContext context) {
var userState = context.read<UserState>();

return BottomBarMatch(
matchId: matchId,
text: "Not Published",
subText:
"Complete your Stripe account to receive payments and publish this match",
button: InkWell(
onTap: () => launchUrl(
Uri.parse(getStripeUrl(
userState.isTestMode, userState.currentUserId!)),
mode: LaunchMode.externalApplication),
onTap: () => completeAccountAction(context, isTest, matchId: matchId),
child: Padding(
padding: EdgeInsets.only(top: 8),
child: Text("GO TO STRIPE", style: TextPalette.linkStyle))));
Expand Down
8 changes: 1 addition & 7 deletions lib/screens/UserPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -780,18 +780,12 @@ class CompleteOrganiserAccountWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
var userState = context.watch<UserState>();

return WarningWidget(
title: "Create your " + (this.isTest ? "Test " : "") + "Stripe account",
body:
"To start receiving payments, you need to create your Stripe account",
textAction: "GO TO STRIPE",
action: () async {
await launchUrl(
Uri.parse(getStripeUrl(isTest, userState.currentUserId!)),
mode: LaunchMode.externalApplication);
},
action: () => completeAccountAction(context, isTest),
);
}
}
51 changes: 32 additions & 19 deletions lib/utils/Utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:nutmeg/api/CloudFunctionsUtils.dart';
import 'package:nutmeg/model/Match.dart';
import 'package:nutmeg/state/MatchesState.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:share_plus/share_plus.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:version/version.dart';
import 'package:timezone/timezone.dart' as tz;

import '../state/UserState.dart';

String gmtSuffix(String timeZoneId) {
var hourOffset = tz.TZDateTime.from(DateTime.now(),
tz.getLocation(timeZoneId)).timeZoneOffset.inHours;
var hourOffset =
tz.TZDateTime.from(DateTime.now(), tz.getLocation(timeZoneId))
.timeZoneOffset
.inHours;
var gmtString = ((hourOffset > 0) ? "+" : "") + hourOffset.toString();
return "GMT$gmtString";
}
Expand All @@ -21,11 +27,9 @@ String formatCurrency(int cents) =>
NumberFormat.simpleCurrency(name: "EUR").format(cents / 100);

String formatEmail(String? email) {
if (email == null)
return "N/A";
if (email == null) return "N/A";
var parts = email.split("@");
if (parts.length > 1 && parts[1] == "privaterelay.appleid.com")
return "N/A";
if (parts.length > 1 && parts[1] == "privaterelay.appleid.com") return "N/A";
return email;
}

Expand All @@ -38,7 +42,8 @@ class DynamicLinks {
link = match.dynamicLink!;
else {
// todo slowly deprecate
var deepLinkUrl = Uri.parse('https://web.nutmegapp.com/match/' + match.documentId);
var deepLinkUrl =
Uri.parse('https://web.nutmegapp.com/match/' + match.documentId);

final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: 'https://nutmegapp.page.link',
Expand All @@ -55,12 +60,10 @@ class DynamicLinks {
// fallbackUrl: deepLinkUrl
),
socialMetaTagParameters: SocialMetaTagParameters(
title: "Match on ${dayDateFormat
.format(match.getLocalizedTime())} "
title: "Match on ${dayDateFormat.format(match.getLocalizedTime())} "
"${gmtSuffix(match.sportCenter.timezoneId)}",
description: "Location: ${match.sportCenter.name}",
)
);
));
var url = await FirebaseDynamicLinks.instance.buildShortLink(parameters);
link = url.shortUrl.toString();
}
Expand All @@ -75,10 +78,9 @@ DateTime getBeginningOfTheWeek(DateTime dateTime) {
return DateUtils.dateOnly(dateTime.subtract(Duration(days: currentDay - 1)));
}

List<T> interleave<T>(List<T> elements, T e, [bool withTop=false]) {
List<T> interleave<T>(List<T> elements, T e, [bool withTop = false]) {
List<T> result = [];
if (withTop)
result.add(e);
if (withTop) result.add(e);
elements.forEach((a) {
result.add(a);
result.add(e);
Expand All @@ -99,12 +101,23 @@ Future<Tuple2<Version, String>> getVersion() async {
}

class ConfigsUtils {
static bool removeCreditsFunctionality() => true;

static bool removeCreditsFunctionality() =>
true;
// FirebaseRemoteConfig.instance.getBool("remove_credit_functionality");
// FirebaseRemoteConfig.instance.getBool("remove_credit_functionality");
static bool feesOnOrganiser(String orgId) => false;
}

String getStripeUrl(bool isTest, String userId) =>
CloudFunctionsClient().getUrl("stripe/account/onboard?is_test=$isTest&user_id=$userId");
String getStripeUrl(bool isTest, String userId) => CloudFunctionsClient()
.getUrl("stripe/account/onboard?is_test=$isTest&user_id=$userId");

Future<void> completeAccountAction(BuildContext context, bool isTest,
{String? matchId}) async {
await launchUrl(
Uri.parse(getStripeUrl(isTest,
context.read<UserState>().getLoggedUserDetails()!.documentId)),
mode: LaunchMode.externalApplication);
await context.read<UserState>().fetchLoggedUserDetails();
if (matchId != null) {
await context.read<MatchesState>().fetchMatch(matchId);
}
}

0 comments on commit 54a24e0

Please sign in to comment.