Frontend first draft
This commit is contained in:
15
frontend/pweb/lib/app/router/page_params.dart
Normal file
15
frontend/pweb/lib/app/router/page_params.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
enum PageParams {
|
||||
token,
|
||||
projectRef,
|
||||
roleRef,
|
||||
taskRef,
|
||||
invitationRef,
|
||||
}
|
||||
|
||||
String routerPageParam(PageParams param) {
|
||||
return ':${param.name}';
|
||||
}
|
||||
|
||||
String routerAddParam(PageParams param) {
|
||||
return '/${routerPageParam(param)}';
|
||||
}
|
||||
60
frontend/pweb/lib/app/router/pages.dart
Normal file
60
frontend/pweb/lib/app/router/pages.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
enum Pages {
|
||||
root,
|
||||
sfactor,
|
||||
login,
|
||||
methods,
|
||||
verify,
|
||||
signup,
|
||||
settings,
|
||||
dashboard,
|
||||
profile,
|
||||
recipients,
|
||||
users,
|
||||
roles,
|
||||
permissions,
|
||||
invitations,
|
||||
}
|
||||
|
||||
String routerPath(String page) {
|
||||
return '/$page';
|
||||
}
|
||||
|
||||
String routerPage(Pages page) {
|
||||
return page == Pages.root ? '/' : routerPath(page.name);
|
||||
}
|
||||
|
||||
String _pagePath(Pages page, {String? objectRef}) => _pagesPath([page], objectRef: objectRef);
|
||||
|
||||
String _pagesPath(List<Pages> pages, {String? objectRef}) {
|
||||
final path = pages.map(routerPage).join();
|
||||
return objectRef != null ? '$path/$objectRef' : path;
|
||||
}
|
||||
|
||||
void navigateAndReplace(BuildContext context, Pages page, {String? objectRef, Object? extra}) {
|
||||
context.go(_pagePath(page, objectRef: objectRef), extra: extra);
|
||||
}
|
||||
|
||||
void navigate(BuildContext context, Pages page, {String? objectRef, Object? extra}) {
|
||||
navigatePages(context, [page], objectRef: objectRef, extra: extra);
|
||||
}
|
||||
|
||||
void navigatePages(BuildContext context, List<Pages> pages, {String? objectRef, Object? extra}) {
|
||||
context.push(_pagesPath(pages, objectRef: objectRef), extra: extra);
|
||||
}
|
||||
|
||||
void navigateNamed(BuildContext context, Pages page, {String? objectRef, Object? extra}) {
|
||||
context.pushNamed(page.name, extra: extra);
|
||||
}
|
||||
|
||||
|
||||
void navigateNamedAndReplace(BuildContext context, Pages page, {String? objectRef, Object? extra}) {
|
||||
context.replaceNamed(page.name, extra: extra);
|
||||
}
|
||||
|
||||
void navigateNext(BuildContext context, Pages page, {Object? extra}) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => navigate(context, page, extra: extra));
|
||||
}
|
||||
57
frontend/pweb/lib/app/router/router.dart
Normal file
57
frontend/pweb/lib/app/router/router.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:pweb/app/router/pages.dart';
|
||||
import 'package:pweb/pages/2fa/page.dart';
|
||||
import 'package:pweb/pages/signup/page.dart';
|
||||
import 'package:pweb/widgets/sidebar/page.dart';
|
||||
import 'package:pweb/pages/login/page.dart';
|
||||
import 'package:pweb/pages/errors/not_found.dart';
|
||||
|
||||
GoRouter createRouter() => GoRouter(
|
||||
debugLogDiagnostics: true,
|
||||
routes: <RouteBase>[
|
||||
GoRoute(
|
||||
name: Pages.root.name,
|
||||
path: routerPage(Pages.root),
|
||||
builder: (_, __) => const LoginPage(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
name: Pages.login.name,
|
||||
path: routerPage(Pages.login),
|
||||
builder: (_, __) => const LoginPage(),
|
||||
),
|
||||
GoRoute(
|
||||
name: Pages.dashboard.name,
|
||||
path: routerPage(Pages.dashboard),
|
||||
builder: (_, __) => const PageSelector(),
|
||||
),
|
||||
GoRoute(
|
||||
name: Pages.sfactor.name,
|
||||
path: routerPage(Pages.sfactor),
|
||||
builder: (context, state) {
|
||||
// Определяем откуда пришел пользователь
|
||||
final isFromSignup = state.uri.queryParameters['from'] == 'signup';
|
||||
|
||||
return TwoFactorCodePage(
|
||||
onVerificationSuccess: () {
|
||||
if (isFromSignup) {
|
||||
// После регистрации -> на страницу логина
|
||||
context.goNamed(Pages.login.name);
|
||||
} else {
|
||||
// После логина -> на дашборд
|
||||
context.goNamed(Pages.dashboard.name);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
name: Pages.signup.name,
|
||||
path: routerPage(Pages.signup),
|
||||
builder: (_, __) => const SignUpPage(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
errorBuilder: (_, __) => const NotFoundPage(),
|
||||
);
|
||||
Reference in New Issue
Block a user