Compare commits

...

6 Commits

Author SHA1 Message Date
b1b72fa8aa use DataCellWidget 2025-07-21 16:42:57 +03:00
e8576c8dbe remove comments 2025-07-21 16:40:46 +03:00
0c0f26bec7 param not params 2025-07-21 16:39:59 +03:00
dd425236f4 no need for (S) cuz it is not List 2025-07-21 16:39:07 +03:00
fb506e16c1 requested cubits 2025-07-21 16:37:46 +03:00
983040135f fix using copywith 2025-07-21 16:30:28 +03:00
23 changed files with 132 additions and 116 deletions

View File

@ -4,8 +4,7 @@ import 'package:syncrow_web/utils/color_manager.dart';
class SvgTextButton extends StatelessWidget { class SvgTextButton extends StatelessWidget {
final String svgAsset; final String svgAsset;
final double? horizontalPadding; final EdgeInsets? padding;
final double? verticalPadding;
final String label; final String label;
final VoidCallback onPressed; final VoidCallback onPressed;
final Color backgroundColor; final Color backgroundColor;
@ -27,8 +26,7 @@ class SvgTextButton extends StatelessWidget {
this.svgColor = const Color(0xFF496EFF), this.svgColor = const Color(0xFF496EFF),
this.labelColor = Colors.black, this.labelColor = Colors.black,
this.borderRadius = 10.0, this.borderRadius = 10.0,
this.horizontalPadding, this.padding,
this.verticalPadding,
this.boxShadow = const [ this.boxShadow = const [
BoxShadow( BoxShadow(
color: ColorsManager.lightGrayColor, color: ColorsManager.lightGrayColor,
@ -47,9 +45,8 @@ class SvgTextButton extends StatelessWidget {
borderRadius: BorderRadius.circular(borderRadius), borderRadius: BorderRadius.circular(borderRadius),
onTap: onPressed, onTap: onPressed,
child: Container( child: Container(
padding: EdgeInsets.symmetric( padding: padding ??
horizontal: horizontalPadding ?? 24, const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
vertical: verticalPadding ?? 12),
decoration: BoxDecoration( decoration: BoxDecoration(
color: backgroundColor, color: backgroundColor,
borderRadius: BorderRadius.circular(borderRadius), borderRadius: BorderRadius.circular(borderRadius),

View File

@ -13,7 +13,7 @@ class RemoteBookableSpacesService implements BookableSpacesService {
static const _defaultErrorMessage = 'Failed to load Bookable Spaces'; static const _defaultErrorMessage = 'Failed to load Bookable Spaces';
@override @override
Future<PaginatedDataModel<BookableSpacemodel>> load( Future<PaginatedDataModel<BookableSpacemodel>> load(
BookableSpacesParams param) async { BookableSpacesParam param) async {
try { try {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.bookableSpaces, path: ApiEndpoints.bookableSpaces,

View File

@ -1,6 +1,6 @@
class BookableSpacesParams { class BookableSpacesParam {
final int currentPage; final int currentPage;
BookableSpacesParams({ BookableSpacesParam({
required this.currentPage, required this.currentPage,
}); });

View File

@ -4,5 +4,5 @@ import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/
abstract class BookableSpacesService { abstract class BookableSpacesService {
Future<PaginatedDataModel<BookableSpacemodel>> load( Future<PaginatedDataModel<BookableSpacemodel>> load(
BookableSpacesParams param); BookableSpacesParam param);
} }

View File

@ -40,22 +40,25 @@ class BookableSpacesBloc
if (event.bookableSpace.spaceConfig!.configUuid == if (event.bookableSpace.spaceConfig!.configUuid ==
event.updatedBookableSpaceConfig.configUuid) { event.updatedBookableSpaceConfig.configUuid) {
final editedBookableSpace = event.bookableSpaces.data.firstWhere(
(element) => element.spaceUuid == event.bookableSpace.spaceUuid,
);
final config = editedBookableSpace.spaceConfig!.copyWith(
availability: event.updatedBookableSpaceConfig.availability,
bookableDays: event.updatedBookableSpaceConfig.bookableDays,
bookingEndTime: event.updatedBookableSpaceConfig.bookingEndTime,
bookingStartTime: event.updatedBookableSpaceConfig.bookingStartTime,
cost: event.updatedBookableSpaceConfig.cost,
);
editedBookableSpace.copyWith(spaceConfig: config);
final index = event.bookableSpaces.data.indexWhere( final index = event.bookableSpaces.data.indexWhere(
(element) => element.spaceUuid == event.bookableSpace.spaceUuid, (element) => element.spaceUuid == event.bookableSpace.spaceUuid,
); );
event.bookableSpaces.data.removeAt(index);
event.bookableSpaces.data.insert(index, editedBookableSpace); if (index != -1) {
final original = event.bookableSpaces.data[index];
final updatedConfig = original.spaceConfig!.copyWith(
availability: event.updatedBookableSpaceConfig.availability,
bookableDays: event.updatedBookableSpaceConfig.bookableDays,
bookingEndTime: event.updatedBookableSpaceConfig.bookingEndTime,
bookingStartTime: event.updatedBookableSpaceConfig.bookingStartTime,
cost: event.updatedBookableSpaceConfig.cost,
);
final updatedSpace = original.copyWith(spaceConfig: updatedConfig);
event.bookableSpaces.data[index] = updatedSpace;
}
} }
emit(BookableSpacesLoaded(bookableSpacesList: event.bookableSpaces)); emit(BookableSpacesLoaded(bookableSpacesList: event.bookableSpaces));

View File

@ -8,7 +8,7 @@ sealed class BookableSpacesEvent extends Equatable {
} }
class LoadBookableSpacesEvent extends BookableSpacesEvent { class LoadBookableSpacesEvent extends BookableSpacesEvent {
final BookableSpacesParams param; final BookableSpacesParam param;
const LoadBookableSpacesEvent(this.param); const LoadBookableSpacesEvent(this.param);
} }

View File

@ -4,7 +4,7 @@ import 'package:equatable/equatable.dart';
part 'steps_state.dart'; part 'steps_state.dart';
class StepsCubit extends Cubit<StepsState> { class StepsCubit extends Cubit<StepsState> {
StepsCubit() : super(StepsInitial()); StepsCubit() : super(StepOneState());
void initDialogValue() { void initDialogValue() {
emit(StepOneState()); emit(StepOneState());

View File

@ -7,9 +7,6 @@ sealed class StepsState extends Equatable {
List<Object> get props => []; List<Object> get props => [];
} }
final class StepsInitial extends StepsState {}
final class StepOneState extends StepsState {} final class StepOneState extends StepsState {}
final class StepTwoState extends StepsState {} final class StepTwoState extends StepsState {}

View File

@ -4,7 +4,7 @@ import 'package:equatable/equatable.dart';
part 'toggle_points_switch_state.dart'; part 'toggle_points_switch_state.dart';
class TogglePointsSwitchCubit extends Cubit<TogglePointsSwitchState> { class TogglePointsSwitchCubit extends Cubit<TogglePointsSwitchState> {
TogglePointsSwitchCubit() : super(TogglePointsSwitchInitial()); TogglePointsSwitchCubit() : super(UnActivatePointsSwitch());
void activateSwitch() { void activateSwitch() {
emit(ActivatePointsSwitch()); emit(ActivatePointsSwitch());

View File

@ -7,7 +7,6 @@ sealed class TogglePointsSwitchState extends Equatable {
List<Object> get props => []; List<Object> get props => [];
} }
final class TogglePointsSwitchInitial extends TogglePointsSwitchState {}
class ActivatePointsSwitch extends TogglePointsSwitchState {} class ActivatePointsSwitch extends TogglePointsSwitchState {}

View File

@ -18,10 +18,10 @@ class UpdateBookableSpacesBloc
Future<void> _onUpdateBookableSpace(UpdateBookableSpace event, Future<void> _onUpdateBookableSpace(UpdateBookableSpace event,
Emitter<UpdateBookableSpacesState> emit) async { Emitter<UpdateBookableSpacesState> emit) async {
emit(UpdateBookableSpaceLoading(event.updatedParams.spaceUuid)); emit(UpdateBookableSpaceLoading(event.updatedParam.spaceUuid));
try { try {
final updatedSpace = final updatedSpace =
await updateBookableSpaceService.update(event.updatedParams); await updateBookableSpaceService.update(event.updatedParam);
emit(UpdateBookableSpaceSuccess(bookableSpaceConfig: updatedSpace)); emit(UpdateBookableSpaceSuccess(bookableSpaceConfig: updatedSpace));
event.onSuccess?.call(); event.onSuccess?.call();

View File

@ -9,9 +9,9 @@ sealed class UpdateBookableSpaceEvent extends Equatable {
class UpdateBookableSpace extends UpdateBookableSpaceEvent { class UpdateBookableSpace extends UpdateBookableSpaceEvent {
final void Function()? onSuccess; final void Function()? onSuccess;
final UpdateBookableSpaceParam updatedParams; final UpdateBookableSpaceParam updatedParam;
const UpdateBookableSpace({ const UpdateBookableSpace({
required this.updatedParams, required this.updatedParam,
this.onSuccess, this.onSuccess,
}); });
} }

View File

@ -33,7 +33,7 @@ class _ManageBookableSpacesPageState extends State<ManageBookableSpacesPage> {
RemoteBookableSpacesService(HTTPService()), RemoteBookableSpacesService(HTTPService()),
)..add( )..add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: 1), BookableSpacesParam(currentPage: 1),
), ),
), ),
), ),

View File

@ -56,7 +56,7 @@ class BookableSpaceSwitchActivationWidget extends StatelessWidget {
onChanged: (value) { onChanged: (value) {
context.read<UpdateBookableSpacesBloc>().add( context.read<UpdateBookableSpacesBloc>().add(
UpdateBookableSpace( UpdateBookableSpace(
updatedParams: UpdateBookableSpaceParam( updatedParam: UpdateBookableSpaceParam(
spaceUuid: space.spaceUuid, spaceUuid: space.spaceUuid,
availability: value, availability: value,
)), )),

View File

@ -65,10 +65,21 @@ class BookingPeriodWidget extends StatelessWidget {
)); ));
throw Exception(); throw Exception();
} else { } else {
setupBookableSpacesBloc.selectedBookableSpaces.forEach( for (int i = 0;
(e) => i <
e.spaceConfig!.copyWith(bookingStartTime: timePicked), setupBookableSpacesBloc
); .selectedBookableSpaces.length;
i++) {
final space =
setupBookableSpacesBloc.selectedBookableSpaces[i];
final updatedConfig = space.spaceConfig
?.copyWith(bookingStartTime: timePicked);
final updatedSpace =
space.copyWith(spaceConfig: updatedConfig);
setupBookableSpacesBloc.selectedBookableSpaces[i] =
updatedSpace;
}
} }
}, },
), ),
@ -99,10 +110,21 @@ class BookingPeriodWidget extends StatelessWidget {
)); ));
throw Exception(); throw Exception();
} else { } else {
setupBookableSpacesBloc.selectedBookableSpaces.forEach( for (int i = 0;
(e) => i <
e.spaceConfig!.copyWith(bookingEndTime: timePicked), setupBookableSpacesBloc
); .selectedBookableSpaces.length;
i++) {
final space =
setupBookableSpacesBloc.selectedBookableSpaces[i];
final updatedConfig = space.spaceConfig
?.copyWith(bookingEndTime: timePicked);
final updatedSpace =
space.copyWith(spaceConfig: updatedConfig);
setupBookableSpacesBloc.selectedBookableSpaces[i] =
updatedSpace;
}
} }
}, },
), ),

View File

@ -71,7 +71,7 @@ class ButtonsDividerBottomDialogWidget extends StatelessWidget {
); );
context.read<BookableSpacesBloc>().add( context.read<BookableSpacesBloc>().add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: 1), BookableSpacesParam(currentPage: 1),
), ),
); );
} else if (nonBookableState is NonBookableSpacesError) { } else if (nonBookableState is NonBookableSpacesError) {
@ -79,8 +79,7 @@ class ButtonsDividerBottomDialogWidget extends StatelessWidget {
SnackBar( SnackBar(
content: Text( content: Text(
nonBookableState.error, nonBookableState.error,
style: style: const TextStyle(color: ColorsManager.red),
const TextStyle(color: ColorsManager.red),
), ),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,

View File

@ -25,7 +25,6 @@ class DetailsStepsWidget extends StatelessWidget {
pointsController: pointsController, pointsController: pointsController,
editingBookableSpace: editingBookableSpace, editingBookableSpace: editingBookableSpace,
), ),
StepsInitial() => const SizedBox(),
}; };
}), }),
); );

View File

@ -17,7 +17,6 @@ class PaginationButtonsWidget extends StatelessWidget {
List<Widget> paginationItems = []; List<Widget> paginationItems = [];
// « Two pages back
if (currentPage > 2) { if (currentPage > 2) {
paginationItems.add( paginationItems.add(
_buildArrowButton( _buildArrowButton(
@ -25,7 +24,7 @@ class PaginationButtonsWidget extends StatelessWidget {
onTap: () { onTap: () {
context.read<BookableSpacesBloc>().add( context.read<BookableSpacesBloc>().add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: currentPage - 2), BookableSpacesParam(currentPage: currentPage - 2),
), ),
); );
}, },
@ -33,7 +32,6 @@ class PaginationButtonsWidget extends StatelessWidget {
); );
} }
// < One page back
if (currentPage > 1) { if (currentPage > 1) {
paginationItems.add( paginationItems.add(
_buildArrowButton( _buildArrowButton(
@ -41,7 +39,7 @@ class PaginationButtonsWidget extends StatelessWidget {
onTap: () { onTap: () {
context.read<BookableSpacesBloc>().add( context.read<BookableSpacesBloc>().add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: currentPage - 1), BookableSpacesParam(currentPage: currentPage - 1),
), ),
); );
}, },
@ -49,7 +47,6 @@ class PaginationButtonsWidget extends StatelessWidget {
); );
} }
// Page numbers
for (int i = 1; i <= totalPages; i++) { for (int i = 1; i <= totalPages; i++) {
paginationItems.add( paginationItems.add(
Padding( Padding(
@ -59,7 +56,7 @@ class PaginationButtonsWidget extends StatelessWidget {
if (i != currentPage) { if (i != currentPage) {
context.read<BookableSpacesBloc>().add( context.read<BookableSpacesBloc>().add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: i), BookableSpacesParam(currentPage: i),
), ),
); );
} }
@ -89,7 +86,6 @@ class PaginationButtonsWidget extends StatelessWidget {
); );
} }
// > One page forward
if (currentPage < totalPages) { if (currentPage < totalPages) {
paginationItems.add( paginationItems.add(
_buildArrowButton( _buildArrowButton(
@ -97,7 +93,7 @@ class PaginationButtonsWidget extends StatelessWidget {
onTap: () { onTap: () {
context.read<BookableSpacesBloc>().add( context.read<BookableSpacesBloc>().add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: currentPage + 1), BookableSpacesParam(currentPage: currentPage + 1),
), ),
); );
}, },
@ -105,7 +101,6 @@ class PaginationButtonsWidget extends StatelessWidget {
); );
} }
// » Two pages forward
if (currentPage + 1 < totalPages) { if (currentPage + 1 < totalPages) {
paginationItems.add( paginationItems.add(
_buildArrowButton( _buildArrowButton(
@ -113,7 +108,7 @@ class PaginationButtonsWidget extends StatelessWidget {
onTap: () { onTap: () {
context.read<BookableSpacesBloc>().add( context.read<BookableSpacesBloc>().add(
LoadBookableSpacesEvent( LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: currentPage + 2), BookableSpacesParam(currentPage: currentPage + 2),
), ),
); );
}, },

View File

@ -28,7 +28,7 @@ class TableOfBookableSpacesWidget extends StatelessWidget {
onPressed: () => context onPressed: () => context
.read<BookableSpacesBloc>() .read<BookableSpacesBloc>()
.add(LoadBookableSpacesEvent( .add(LoadBookableSpacesEvent(
BookableSpacesParams(currentPage: 1), BookableSpacesParam(currentPage: 1),
)), )),
child: const Text('Try Again')) child: const Text('Try Again'))
]); ]);
@ -41,12 +41,9 @@ class TableOfBookableSpacesWidget extends StatelessWidget {
title: space.spaceName, title: space.spaceName,
), ),
), ),
DataCell(Padding( DataCell(DataCellWidget(
padding: const EdgeInsetsGeometry.only(left: 10), title: space.spaceVirtualAddress,
child: Text( )),
space.spaceVirtualAddress,
style: const TextStyle(fontSize: 11),
))),
DataCell(Container( DataCell(Container(
padding: const EdgeInsetsGeometry.only(left: 10), padding: const EdgeInsetsGeometry.only(left: 10),
width: 200, width: 200,

View File

@ -53,8 +53,7 @@ class RowOfButtonsTitleWidget extends StatelessWidget {
], ],
), ),
SvgTextButton( SvgTextButton(
verticalPadding: 10, padding: const EdgeInsets.all(10),
horizontalPadding: 10,
svgSize: 15, svgSize: 15,
fontSize: 10, fontSize: 10,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

View File

@ -73,34 +73,31 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
}), }),
value: state is ActivatePointsSwitch, value: state is ActivatePointsSwitch,
onChanged: (value) { onChanged: (value) {
final bloc = context.read<SetupBookableSpacesBloc>();
final updatedCost = value ? -1 : 0;
final switchCubit =
context.read<TogglePointsSwitchCubit>();
if (value) { if (value) {
context switchCubit.activateSwitch();
.read<TogglePointsSwitchCubit>()
.activateSwitch();
context
.read<SetupBookableSpacesBloc>()
.selectedBookableSpaces
.forEach(
(e) => e.spaceConfig!.copyWith(cost: -1),
);
context
.read<SetupBookableSpacesBloc>()
.add(CheckConfigurValidityEvent());
} else { } else {
context switchCubit.unActivateSwitch();
.read<TogglePointsSwitchCubit>()
.unActivateSwitch();
widget.pointsController.clear(); widget.pointsController.clear();
context
.read<SetupBookableSpacesBloc>()
.selectedBookableSpaces
.forEach(
(e) => e.spaceConfig!.copyWith(cost: 0),
);
context
.read<SetupBookableSpacesBloc>()
.add(CheckConfigurValidityEvent());
} }
for (int i = 0;
i < bloc.selectedBookableSpaces.length;
i++) {
final space = bloc.selectedBookableSpaces[i];
final updatedConfig =
space.spaceConfig?.copyWith(cost: updatedCost);
final updatedSpace =
space.copyWith(spaceConfig: updatedConfig);
bloc.selectedBookableSpaces[i] = updatedSpace;
}
bloc.add(CheckConfigurValidityEvent());
}, },
), ),
) )
@ -114,16 +111,21 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
title: 'Ex: 0', title: 'Ex: 0',
height: 40, height: 40,
onChanged: (p0) { onChanged: (p0) {
context final updatedCost =
.read<SetupBookableSpacesBloc>() int.tryParse(widget.pointsController.text) ?? 0;
.selectedBookableSpaces
.forEach( final bloc = context.read<SetupBookableSpacesBloc>();
(e) => e.spaceConfig!.copyWith(
cost: int.parse(widget.pointsController.text.isEmpty for (var i = 0; i < bloc.selectedBookableSpaces.length; i++) {
? '0' final space = bloc.selectedBookableSpaces[i];
: widget.pointsController.text), final updatedConfig =
), space.spaceConfig?.copyWith(cost: updatedCost);
); final updatedSpace =
space.copyWith(spaceConfig: updatedConfig);
bloc.selectedBookableSpaces[i] = updatedSpace;
}
context context
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
.add(CheckConfigurValidityEvent()); .add(CheckConfigurValidityEvent());

View File

@ -65,7 +65,7 @@ class SaveSecondStepButton extends StatelessWidget {
UpdateBookableSpace( UpdateBookableSpace(
onSuccess: () => onSuccess: () =>
context.read<NonBookableSpacesBloc>().add(CallInitStateEvent()), context.read<NonBookableSpacesBloc>().add(CallInitStateEvent()),
updatedParams: UpdateBookableSpaceParam.fromBookableModel( updatedParam: UpdateBookableSpaceParam.fromBookableModel(
context context
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
.selectedBookableSpaces .selectedBookableSpaces

View File

@ -52,21 +52,28 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
onChanged: (newValue) { onChanged: (newValue) {
setState(() { setState(() {
_daysChecked[entry.key] = newValue ?? false; _daysChecked[entry.key] = newValue ?? false;
final selectedDays = _daysChecked.entries
.where((e) => e.value)
.map((e) => e.key)
.toList();
for (var space in context
.read<SetupBookableSpacesBloc>()
.selectedBookableSpaces) {
space.spaceConfig!.copyWith(bookableDays: selectedDays);
}
}); });
context final selectedDays = _daysChecked.entries
.read<SetupBookableSpacesBloc>() .where((e) => e.value)
.add(CheckConfigurValidityEvent()); .map((e) => e.key)
.toList();
final bloc = context.read<SetupBookableSpacesBloc>();
for (int i = 0;
i < bloc.selectedBookableSpaces.length;
i++) {
final space = bloc.selectedBookableSpaces[i];
final updatedConfig = space.spaceConfig
?.copyWith(bookableDays: selectedDays);
final updatedSpace =
space.copyWith(spaceConfig: updatedConfig);
bloc.selectedBookableSpaces[i] = updatedSpace;
}
bloc.add(CheckConfigurValidityEvent());
}, },
), ),
), ),