Skip to content

Commit

Permalink
feat: new severe close confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Jun 13, 2024
1 parent cdcbca5 commit 9b66d33
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:reactive_forms/reactive_forms.dart';
import 'package:studyu_core/core.dart';
import 'package:studyu_designer_v2/common_views/async_value_widget.dart';
import 'package:studyu_designer_v2/common_views/dialog.dart';
import 'package:studyu_designer_v2/common_views/form_buttons.dart';
import 'package:studyu_designer_v2/common_views/primary_button.dart';
import 'package:studyu_designer_v2/features/study/settings/study_settings_form_controller.dart';
import 'package:studyu_designer_v2/features/study/study_controller.dart';
import 'package:studyu_designer_v2/features/study/study_page_view.dart';
import 'package:studyu_designer_v2/localization/app_translation.dart';
Expand All @@ -15,51 +15,62 @@ class CloseConfirmationDialog extends StudyPageWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final controller = ref.watch(studyControllerProvider(studyId).notifier);
final formViewModel =
ref.watch(studySettingsFormViewModelProvider(studyId));
final state = ref.watch(studyControllerProvider(studyId));
final formKey = GlobalKey<FormState>();
String? inputStudyName;

return ReactiveForm(
formGroup: formViewModel.form,
child: StandardDialog(
titleText: tr.dialog_study_close_title,
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
return AsyncValueWidget<Study>(
value: state.study,
data: (Study study) {
return StandardDialog(
titleText: tr.dialog_study_close_title,
body: Form(
key: formKey,
child: Column(
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(
text: tr.dialog_study_close_description,
),
),
],
Text(tr.dialog_study_close_description),
const SizedBox(height: 16.0),
SelectableText(
'Enter the title of the study "${study.title}" to confirm that you want to close it:',
),
const SizedBox(height: 16.0),
TextFormField(
decoration: const InputDecoration(
labelText: 'Title of the study to close',
),
validator: (value) {
if (value == null || value != study.title) {
return 'Study title does not match';
}
return null;
},
onSaved: (value) {
inputStudyName = value;
},
),
],
),
],
),
actionButtons: [
const DismissButton(),
ReactiveFormConsumer(
builder: (context, form, child) {
return PrimaryButton(
text: tr.dialog_close,
icon: null,
onPressedFuture: () => controller.closeStudy(),
);
},
),
],
maxWidth: 650,
minWidth: 610,
minHeight: 200,
),
actionButtons: [
const DismissButton(),
PrimaryButton(
text: tr.dialog_close,
icon: null,
onPressedFuture: () async {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
if (inputStudyName == study.title) {
await controller.closeStudy();
}
}
},
),
],
maxWidth: 650,
minWidth: 610,
minHeight: 200,
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class CloseSuccessDialog extends StudyPageWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);

return StandardDialog(
body: Column(
children: [
Expand All @@ -34,7 +33,7 @@ class CloseSuccessDialog extends StudyPageWidget {
),
actionButtons: [
PrimaryButton(
text: tr.action_button_study_close,
text: tr.dialog_close,
icon: null,
onPressedFuture: () => Navigator.maybePop(context),
),
Expand Down
8 changes: 7 additions & 1 deletion designer_v2/lib/features/study/study_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import 'package:studyu_designer_v2/theme.dart';
abstract class IStudyAppBarViewModel
implements IStudyStatusBadgeViewModel, IStudyNavViewModel {
bool get isSyncIndicatorVisible;

bool get isStatusBadgeVisible;

bool get isPublishVisible;

bool get isClosedVisible;
}

Expand Down Expand Up @@ -268,7 +271,10 @@ class _StudyScaffoldState extends ConsumerState<StudyScaffold> {
text: tr.action_button_study_close,
icon: null,
onPressed: () => showStudyDialog(
context, widget.studyId, StudyDialogType.close),
context,
widget.studyId,
StudyDialogType.close,
),
);
},
),
Expand Down
3 changes: 1 addition & 2 deletions designer_v2/lib/localization/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"phase_sequence_counterbalanced": "Ausgeglichen (AB BA)",
"phase_sequence_random": "Zufällig",
"phase_sequence_custom": "Benutzerdefiniert",

"form_enrollment_option_open": "Open",
"form_enrollment_option_invite": "Private (Invite-only)",
"@__________________NAV_DRAWER__________________": {},
Expand Down Expand Up @@ -123,7 +122,7 @@
"notification_study_closed": "Die Studie wurde geschlossen",
"notification_study_closed_description": "Neue Teilnehmer können sich nicht mehr einschreiben",
"dialog_study_close_title": "Teilnahme schließen?",
"dialog_study_close_description": "Bist du sicher, dass die Teilnahme an der Studie geschlossen werden soll? Es können keine neuen Teilnehmer mehr eingeschrieben werden, aber bereits angemeldete Teilnehmer können die Studie weiterhin durchführen.",
"dialog_study_close_description": "Bist du sicher, dass die Teilnahme an der Studie geschlossen werden soll? Dadurch können keine neuen Teilnehmer mehr aufgenommen werden. Bereits eingeschriebene Teilnehmer werden die Studie weiterhin durchführen können. Das Schließen einer Studie kann nicht rückgängig gemacht werden.",
"dialog_study_delete_title": "Dauerhaft löschen?",
"dialog_study_delete_description": "Bist du sicher, dass die Studie gelöscht werden soll? Die Studie und alle gesammelten Daten gehen dabei unwiderruflich verloren.",
"@__________________STUDYPAGE_DESIGN_SHARED__________________": {},
Expand Down
2 changes: 1 addition & 1 deletion designer_v2/lib/localization/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"notification_study_closed": "Study was closed",
"notification_study_closed_description": "New participants can no longer enroll in this study.",
"dialog_study_close_title": "Close participation?",
"dialog_study_close_description": "Are you sure that you want to stop new enrollments for this study? New participants can no longer join, but those who are already enrolled can still continue.",
"dialog_study_close_description": "Are you sure that you want to stop new enrollments for this study? New participants can no longer join, but those who are already enrolled can still continue. This action cannot be undone.",
"dialog_study_delete_title": "Permanently delete?",
"dialog_study_delete_description": "Are you sure you want to delete this study? You will permanently lose the study and all data that has been collected.",
"@__________________STUDYPAGE_DESIGN_SHARED__________________": {},
Expand Down

0 comments on commit 9b66d33

Please sign in to comment.