Email Confirmation and refactor for snackbar
This commit is contained in:
@@ -1,21 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/pages/status/page.dart';
|
||||
import 'package:pweb/services/verification.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/provider/email_verification.dart';
|
||||
import 'package:pshared/widgets/locale.dart';
|
||||
|
||||
import 'package:pweb/app/router/pages.dart';
|
||||
import 'package:pweb/pages/errors/error.dart';
|
||||
import 'package:pweb/pages/status/success.dart';
|
||||
import 'package:pweb/pages/with_footer.dart';
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class AccountVerificationPage extends StatelessWidget {
|
||||
class AccountVerificationPage extends StatefulWidget {
|
||||
final String token;
|
||||
|
||||
const AccountVerificationPage({super.key, required this.token});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => StatusPage<bool>(
|
||||
operation: () async => VerificationService.verify(token),
|
||||
errorMessage: AppLocalizations.of(context)!.accountVerificationFailed,
|
||||
successMessage: AppLocalizations.of(context)!.accountVerified,
|
||||
successDescription: AppLocalizations.of(context)!.accountVerifiedDescription,
|
||||
);
|
||||
State<AccountVerificationPage> createState() => _AccountVerificationPageState();
|
||||
}
|
||||
|
||||
class _AccountVerificationPageState extends State<AccountVerificationPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
context.read<EmailVerificationProvider>().verify(widget.token);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const _AccountVerificationContent();
|
||||
}
|
||||
}
|
||||
|
||||
class _AccountVerificationContent extends StatelessWidget {
|
||||
const _AccountVerificationContent();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final locs = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<EmailVerificationProvider>();
|
||||
final action = OutlinedButton.icon(
|
||||
onPressed: () => navigateAndReplace(context, Pages.login),
|
||||
icon: const Icon(Icons.login),
|
||||
label: Text(locs.login),
|
||||
);
|
||||
|
||||
Widget content;
|
||||
if (provider.isLoading) {
|
||||
content = const Center(child: CircularProgressIndicator());
|
||||
} else if (provider.isSuccess) {
|
||||
content = StatusPageSuccess(
|
||||
successMessage: locs.accountVerified,
|
||||
successDescription: locs.accountVerifiedDescription,
|
||||
action: action,
|
||||
);
|
||||
} else {
|
||||
content = exceptionToErrorPage(
|
||||
context: context,
|
||||
title: locs.verificationFailed,
|
||||
errorMessage: locs.accountVerificationFailed,
|
||||
exception: provider.error ?? Exception(locs.accountVerificationFailed),
|
||||
);
|
||||
}
|
||||
|
||||
return PageWithFooter(
|
||||
appBar: AppBar(
|
||||
title: Text(locs.verifyAccount),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
const LocaleChangerDropdown(
|
||||
availableLocales: AppLocalizations.supportedLocales,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user