mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 16:54:56 +00:00
Implement delete space functionality in CommunityStructureHeader: Integrate DeleteSpaceDialog for space deletion confirmation and update routing for space management page.
This commit is contained in:
@ -4,6 +4,7 @@ import 'package:flutter_svg/svg.dart';
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart';
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/community_structure_header_action_buttons.dart';
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/community_structure_header_action_buttons.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/delete_space/presentation/widgets/delete_space_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/helpers/space_details_dialog_helper.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/helpers/space_details_dialog_helper.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
@ -91,7 +92,19 @@ class CommunityStructureHeader extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
CommunityStructureHeaderActionButtons(
|
CommunityStructureHeaderActionButtons(
|
||||||
onDelete: (space) {},
|
onDelete: (space) => showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (_) => DeleteSpaceDialog(
|
||||||
|
space: space,
|
||||||
|
community: selectedCommunity,
|
||||||
|
onSuccess: () {
|
||||||
|
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||||
|
SelectCommunityEvent(community: selectedCommunity),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
onDuplicate: (space) {},
|
onDuplicate: (space) {},
|
||||||
onEdit: (space) {
|
onEdit: (space) {
|
||||||
SpaceDetailsDialogHelper.showEdit(
|
SpaceDetailsDialogHelper.showEdit(
|
||||||
|
|||||||
@ -0,0 +1,118 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/delete_space/data/remote_delete_space_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/delete_space/presentation/bloc/delete_space_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/delete_space/presentation/widgets/delete_space_dialog_form.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
|
class DeleteSpaceDialog extends StatelessWidget {
|
||||||
|
const DeleteSpaceDialog({
|
||||||
|
required this.space,
|
||||||
|
required this.community,
|
||||||
|
required this.onSuccess,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final SpaceModel space;
|
||||||
|
final CommunityModel community;
|
||||||
|
final void Function() onSuccess;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) => DeleteSpaceBloc(
|
||||||
|
RemoteDeleteSpaceService(httpService: HTTPService()),
|
||||||
|
),
|
||||||
|
child: Builder(
|
||||||
|
builder: (context) => Dialog(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsetsDirectional.all(32),
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: context.screenWidth * 0.2,
|
||||||
|
),
|
||||||
|
child: BlocConsumer<DeleteSpaceBloc, DeleteSpaceState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state case DeleteSpaceSuccess()) onSuccess();
|
||||||
|
},
|
||||||
|
builder: (context, state) => switch (state) {
|
||||||
|
DeleteSpaceInitial() => DeleteSpaceDialogForm(
|
||||||
|
space: space,
|
||||||
|
communityUuid: community.uuid,
|
||||||
|
),
|
||||||
|
DeleteSpaceLoading() => const DeleteSpaceLoadingWidget(),
|
||||||
|
DeleteSpaceSuccess(:final successMessage) => DeleteSpaceStatusWidget(
|
||||||
|
message: successMessage,
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.check_circle,
|
||||||
|
size: 92,
|
||||||
|
color: ColorsManager.goodGreen,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DeleteSpaceFailure() => DeleteSpaceStatusWidget(
|
||||||
|
message: state.errorMessage,
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.error,
|
||||||
|
size: 92,
|
||||||
|
color: ColorsManager.red,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeleteSpaceLoadingWidget extends StatelessWidget {
|
||||||
|
const DeleteSpaceLoadingWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const SizedBox.square(
|
||||||
|
dimension: 32,
|
||||||
|
child: Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeleteSpaceStatusWidget extends StatelessWidget {
|
||||||
|
const DeleteSpaceStatusWidget({
|
||||||
|
required this.message,
|
||||||
|
required this.icon,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
final Widget icon;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
spacing: 16,
|
||||||
|
children: [
|
||||||
|
icon,
|
||||||
|
SelectableText(
|
||||||
|
message,
|
||||||
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
fontSize: 22,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: Navigator.of(context).pop,
|
||||||
|
child: const Text('Close'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/delete_space/domain/params/delete_space_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/delete_space/presentation/bloc/delete_space_bloc.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
|
class DeleteSpaceDialogForm extends StatelessWidget {
|
||||||
|
const DeleteSpaceDialogForm({
|
||||||
|
required this.space,
|
||||||
|
required this.communityUuid,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final SpaceModel space;
|
||||||
|
final String communityUuid;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(Assets.xDelete, width: 36, height: 36),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
SelectableText(
|
||||||
|
'Delete Space',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: context.textTheme.titleLarge?.copyWith(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SelectableText(
|
||||||
|
'Are you sure you want to delete this space? This action is irreversible',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: context.textTheme.bodyLarge?.copyWith(
|
||||||
|
color: ColorsManager.lightGreyColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: FilledButton(
|
||||||
|
style: _buildButtonStyle(
|
||||||
|
context,
|
||||||
|
color: ColorsManager.grey25,
|
||||||
|
textColor: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
onPressed: Navigator.of(context).pop,
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: FilledButton(
|
||||||
|
style: _buildButtonStyle(
|
||||||
|
context,
|
||||||
|
color: ColorsManager.semiTransparentRed,
|
||||||
|
textColor: ColorsManager.whiteColors,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
context.read<DeleteSpaceBloc>().add(
|
||||||
|
DeleteSpace(
|
||||||
|
DeleteSpaceParam(
|
||||||
|
spaceUuid: space.uuid,
|
||||||
|
communityUuid: communityUuid,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Delete'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonStyle _buildButtonStyle(
|
||||||
|
BuildContext context, {
|
||||||
|
required Color color,
|
||||||
|
required Color textColor,
|
||||||
|
}) {
|
||||||
|
return FilledButton.styleFrom(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
backgroundColor: color,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
foregroundColor: textColor,
|
||||||
|
textStyle: context.textTheme.bodyLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user