Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
✨ add onError and progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenautjoe committed Jun 5, 2019
1 parent ed16676 commit 947e1cd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
6 changes: 3 additions & 3 deletions assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"AUTH.CREATE_ACC.PASTE_LINK": "Paste your registration link below",
"AUTH.CREATE_ACC.PASTE_PASSWORD_RESET_LINK": "Paste your password reset link below",
"AUTH.CREATE_ACC.PASTE_LINK_HELP_TEXT": "Use the link from the Join Openbook button in your invitation email.",
"AUTH.CREATE_ACC.REQUEST_INVITE": "Need an invite? Request it here.",
"AUTH.CREATE_ACC.SUBSCRIBE": "Subscribe",
"AUTH.CREATE_ACC.SUBSCRIBE_TO_WAITLIST_TEXT": "Join the waitlist and get early access!",
"AUTH.CREATE_ACC.REQUEST_INVITE": "No invite? Request one here.",
"AUTH.CREATE_ACC.SUBSCRIBE": "Request",
"AUTH.CREATE_ACC.SUBSCRIBE_TO_WAITLIST_TEXT": "Request an invite!",
"AUTH.CREATE_ACC.CONGRATULATIONS": "Congratulations!",
"AUTH.CREATE_ACC.YOUR_SUBSCRIBED": "You're {0} on the waitlist.",
"AUTH.CREATE_ACC.ALMOST_THERE": "Almost there...",
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/waitlist/subscribe_done_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class OBWaitlistSubscribeDoneStepState extends State<OBWaitlistSubscribeDoneStep
}

Widget _buildNextButton({@required BuildContext context}) {
String buttonText =
localizationService.trans('AUTH.LOGIN.LOGIN');

return OBSuccessButton(
minWidth: double.infinity,
Expand All @@ -104,7 +102,7 @@ class OBWaitlistSubscribeDoneStepState extends State<OBWaitlistSubscribeDoneStep
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
buttonText,
'Done',
style: TextStyle(fontSize: 18.0),
)
],
Expand Down
54 changes: 44 additions & 10 deletions lib/pages/waitlist/subscribe_email_step.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:Openbook/pages/waitlist/subscribe_done_step.dart';
import 'package:Openbook/provider.dart';
import 'package:Openbook/services/localization.dart';
import 'package:Openbook/services/toast.dart';
import 'package:Openbook/services/user.dart';
import 'package:Openbook/services/validation.dart';
import 'package:Openbook/widgets/buttons/button.dart';
Expand All @@ -24,6 +25,7 @@ class OBWaitlistSubscribePageState extends State<OBWaitlistSubscribePage> {
UserService _userService;
LocalizationService _localizationService;
ValidationService _validationService;
ToastService _toastService;

TextEditingController _emailController = TextEditingController();

Expand All @@ -41,6 +43,7 @@ class OBWaitlistSubscribePageState extends State<OBWaitlistSubscribePage> {
_localizationService = openbookProvider.localizationService;
_validationService = openbookProvider.validationService;
_userService = openbookProvider.userService;
_toastService = openbookProvider.toastService;

return Scaffold(
body: Center(
Expand Down Expand Up @@ -84,12 +87,24 @@ class OBWaitlistSubscribePageState extends State<OBWaitlistSubscribePage> {
}

void onPressedNextStep(BuildContext context) async {
if (_subscribeInProgress) return;
_isSubmitted = true;
bool isEmailValid = _validateForm();
if (isEmailValid) {
int count = await _userService.subscribeToBetaWaitlist(email: _emailController.text);
WaitlistSubscribeArguments args = new WaitlistSubscribeArguments(count: count);
Navigator.pushNamed(context, '/waitlist/subscribe_done_step', arguments: args);

if (!isEmailValid) return;

_setSubscribeInProgress(true);
try {
int count = await _userService.subscribeToBetaWaitlist(
email: _emailController.text);
WaitlistSubscribeArguments args =
new WaitlistSubscribeArguments(count: count);
Navigator.pushNamed(context, '/waitlist/subscribe_done_step',
arguments: args);
} catch (error) {
_onError(error);
} finally {
_setSubscribeInProgress(false);
}
}

Expand Down Expand Up @@ -135,8 +150,8 @@ class OBWaitlistSubscribePageState extends State<OBWaitlistSubscribePage> {
}

Widget _buildSubscribeEmailText({@required BuildContext context}) {
String subscribeEmailText =
_localizationService.trans('AUTH.CREATE_ACC.SUBSCRIBE_TO_WAITLIST_TEXT');
String subscribeEmailText = _localizationService
.trans('AUTH.CREATE_ACC.SUBSCRIBE_TO_WAITLIST_TEXT');

return Column(
children: <Widget>[
Expand All @@ -159,7 +174,7 @@ class OBWaitlistSubscribePageState extends State<OBWaitlistSubscribePage> {

Widget _buildEmailForm() {
String emailInputPlaceholder =
_localizationService.trans('AUTH.CREATE_ACC.EMAIL_PLACEHOLDER');
_localizationService.trans('AUTH.CREATE_ACC.EMAIL_PLACEHOLDER');

return Form(
key: _formKey,
Expand All @@ -171,14 +186,33 @@ class OBWaitlistSubscribePageState extends State<OBWaitlistSubscribePage> {
autocorrect: false,
hintText: emailInputPlaceholder,
validator: (String email) {
String validateEMail = _validationService.validateUserEmail(email);
String validateEMail =
_validationService.validateUserEmail(email);
if (validateEMail != null) return validateEMail;
},
controller: _emailController,
)
),
)),
),
]),
);
}

void _onError(error) async {
if (error is HttpieConnectionRefusedError) {
_toastService.error(
message: error.toHumanReadableMessage(), context: context);
} else if (error is HttpieRequestError) {
String errorMessage = await error.toHumanReadableMessage();
_toastService.error(message: errorMessage, context: context);
} else {
_toastService.error(message: 'Unknown error', context: context);
throw error;
}
}

void _setSubscribeInProgress(subscribeInProgress) {
setState(() {
_subscribeInProgress = subscribeInProgress;
});
}
}

0 comments on commit 947e1cd

Please sign in to comment.