mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Merge branch 'dev' of https://github.com/SyncrowIOT/web into SP-1720-FE-Draw-AssignTagsToSpace-Dialog
This commit is contained in:
@ -1,24 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/bloc/communities_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/communities/domain/models/community_model.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/create_community_dialog.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/presentation/edit_community_dialog.dart';
|
||||
|
||||
abstract final class SpaceManagementCommunityDialogHelper {
|
||||
static void showCreateDialog(BuildContext context) {
|
||||
static void showCreateDialog(BuildContext context) => showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const CreateCommunityDialog(),
|
||||
);
|
||||
|
||||
static void showEditDialog(
|
||||
BuildContext context,
|
||||
CommunityModel community,
|
||||
) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => CreateCommunityDialog(
|
||||
title: const SelectableText('Community Name'),
|
||||
onCreateCommunity: (community) {
|
||||
context.read<CommunitiesBloc>().add(
|
||||
InsertCommunity(community),
|
||||
);
|
||||
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||
SelectCommunityEvent(community: community),
|
||||
);
|
||||
},
|
||||
builder: (_) => EditCommunityDialog(
|
||||
community: community,
|
||||
parentContext: context,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static void showLoadingDialog(BuildContext context) => showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
|
||||
static void showSuccessSnackBar(BuildContext context, String message) =>
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,28 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/bloc/create_community_bloc.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/create_community_name_text_field.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class CreateCommunityDialogWidget extends StatefulWidget {
|
||||
class CommunityDialog extends StatefulWidget {
|
||||
final String? initialName;
|
||||
final Widget title;
|
||||
final void Function(String name) onSubmit;
|
||||
final String? errorMessage;
|
||||
|
||||
const CreateCommunityDialogWidget({
|
||||
super.key,
|
||||
const CommunityDialog({
|
||||
required this.title,
|
||||
required this.onSubmit,
|
||||
this.initialName,
|
||||
this.errorMessage,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CreateCommunityDialogWidget> createState() =>
|
||||
_CreateCommunityDialogWidgetState();
|
||||
State<CommunityDialog> createState() => _CommunityDialogState();
|
||||
}
|
||||
|
||||
class _CreateCommunityDialogWidgetState extends State<CreateCommunityDialogWidget> {
|
||||
class _CommunityDialogState extends State<CommunityDialog> {
|
||||
late final TextEditingController _nameController;
|
||||
|
||||
@override
|
||||
@ -63,35 +64,20 @@ class _CreateCommunityDialogWidgetState extends State<CreateCommunityDialogWidge
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: SingleChildScrollView(
|
||||
child: BlocBuilder<CreateCommunityBloc, CreateCommunityState>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DefaultTextStyle(
|
||||
style: Theme.of(context).textTheme.headlineMedium!,
|
||||
child: widget.title,
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
CreateCommunityNameTextField(
|
||||
nameController: _nameController,
|
||||
),
|
||||
if (state case CreateCommunityFailure(:final message))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 18),
|
||||
child: SelectableText(
|
||||
'* $message',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_buildActionButtons(context),
|
||||
],
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DefaultTextStyle(
|
||||
style: Theme.of(context).textTheme.headlineMedium!,
|
||||
child: widget.title,
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
CreateCommunityNameTextField(nameController: _nameController),
|
||||
_buildErrorMessage(),
|
||||
const SizedBox(height: 24),
|
||||
_buildActionButtons(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -132,13 +118,22 @@ class _CreateCommunityDialogWidgetState extends State<CreateCommunityDialogWidge
|
||||
|
||||
void _onSubmit(BuildContext context) {
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
context.read<CreateCommunityBloc>().add(
|
||||
CreateCommunity(
|
||||
CreateCommunityParam(
|
||||
name: _nameController.text.trim(),
|
||||
),
|
||||
),
|
||||
);
|
||||
widget.onSubmit.call(_nameController.text.trim());
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildErrorMessage() {
|
||||
return Visibility(
|
||||
visible: widget.errorMessage != null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.symmetric(vertical: 18),
|
||||
child: SelectableText(
|
||||
'* ${widget.errorMessage}',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: context.theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import 'package:syncrow_web/pages/space_management_v2/modules/communities/presen
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/data/services/remote_products_service.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/presentation/bloc/products_bloc.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/data/services/remote_space_details_service.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/data/services/unique_subspaces_decorator.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/bloc/space_details_bloc.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
||||
@ -32,7 +33,9 @@ class SpaceManagementPage extends StatelessWidget {
|
||||
BlocProvider(create: (context) => CommunitiesTreeSelectionBloc()),
|
||||
BlocProvider(
|
||||
create: (context) => SpaceDetailsBloc(
|
||||
RemoteSpaceDetailsService(httpService: HTTPService()),
|
||||
UniqueSubspacesDecorator(
|
||||
RemoteSpaceDetailsService(httpService: HTTPService()),
|
||||
),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
|
@ -1,9 +1,9 @@
|
||||
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/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/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/create_community_dialog.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/constants/assets.dart';
|
||||
@ -44,18 +44,6 @@ class CommunityStructureHeader extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _showCreateCommunityDialog(BuildContext context) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => CreateCommunityDialog(
|
||||
title: const Text('Edit Community'),
|
||||
onCreateCommunity: (community) {
|
||||
// TODO(FarisArmoush): Implement
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommunityInfo(
|
||||
BuildContext context, ThemeData theme, double screenWidth) {
|
||||
final selectedCommunity =
|
||||
@ -86,7 +74,12 @@ class CommunityStructureHeader extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
GestureDetector(
|
||||
onTap: () => _showCreateCommunityDialog(context),
|
||||
onTap: () {
|
||||
SpaceManagementCommunityDialogHelper.showEditDialog(
|
||||
context,
|
||||
selectedCommunity,
|
||||
);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconEdit,
|
||||
width: 16,
|
||||
|
@ -39,6 +39,26 @@ class CommunityModel extends Equatable {
|
||||
.toList();
|
||||
}
|
||||
|
||||
CommunityModel copyWith({
|
||||
String? uuid,
|
||||
String? name,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
String? description,
|
||||
String? externalId,
|
||||
List<SpaceModel>? spaces,
|
||||
}) {
|
||||
return CommunityModel(
|
||||
uuid: uuid ?? this.uuid,
|
||||
name: name ?? this.name,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
description: description ?? this.description,
|
||||
externalId: externalId ?? this.externalId,
|
||||
spaces: spaces ?? this.spaces,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [uuid, name, spaces];
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
on<LoadCommunities>(_onLoadCommunities);
|
||||
on<LoadMoreCommunities>(_onLoadMoreCommunities);
|
||||
on<InsertCommunity>(_onInsertCommunity);
|
||||
on<CommunitiesUpdateCommunity>(_onCommunitiesUpdateCommunity);
|
||||
}
|
||||
|
||||
final CommunitiesService _communitiesService;
|
||||
@ -114,4 +115,18 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
) {
|
||||
emit(state.copyWith(communities: [event.community, ...state.communities]));
|
||||
}
|
||||
|
||||
void _onCommunitiesUpdateCommunity(
|
||||
CommunitiesUpdateCommunity event,
|
||||
Emitter<CommunitiesState> emit,
|
||||
) {
|
||||
final updatedCommunities = state.communities
|
||||
.map((e) => e.uuid == event.community.uuid ? event.community : e)
|
||||
.toList();
|
||||
emit(
|
||||
state.copyWith(
|
||||
communities: updatedCommunities,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -31,3 +31,12 @@ final class InsertCommunity extends CommunitiesEvent {
|
||||
@override
|
||||
List<Object?> get props => [community];
|
||||
}
|
||||
|
||||
final class CommunitiesUpdateCommunity extends CommunitiesEvent {
|
||||
const CommunitiesUpdateCommunity(this.community);
|
||||
|
||||
final CommunityModel community;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [community];
|
||||
}
|
||||
|
@ -1,57 +1,58 @@
|
||||
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/main_module/shared/helpers/space_management_community_dialog_helper.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/widgets/community_dialog.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/bloc/communities_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/create_community/data/services/remote_create_community_service.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/bloc/create_community_bloc.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/create_community_dialog_widget.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
|
||||
class CreateCommunityDialog extends StatelessWidget {
|
||||
final void Function(CommunityModel community) onCreateCommunity;
|
||||
final String? initialName;
|
||||
final Widget title;
|
||||
|
||||
const CreateCommunityDialog({
|
||||
super.key,
|
||||
required this.onCreateCommunity,
|
||||
required this.title,
|
||||
this.initialName,
|
||||
});
|
||||
const CreateCommunityDialog({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => CreateCommunityBloc(RemoteCreateCommunityService(HTTPService())),
|
||||
child: BlocListener<CreateCommunityBloc, CreateCommunityState>(
|
||||
create: (_) => CreateCommunityBloc(
|
||||
RemoteCreateCommunityService(HTTPService()),
|
||||
),
|
||||
child: BlocConsumer<CreateCommunityBloc, CreateCommunityState>(
|
||||
listener: (context, state) {
|
||||
switch (state) {
|
||||
case CreateCommunityLoading():
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
case CreateCommunityLoading() || CreateCommunityInitial():
|
||||
SpaceManagementCommunityDialogHelper.showLoadingDialog(context);
|
||||
break;
|
||||
case CreateCommunitySuccess(:final community):
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Community created successfully')),
|
||||
SpaceManagementCommunityDialogHelper.showSuccessSnackBar(
|
||||
context,
|
||||
'${community.name} community created successfully',
|
||||
);
|
||||
onCreateCommunity.call(community);
|
||||
context.read<CommunitiesBloc>().add(
|
||||
InsertCommunity(community),
|
||||
);
|
||||
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||
SelectCommunityEvent(community: community),
|
||||
);
|
||||
break;
|
||||
case CreateCommunityFailure():
|
||||
Navigator.of(context).pop();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
child: CreateCommunityDialogWidget(
|
||||
title: title,
|
||||
initialName: initialName,
|
||||
),
|
||||
builder: (BuildContext context, CreateCommunityState state) {
|
||||
return CommunityDialog(
|
||||
title: const Text('Create Community'),
|
||||
initialName: null,
|
||||
onSubmit: (name) => context.read<CreateCommunityBloc>().add(
|
||||
CreateCommunity(CreateCommunityParam(name: name)),
|
||||
),
|
||||
errorMessage: state is CreateCommunityFailure ? state.message : null,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_space_details_param.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/services/space_details_service.dart';
|
||||
|
||||
class UniqueSubspacesDecorator implements SpaceDetailsService {
|
||||
final SpaceDetailsService _decoratee;
|
||||
|
||||
const UniqueSubspacesDecorator(this._decoratee);
|
||||
|
||||
@override
|
||||
Future<SpaceDetailsModel> getSpaceDetails(LoadSpaceDetailsParam param) async {
|
||||
final response = await _decoratee.getSpaceDetails(param);
|
||||
|
||||
final uniqueSubspaces = <String, Subspace>{};
|
||||
|
||||
for (final subspace in response.subspaces) {
|
||||
final normalizedName = subspace.name.trim().toLowerCase();
|
||||
if (!uniqueSubspaces.containsKey(normalizedName)) {
|
||||
uniqueSubspaces[normalizedName] = subspace;
|
||||
}
|
||||
}
|
||||
|
||||
return response.copyWith(
|
||||
subspaces: uniqueSubspaces.values.toList(),
|
||||
);
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ abstract final class SpaceDetailsDialogHelper {
|
||||
),
|
||||
child: SpaceDetailsDialog(
|
||||
context: context,
|
||||
title: const Text('Create Space'),
|
||||
title: const SelectableText('Create Space'),
|
||||
spaceModel: SpaceModel.empty(),
|
||||
onSave: print,
|
||||
),
|
||||
@ -36,7 +36,7 @@ abstract final class SpaceDetailsDialogHelper {
|
||||
),
|
||||
child: SpaceDetailsDialog(
|
||||
context: context,
|
||||
title: const Text('Edit Space'),
|
||||
title: const SelectableText('Edit Space'),
|
||||
spaceModel: spaceModel,
|
||||
onSave: (space) {},
|
||||
),
|
||||
|
@ -78,7 +78,11 @@ class _SpaceDetailsDialogState extends State<SpaceDetailsDialog> {
|
||||
return AlertDialog(
|
||||
title: widget.title,
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
content: const Center(child: CircularProgressIndicator()),
|
||||
content: SizedBox(
|
||||
height: context.screenHeight * 0.3,
|
||||
width: context.screenWidth * 0.5,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class SpaceDetailsForm extends StatelessWidget {
|
||||
create: (context) => SpaceDetailsModelBloc(initialState: space),
|
||||
child: BlocBuilder<SpaceDetailsModelBloc, SpaceDetailsModel>(
|
||||
buildWhen: (previous, current) => previous != current,
|
||||
builder: (context, state) {
|
||||
builder: (context, space) {
|
||||
return AlertDialog(
|
||||
title: title,
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
@ -39,7 +39,7 @@ class SpaceDetailsForm extends StatelessWidget {
|
||||
spacing: 20,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: SpaceIconPicker(iconPath: state.icon)),
|
||||
Expanded(child: SpaceIconPicker(iconPath: space.icon)),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
@ -47,17 +47,17 @@ class SpaceDetailsForm extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SpaceNameTextField(
|
||||
initialValue: state.spaceName,
|
||||
isNameFieldExist: (value) => state.subspaces.any(
|
||||
initialValue: space.spaceName,
|
||||
isNameFieldExist: (value) => space.subspaces.any(
|
||||
(subspace) => subspace.name == value,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
SpaceSubSpacesBox(
|
||||
subspaces: state.subspaces,
|
||||
subspaces: space.subspaces,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SpaceDetailsDevicesBox(space: state),
|
||||
SpaceDetailsDevicesBox(space: space),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -66,7 +66,7 @@ class SpaceDetailsForm extends StatelessWidget {
|
||||
),
|
||||
actions: [
|
||||
SpaceDetailsActionButtons(
|
||||
onSave: () => onSave(state),
|
||||
onSave: () => onSave(space),
|
||||
onCancel: Navigator.of(context).pop,
|
||||
),
|
||||
],
|
||||
|
@ -56,8 +56,9 @@ class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Create Sub Spaces'),
|
||||
title: const SelectableText('Create Sub Spaces'),
|
||||
content: Column(
|
||||
spacing: 12,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SubSpacesInput(
|
||||
@ -70,7 +71,7 @@ class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
||||
child: Visibility(
|
||||
key: ValueKey(_hasDuplicateNames),
|
||||
visible: _hasDuplicateNames,
|
||||
child: const Text(
|
||||
child: const SelectableText(
|
||||
'Error: Duplicate subspace names are not allowed.',
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.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/update_community/domain/params/update_community_param.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
@ -13,15 +13,15 @@ class RemoteUpdateCommunityService implements UpdateCommunityService {
|
||||
static const _defaultErrorMessage = 'Failed to update community';
|
||||
|
||||
@override
|
||||
Future<CommunityModel> updateCommunity(UpdateCommunityParam param) async {
|
||||
Future<CommunityModel> updateCommunity(CommunityModel param) async {
|
||||
final endpoint = await _makeUrl(param.uuid);
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: 'endpoint',
|
||||
expectedResponseModel: (data) => CommunityModel.fromJson(
|
||||
data as Map<String, dynamic>,
|
||||
),
|
||||
await _httpService.put(
|
||||
path: endpoint,
|
||||
body: {'name': param.name},
|
||||
expectedResponseModel: (data) => null,
|
||||
);
|
||||
return response;
|
||||
return param;
|
||||
} on DioException catch (e) {
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
@ -36,4 +36,12 @@ class RemoteUpdateCommunityService implements UpdateCommunityService {
|
||||
throw APIException(formattedErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _makeUrl(String communityUuid) async {
|
||||
final projectUuid = await ProjectManager.getProjectUUID();
|
||||
if (projectUuid == null) {
|
||||
throw APIException('Project UUID is not set');
|
||||
}
|
||||
return '/projects/$projectUuid/communities/$communityUuid';
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class UpdateCommunityParam extends Equatable {
|
||||
const UpdateCommunityParam({required this.name});
|
||||
|
||||
final String name;
|
||||
|
||||
@override
|
||||
List<Object> get props => [name];
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
||||
|
||||
abstract class UpdateCommunityService {
|
||||
Future<CommunityModel> updateCommunity(UpdateCommunityParam param);
|
||||
Future<CommunityModel> updateCommunity(CommunityModel community);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.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/update_community/domain/params/update_community_param.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
|
||||
@ -24,7 +23,7 @@ class UpdateCommunityBloc extends Bloc<UpdateCommunityEvent, UpdateCommunityStat
|
||||
emit(UpdateCommunityLoading());
|
||||
try {
|
||||
final updatedCommunity = await _updateCommunityService.updateCommunity(
|
||||
event.param,
|
||||
event.communityModel,
|
||||
);
|
||||
emit(UpdateCommunitySuccess(updatedCommunity));
|
||||
} on APIException catch (e) {
|
||||
|
@ -8,10 +8,10 @@ sealed class UpdateCommunityEvent extends Equatable {
|
||||
}
|
||||
|
||||
final class UpdateCommunity extends UpdateCommunityEvent {
|
||||
const UpdateCommunity(this.param);
|
||||
const UpdateCommunity(this.communityModel);
|
||||
|
||||
final UpdateCommunityParam param;
|
||||
final CommunityModel communityModel ;
|
||||
|
||||
@override
|
||||
List<Object> get props => [param];
|
||||
List<Object> get props => [communityModel];
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ final class UpdateCommunitySuccess extends UpdateCommunityState {
|
||||
}
|
||||
|
||||
final class UpdateCommunityFailure extends UpdateCommunityState {
|
||||
final String message;
|
||||
final String errorMessage;
|
||||
|
||||
const UpdateCommunityFailure(this.message);
|
||||
const UpdateCommunityFailure(this.errorMessage);
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
List<Object> get props => [errorMessage];
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/widgets/community_dialog.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/presentation/bloc/communities_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/update_community/data/services/remote_update_community_service.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/presentation/bloc/update_community_bloc.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
|
||||
class EditCommunityDialog extends StatelessWidget {
|
||||
const EditCommunityDialog({
|
||||
required this.community,
|
||||
required this.parentContext,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final CommunityModel community;
|
||||
final BuildContext parentContext;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => UpdateCommunityBloc(
|
||||
RemoteUpdateCommunityService(HTTPService()),
|
||||
),
|
||||
child: BlocConsumer<UpdateCommunityBloc, UpdateCommunityState>(
|
||||
listener: (context, state) {
|
||||
switch (state) {
|
||||
case UpdateCommunityInitial() || UpdateCommunityLoading():
|
||||
SpaceManagementCommunityDialogHelper.showLoadingDialog(context);
|
||||
break;
|
||||
case UpdateCommunitySuccess(:final community):
|
||||
_onUpdateCommunitySuccess(context, community);
|
||||
break;
|
||||
case UpdateCommunityFailure():
|
||||
Navigator.of(context).pop();
|
||||
break;
|
||||
}
|
||||
},
|
||||
builder: (context, state) => CommunityDialog(
|
||||
title: const Text('Edit Community'),
|
||||
initialName: community.name,
|
||||
errorMessage: state is UpdateCommunityFailure ? state.errorMessage : null,
|
||||
onSubmit: (name) => context.read<UpdateCommunityBloc>().add(
|
||||
UpdateCommunity(community.copyWith(name: name)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onUpdateCommunitySuccess(
|
||||
BuildContext context,
|
||||
CommunityModel community,
|
||||
) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
SpaceManagementCommunityDialogHelper.showSuccessSnackBar(
|
||||
context,
|
||||
'${community.name} community updated successfully',
|
||||
);
|
||||
parentContext.read<CommunitiesBloc>().add(
|
||||
CommunitiesUpdateCommunity(community),
|
||||
);
|
||||
parentContext.read<CommunitiesTreeSelectionBloc>().add(
|
||||
SelectCommunityEvent(community: community),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user