Route to code_success screen on code applied

This commit is contained in:
Neeraj Gupta 2023-02-23 10:08:09 +05:30
parent 3d96e73ad0
commit 8661b4dd45
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 27 additions and 8 deletions

View file

@ -1,6 +1,8 @@
import "package:flutter/material.dart";
import "package:logging/logging.dart";
import "package:photos/extensions/input_formatter.dart";
import "package:photos/models/api/storage_bonus/storage_bonus.dart";
import "package:photos/models/user_details.dart";
import "package:photos/services/storage_bonus_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/button_widget.dart";
@ -8,10 +10,18 @@ import "package:photos/ui/components/icon_button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/components/title_bar_title_widget.dart";
import "package:photos/ui/components/title_bar_widget.dart";
import "package:photos/ui/growth/code_success_screen.dart";
import "package:photos/utils/dialog_util.dart";
class ApplyCodeScreen extends StatefulWidget {
const ApplyCodeScreen({super.key});
// referrerView and userDetails used to render code_success_screen
final ReferralView referralView;
final UserDetails userDetails;
const ApplyCodeScreen(
this.referralView,
this.userDetails, {
super.key,
});
@override
State<ApplyCodeScreen> createState() => _ApplyCodeScreenState();
@ -112,14 +122,22 @@ class _ApplyCodeScreenState extends State<ApplyCodeScreen> {
await StorageBonusService.instance
.getGateway()
.claimReferralCode(code.trim().toUpperCase());
Navigator.of(context).pop();
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => CodeSuccessScreen(
widget.referralView,
widget.userDetails,
),
),
);
} catch (e) {
Logger('$runtimeType')
.severe("failed to apply referral", e);
showErrorDialogForException(
context: context,
exception: e as Exception,
);
context: context,
exception: e as Exception,
apiErrorPrefix: "Failed to apply code");
}
},
)

View file

@ -216,7 +216,7 @@ class ReferralWidget extends StatelessWidget {
onTap: () async {
await routeToPage(
context,
const ApplyCodeScreen(),
ApplyCodeScreen(referralView, userDetails),
);
notifyParent();
},

View file

@ -43,14 +43,15 @@ Future<ButtonResult?> showErrorDialogForException({
required BuildContext context,
required Exception exception,
bool isDismissible = true,
String apiErrorPrefix = "It looks like something went wrong.",
}) async {
String errorMessage =
"It looks like something went wrong. Please retry after some time. If the error persists, please contact our support team.";
if (exception is DioError &&
exception.response != null &&
exception.response!.data["code"] != null) {
errorMessage = "It looks like something went wrong. \n\nReason: " +
exception.response!.data["code"];
errorMessage =
"$apiErrorPrefix\n\nReason: " + exception.response!.data["code"];
}
return showDialogWidget(
context: context,