Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Cancel app creation button #67

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions lib/views/create_project_form.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:client_backoffice/navigation/backoffice_navigator.dart';
import 'package:client_common/models/auth_model.dart';
import 'package:client_common/models/user_application_model.dart';
import 'package:client_common/navigator/common_navigator.dart';
import 'package:client_common/views/loading_button.dart';
Expand All @@ -25,6 +26,7 @@ class _CreateProjectFormState extends State<CreateProjectForm> {
@override
Widget build(BuildContext context) {
bool isLoading = context.select<UserApplicationModel, bool>((m) => m.createApplicationStatus.isFetching());
bool userHasApp = context.read<UserApplicationModel>().userApps.isNotEmpty;
jonas-martinez marked this conversation as resolved.
Show resolved Hide resolved
return Form(
key: _formKey,
child: LenraFlex(
Expand All @@ -33,12 +35,18 @@ class _CreateProjectFormState extends State<CreateProjectForm> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
fields(context),
LoadingButton(
text: "Create my project",
loading: isLoading,
onPressed: () {
submit();
},
LenraFlex(
spacing: 16,
children: [
cancelButton(userHasApp),
jonas-martinez marked this conversation as resolved.
Show resolved Hide resolved
LoadingButton(
text: "Create my project",
loading: isLoading,
onPressed: () {
submit();
},
),
],
),
],
),
Expand Down Expand Up @@ -86,6 +94,30 @@ class _CreateProjectFormState extends State<CreateProjectForm> {
);
}

LenraButton cancelButton(bool hasApp) {
if (hasApp) {
return LenraButton(
text: "Cancel",
onPressed: () {
CommonNavigator.go(context, BackofficeNavigator.selectProject);
jonas-martinez marked this conversation as resolved.
Show resolved Hide resolved
},
type: LenraComponentType.secondary,
);
} else {
return LenraButton(
text: "Logout",
onPressed: () {
context.read<AuthModel>().logout().then((value) {
CommonNavigator.go(context, CommonNavigator.login);
}).catchError((error) {
logger.warning(error);
});
},
type: LenraComponentType.secondary,
);
}
}

void submit() {
if (_formKey.currentState!.validate()) {
context.read<UserApplicationModel>().createApp(projectName, gitRepository).then((app) {
Expand Down