mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: improve confirm deletion dialog
This commit is contained in:
parent
38f49d617f
commit
59b36f67c8
@ -19,6 +19,7 @@ import 'package:flowy_infra_ui/style_widget/hover.dart';
|
||||
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SpacePermissionSwitch extends StatefulWidget {
|
||||
@ -222,7 +223,7 @@ class SpaceCancelOrConfirmButton extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class ConfirmDeletionPopup extends StatelessWidget {
|
||||
class ConfirmDeletionPopup extends StatefulWidget {
|
||||
const ConfirmDeletionPopup({
|
||||
super.key,
|
||||
required this.title,
|
||||
@ -234,50 +235,67 @@ class ConfirmDeletionPopup extends StatelessWidget {
|
||||
final String description;
|
||||
final VoidCallback onConfirm;
|
||||
|
||||
@override
|
||||
State<ConfirmDeletionPopup> createState() => _ConfirmDeletionPopupState();
|
||||
}
|
||||
|
||||
class _ConfirmDeletionPopupState extends State<ConfirmDeletionPopup> {
|
||||
final focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 20.0,
|
||||
horizontal: 20.0,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
FlowyText(
|
||||
title,
|
||||
fontSize: 14.0,
|
||||
),
|
||||
const Spacer(),
|
||||
FlowyButton(
|
||||
useIntrinsicWidth: true,
|
||||
text: const FlowySvg(FlowySvgs.upgrade_close_s),
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
const VSpace(8.0),
|
||||
FlowyText.regular(
|
||||
description,
|
||||
fontSize: 12.0,
|
||||
color: Theme.of(context).hintColor,
|
||||
maxLines: 3,
|
||||
lineHeight: 1.4,
|
||||
),
|
||||
const VSpace(20.0),
|
||||
SpaceCancelOrConfirmButton(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () {
|
||||
onConfirm();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmButtonName: LocaleKeys.space_delete.tr(),
|
||||
confirmButtonColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
],
|
||||
return KeyboardListener(
|
||||
focusNode: focusNode,
|
||||
autofocus: true,
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 20.0,
|
||||
horizontal: 20.0,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
FlowyText(
|
||||
widget.title,
|
||||
fontSize: 14.0,
|
||||
),
|
||||
const Spacer(),
|
||||
FlowyButton(
|
||||
useIntrinsicWidth: true,
|
||||
text: const FlowySvg(FlowySvgs.upgrade_close_s),
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
const VSpace(8.0),
|
||||
FlowyText.regular(
|
||||
widget.description,
|
||||
fontSize: 12.0,
|
||||
color: Theme.of(context).hintColor,
|
||||
maxLines: 3,
|
||||
lineHeight: 1.4,
|
||||
),
|
||||
const VSpace(20.0),
|
||||
SpaceCancelOrConfirmButton(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () {
|
||||
widget.onConfirm();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmButtonName: LocaleKeys.space_delete.tr(),
|
||||
confirmButtonColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -227,31 +227,14 @@ class _SidebarSpaceHeaderState extends State<SidebarSpaceHeader> {
|
||||
|
||||
void _showDeleteSpaceDialog(BuildContext context) {
|
||||
final spaceBloc = context.read<SpaceBloc>();
|
||||
showDialog(
|
||||
final space = spaceBloc.state.currentSpace;
|
||||
final name = space != null ? space.name : '';
|
||||
showConfirmDeletionDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
final space = spaceBloc.state.currentSpace;
|
||||
final name = space != null ? space.name : '';
|
||||
final title = LocaleKeys.space_deleteConfirmation.tr() + name;
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
child: BlocProvider.value(
|
||||
value: spaceBloc,
|
||||
child: SizedBox(
|
||||
width: 440,
|
||||
child: ConfirmDeletionPopup(
|
||||
title: title,
|
||||
description:
|
||||
LocaleKeys.space_deleteConfirmationDescription.tr(),
|
||||
onConfirm: () {
|
||||
context.read<SpaceBloc>().add(const SpaceEvent.delete(null));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
name: name,
|
||||
description: LocaleKeys.space_deleteConfirmationDescription.tr(),
|
||||
onConfirm: () {
|
||||
context.read<SpaceBloc>().add(const SpaceEvent.delete(null));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -105,14 +105,16 @@ class _WorkspaceMoreActionWrapper extends CustomActionCell {
|
||||
case WorkspaceMoreAction.divider:
|
||||
break;
|
||||
case WorkspaceMoreAction.delete:
|
||||
await NavigatorAlertDialog(
|
||||
title: LocaleKeys.workspace_deleteWorkspaceHintText.tr(),
|
||||
confirm: () {
|
||||
await showConfirmDeletionDialog(
|
||||
context: context,
|
||||
name: workspace.name,
|
||||
description: LocaleKeys.workspace_deleteWorkspaceHintText.tr(),
|
||||
onConfirm: () {
|
||||
workspaceBloc.add(
|
||||
UserWorkspaceEvent.deleteWorkspace(workspace.workspaceId),
|
||||
);
|
||||
},
|
||||
).show(context);
|
||||
);
|
||||
case WorkspaceMoreAction.rename:
|
||||
await NavigatorTextFieldDialog(
|
||||
title: LocaleKeys.workspace_renameWorkspace.tr(),
|
||||
|
@ -14,7 +14,6 @@ import 'package:appflowy/workspace/application/view/view_ext.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/draggable_view_item.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_add_button.dart';
|
||||
@ -726,7 +725,14 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
views.map((e) => ViewBackendService.getPublishInfo(e)),
|
||||
).then((value) => value.where((e) => e.isSuccess));
|
||||
if (containPublishedPage.isNotEmpty && context.mounted) {
|
||||
_showDeleteDialog(context);
|
||||
await showConfirmDeletionDialog(
|
||||
context: context,
|
||||
name: widget.view.name,
|
||||
description: LocaleKeys.publish_containsPublishedPage.tr(),
|
||||
onConfirm: () {
|
||||
context.read<ViewBloc>().add(const ViewEvent.delete());
|
||||
},
|
||||
);
|
||||
} else if (context.mounted) {
|
||||
context.read<ViewBloc>().add(const ViewEvent.delete());
|
||||
}
|
||||
@ -790,30 +796,6 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
}
|
||||
return LocaleKeys.newPageText.tr();
|
||||
}
|
||||
|
||||
void _showDeleteDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 440,
|
||||
child: ConfirmDeletionPopup(
|
||||
title:
|
||||
LocaleKeys.space_deleteConfirmation.tr() + widget.view.name,
|
||||
description: LocaleKeys.publish_containsPublishedPage.tr(),
|
||||
onConfirm: () {
|
||||
context.read<ViewBloc>().add(const ViewEvent.delete());
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DotIconWidget extends StatelessWidget {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/startup/tasks/app_widget.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/size.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
@ -300,3 +301,30 @@ void showToastNotification(
|
||||
showProgressBar: false,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showConfirmDeletionDialog({
|
||||
required BuildContext context,
|
||||
required String name,
|
||||
required String description,
|
||||
required VoidCallback onConfirm,
|
||||
}) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
final title = LocaleKeys.space_deleteConfirmation.tr() + name;
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 440,
|
||||
child: ConfirmDeletionPopup(
|
||||
title: title,
|
||||
description: description,
|
||||
onConfirm: onConfirm,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@
|
||||
"reachOut": "Reach out on Discord"
|
||||
},
|
||||
"menuTitle": "Workspaces",
|
||||
"deleteWorkspaceHintText": "Are you sure you want to delete the workspace? This action cannot be undone.",
|
||||
"deleteWorkspaceHintText": "Are you sure you want to delete the workspace? This action cannot be undone, and any pages you have published will be unpublished.",
|
||||
"createSuccess": "Workspace created successfully",
|
||||
"createFailed": "Failed to create workspace",
|
||||
"createLimitExceeded": "You've reached the maximum workspace limit allowed for your account. If you need additional workspaces to continue your work, please request on Github",
|
||||
@ -439,7 +439,7 @@
|
||||
},
|
||||
"deleteWorkspacePrompt": {
|
||||
"title": "Delete workspace",
|
||||
"content": "Are you sure you want to delete this workspace? This action cannot be undone."
|
||||
"content": "Are you sure you want to delete this workspace? This action cannot be undone, and any pages you have published will be unpublished."
|
||||
},
|
||||
"leaveWorkspacePrompt": {
|
||||
"title": "Leave workspace",
|
||||
@ -2008,7 +2008,7 @@
|
||||
"space": {
|
||||
"delete": "Delete",
|
||||
"deleteConfirmation": "Delete: ",
|
||||
"deleteConfirmationDescription": "All pages within this Space will be deleted and moved to Trash.",
|
||||
"deleteConfirmationDescription": "All pages within this Space will be deleted and moved to the Trash, and any published pages will be unpublished.",
|
||||
"rename": "Rename Space",
|
||||
"changeIcon": "Change icon",
|
||||
"manage": "Manage Space",
|
||||
|
Loading…
Reference in New Issue
Block a user