From 8431b07057260e140d89ab9fba3fcbd915cced3b Mon Sep 17 00:00:00 2001 From: efrilm Date: Sun, 3 Aug 2025 23:33:00 +0700 Subject: [PATCH] feat: create table --- lib/core/components/custom_text_field.dart | 4 +- .../datasources/table_remote_datasource.dart | 53 ++++ lib/main.dart | 3 +- .../blocs/create_table/create_table_bloc.dart | 19 +- .../create_table_bloc.freezed.dart | 256 ++++++++++++++++-- .../create_table/create_table_event.dart | 7 +- .../create_table/create_table_state.dart | 1 + .../table/dialogs/form_table_new_dialog.dart | 86 ++++++ .../pages/new_table_management_page.dart | 59 +--- 9 files changed, 393 insertions(+), 95 deletions(-) create mode 100644 lib/data/datasources/table_remote_datasource.dart create mode 100644 lib/presentation/table/dialogs/form_table_new_dialog.dart diff --git a/lib/core/components/custom_text_field.dart b/lib/core/components/custom_text_field.dart index c256cf4..3e677fc 100644 --- a/lib/core/components/custom_text_field.dart +++ b/lib/core/components/custom_text_field.dart @@ -14,7 +14,7 @@ class CustomTextField extends StatelessWidget { final Widget? prefixIcon; final Widget? suffixIcon; final bool readOnly; - final int? maxLines; + final int maxLines; final String? Function(String?)? validator; const CustomTextField({ @@ -30,7 +30,7 @@ class CustomTextField extends StatelessWidget { this.prefixIcon, this.suffixIcon, this.readOnly = false, - this.maxLines, + this.maxLines = 1, this.validator, }); diff --git a/lib/data/datasources/table_remote_datasource.dart b/lib/data/datasources/table_remote_datasource.dart new file mode 100644 index 0000000..33b8427 --- /dev/null +++ b/lib/data/datasources/table_remote_datasource.dart @@ -0,0 +1,53 @@ +import 'dart:developer'; +import 'package:dartz/dartz.dart'; +import 'package:dio/dio.dart'; +import 'package:enaklo_pos/core/network/dio_client.dart'; +import '../../core/constants/variables.dart'; +import 'auth_local_datasource.dart'; + +class TableRemoteDataSource { + final Dio dio = DioClient.instance; + + Future> createTable({ + required String tableName, + required int capacity, + required String location, + }) async { + try { + final authData = await AuthLocalDataSource().getAuthData(); + final url = '${Variables.baseUrl}/api/v1/tables'; + + final response = await dio.post( + url, + data: { + "outlet_id": authData.user?.outletId, + "table_name": tableName, + "capacity": capacity, + "location": location, + "status": "available", + "is_active": true, + "position_x": 200, + "position_y": 200, + }, + options: Options( + headers: { + 'Authorization': 'Bearer ${authData.token}', + 'Accept': 'application/json', + }, + ), + ); + + if (response.statusCode == 200 || response.statusCode == 201) { + return Right(true); + } else { + return const Left('Failed to create table'); + } + } on DioException catch (e) { + log("Dio error: ${e.message}"); + return Left(e.response?.data['message'] ?? 'Gagal membuat table'); + } catch (e) { + log("Unexpected error: $e"); + return const Left('Unexpected error occurred'); + } + } +} diff --git a/lib/main.dart b/lib/main.dart index e689334..6d86213 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'dart:developer'; import 'package:enaklo_pos/core/constants/theme.dart'; import 'package:enaklo_pos/data/datasources/customer_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart'; +import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart'; import 'package:enaklo_pos/presentation/customer/bloc/customer_form/customer_form_bloc.dart'; import 'package:enaklo_pos/presentation/customer/bloc/customer_loader/customer_loader_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart'; @@ -147,7 +148,7 @@ class _MyAppState extends State { create: (context) => TransactionReportBloc(OrderRemoteDatasource()), ), BlocProvider( - create: (context) => CreateTableBloc(), + create: (context) => CreateTableBloc(TableRemoteDataSource()), ), BlocProvider( create: (context) => ChangePositionTableBloc(), diff --git a/lib/presentation/table/blocs/create_table/create_table_bloc.dart b/lib/presentation/table/blocs/create_table/create_table_bloc.dart index ecdd58c..8613d7d 100644 --- a/lib/presentation/table/blocs/create_table/create_table_bloc.dart +++ b/lib/presentation/table/blocs/create_table/create_table_bloc.dart @@ -1,7 +1,5 @@ -import 'dart:ui'; - import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'create_table_event.dart'; @@ -9,12 +7,19 @@ part 'create_table_state.dart'; part 'create_table_bloc.freezed.dart'; class CreateTableBloc extends Bloc { - CreateTableBloc() : super(_Initial()) { + final TableRemoteDataSource _tableRemoteDataSource; + CreateTableBloc(this._tableRemoteDataSource) + : super(CreateTableState.initial()) { on<_CreateTable>((event, emit) async { emit(_Loading()); - await ProductLocalDatasource.instance - .createTableManagement(event.tableName, event.position); - emit(_Success('Create Table Success')); + final result = await _tableRemoteDataSource.createTable( + tableName: event.tableName, + capacity: event.capacity, + location: event.location, + ); + + result.fold((l) => emit(_Error(l)), + (r) => emit(_Success('Meja berhasil dibuat'))); }); } } diff --git a/lib/presentation/table/blocs/create_table/create_table_bloc.freezed.dart b/lib/presentation/table/blocs/create_table/create_table_bloc.freezed.dart index 707ba61..821fef8 100644 --- a/lib/presentation/table/blocs/create_table/create_table_bloc.freezed.dart +++ b/lib/presentation/table/blocs/create_table/create_table_bloc.freezed.dart @@ -19,19 +19,22 @@ mixin _$CreateTableEvent { @optionalTypeArgs TResult when({ required TResult Function() started, - required TResult Function(String tableName, Offset position) createTable, + required TResult Function(String tableName, int capacity, String location) + createTable, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ TResult? Function()? started, - TResult? Function(String tableName, Offset position)? createTable, + TResult? Function(String tableName, int capacity, String location)? + createTable, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ TResult Function()? started, - TResult Function(String tableName, Offset position)? createTable, + TResult Function(String tableName, int capacity, String location)? + createTable, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -119,7 +122,8 @@ class _$StartedImpl implements _Started { @optionalTypeArgs TResult when({ required TResult Function() started, - required TResult Function(String tableName, Offset position) createTable, + required TResult Function(String tableName, int capacity, String location) + createTable, }) { return started(); } @@ -128,7 +132,8 @@ class _$StartedImpl implements _Started { @optionalTypeArgs TResult? whenOrNull({ TResult? Function()? started, - TResult? Function(String tableName, Offset position)? createTable, + TResult? Function(String tableName, int capacity, String location)? + createTable, }) { return started?.call(); } @@ -137,7 +142,8 @@ class _$StartedImpl implements _Started { @optionalTypeArgs TResult maybeWhen({ TResult Function()? started, - TResult Function(String tableName, Offset position)? createTable, + TResult Function(String tableName, int capacity, String location)? + createTable, required TResult orElse(), }) { if (started != null) { @@ -188,7 +194,7 @@ abstract class _$$CreateTableImplCopyWith<$Res> { _$CreateTableImpl value, $Res Function(_$CreateTableImpl) then) = __$$CreateTableImplCopyWithImpl<$Res>; @useResult - $Res call({String tableName, Offset position}); + $Res call({String tableName, int capacity, String location}); } /// @nodoc @@ -205,17 +211,22 @@ class __$$CreateTableImplCopyWithImpl<$Res> @override $Res call({ Object? tableName = null, - Object? position = null, + Object? capacity = null, + Object? location = null, }) { return _then(_$CreateTableImpl( - null == tableName + tableName: null == tableName ? _value.tableName : tableName // ignore: cast_nullable_to_non_nullable as String, - null == position - ? _value.position - : position // ignore: cast_nullable_to_non_nullable - as Offset, + capacity: null == capacity + ? _value.capacity + : capacity // ignore: cast_nullable_to_non_nullable + as int, + location: null == location + ? _value.location + : location // ignore: cast_nullable_to_non_nullable + as String, )); } } @@ -223,16 +234,21 @@ class __$$CreateTableImplCopyWithImpl<$Res> /// @nodoc class _$CreateTableImpl implements _CreateTable { - const _$CreateTableImpl(this.tableName, this.position); + const _$CreateTableImpl( + {required this.tableName, + required this.capacity, + required this.location}); @override final String tableName; @override - final Offset position; + final int capacity; + @override + final String location; @override String toString() { - return 'CreateTableEvent.createTable(tableName: $tableName, position: $position)'; + return 'CreateTableEvent.createTable(tableName: $tableName, capacity: $capacity, location: $location)'; } @override @@ -242,12 +258,14 @@ class _$CreateTableImpl implements _CreateTable { other is _$CreateTableImpl && (identical(other.tableName, tableName) || other.tableName == tableName) && - (identical(other.position, position) || - other.position == position)); + (identical(other.capacity, capacity) || + other.capacity == capacity) && + (identical(other.location, location) || + other.location == location)); } @override - int get hashCode => Object.hash(runtimeType, tableName, position); + int get hashCode => Object.hash(runtimeType, tableName, capacity, location); /// Create a copy of CreateTableEvent /// with the given fields replaced by the non-null parameter values. @@ -261,29 +279,32 @@ class _$CreateTableImpl implements _CreateTable { @optionalTypeArgs TResult when({ required TResult Function() started, - required TResult Function(String tableName, Offset position) createTable, + required TResult Function(String tableName, int capacity, String location) + createTable, }) { - return createTable(tableName, position); + return createTable(tableName, capacity, location); } @override @optionalTypeArgs TResult? whenOrNull({ TResult? Function()? started, - TResult? Function(String tableName, Offset position)? createTable, + TResult? Function(String tableName, int capacity, String location)? + createTable, }) { - return createTable?.call(tableName, position); + return createTable?.call(tableName, capacity, location); } @override @optionalTypeArgs TResult maybeWhen({ TResult Function()? started, - TResult Function(String tableName, Offset position)? createTable, + TResult Function(String tableName, int capacity, String location)? + createTable, required TResult orElse(), }) { if (createTable != null) { - return createTable(tableName, position); + return createTable(tableName, capacity, location); } return orElse(); } @@ -321,11 +342,14 @@ class _$CreateTableImpl implements _CreateTable { } abstract class _CreateTable implements CreateTableEvent { - const factory _CreateTable(final String tableName, final Offset position) = - _$CreateTableImpl; + const factory _CreateTable( + {required final String tableName, + required final int capacity, + required final String location}) = _$CreateTableImpl; String get tableName; - Offset get position; + int get capacity; + String get location; /// Create a copy of CreateTableEvent /// with the given fields replaced by the non-null parameter values. @@ -341,6 +365,7 @@ mixin _$CreateTableState { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) success, + required TResult Function(String message) error, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -348,6 +373,7 @@ mixin _$CreateTableState { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? success, + TResult? Function(String message)? error, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -355,6 +381,7 @@ mixin _$CreateTableState { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? success, + TResult Function(String message)? error, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -363,6 +390,7 @@ mixin _$CreateTableState { required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, required TResult Function(_Success value) success, + required TResult Function(_Error value) error, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -370,6 +398,7 @@ mixin _$CreateTableState { TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, TResult? Function(_Success value)? success, + TResult? Function(_Error value)? error, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -377,6 +406,7 @@ mixin _$CreateTableState { TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, TResult Function(_Success value)? success, + TResult Function(_Error value)? error, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -447,6 +477,7 @@ class _$InitialImpl implements _Initial { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) success, + required TResult Function(String message) error, }) { return initial(); } @@ -457,6 +488,7 @@ class _$InitialImpl implements _Initial { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? success, + TResult? Function(String message)? error, }) { return initial?.call(); } @@ -467,6 +499,7 @@ class _$InitialImpl implements _Initial { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? success, + TResult Function(String message)? error, required TResult orElse(), }) { if (initial != null) { @@ -481,6 +514,7 @@ class _$InitialImpl implements _Initial { required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, required TResult Function(_Success value) success, + required TResult Function(_Error value) error, }) { return initial(this); } @@ -491,6 +525,7 @@ class _$InitialImpl implements _Initial { TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, TResult? Function(_Success value)? success, + TResult? Function(_Error value)? error, }) { return initial?.call(this); } @@ -501,6 +536,7 @@ class _$InitialImpl implements _Initial { TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, TResult Function(_Success value)? success, + TResult Function(_Error value)? error, required TResult orElse(), }) { if (initial != null) { @@ -558,6 +594,7 @@ class _$LoadingImpl implements _Loading { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) success, + required TResult Function(String message) error, }) { return loading(); } @@ -568,6 +605,7 @@ class _$LoadingImpl implements _Loading { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? success, + TResult? Function(String message)? error, }) { return loading?.call(); } @@ -578,6 +616,7 @@ class _$LoadingImpl implements _Loading { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? success, + TResult Function(String message)? error, required TResult orElse(), }) { if (loading != null) { @@ -592,6 +631,7 @@ class _$LoadingImpl implements _Loading { required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, required TResult Function(_Success value) success, + required TResult Function(_Error value) error, }) { return loading(this); } @@ -602,6 +642,7 @@ class _$LoadingImpl implements _Loading { TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, TResult? Function(_Success value)? success, + TResult? Function(_Error value)? error, }) { return loading?.call(this); } @@ -612,6 +653,7 @@ class _$LoadingImpl implements _Loading { TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, TResult Function(_Success value)? success, + TResult Function(_Error value)? error, required TResult orElse(), }) { if (loading != null) { @@ -696,6 +738,7 @@ class _$SuccessImpl implements _Success { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) success, + required TResult Function(String message) error, }) { return success(message); } @@ -706,6 +749,7 @@ class _$SuccessImpl implements _Success { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? success, + TResult? Function(String message)? error, }) { return success?.call(message); } @@ -716,6 +760,7 @@ class _$SuccessImpl implements _Success { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? success, + TResult Function(String message)? error, required TResult orElse(), }) { if (success != null) { @@ -730,6 +775,7 @@ class _$SuccessImpl implements _Success { required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, required TResult Function(_Success value) success, + required TResult Function(_Error value) error, }) { return success(this); } @@ -740,6 +786,7 @@ class _$SuccessImpl implements _Success { TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, TResult? Function(_Success value)? success, + TResult? Function(_Error value)? error, }) { return success?.call(this); } @@ -750,6 +797,7 @@ class _$SuccessImpl implements _Success { TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, TResult Function(_Success value)? success, + TResult Function(_Error value)? error, required TResult orElse(), }) { if (success != null) { @@ -770,3 +818,155 @@ abstract class _Success implements CreateTableState { _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => throw _privateConstructorUsedError; } + +/// @nodoc +abstract class _$$ErrorImplCopyWith<$Res> { + factory _$$ErrorImplCopyWith( + _$ErrorImpl value, $Res Function(_$ErrorImpl) then) = + __$$ErrorImplCopyWithImpl<$Res>; + @useResult + $Res call({String message}); +} + +/// @nodoc +class __$$ErrorImplCopyWithImpl<$Res> + extends _$CreateTableStateCopyWithImpl<$Res, _$ErrorImpl> + implements _$$ErrorImplCopyWith<$Res> { + __$$ErrorImplCopyWithImpl( + _$ErrorImpl _value, $Res Function(_$ErrorImpl) _then) + : super(_value, _then); + + /// Create a copy of CreateTableState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? message = null, + }) { + return _then(_$ErrorImpl( + null == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$ErrorImpl implements _Error { + const _$ErrorImpl(this.message); + + @override + final String message; + + @override + String toString() { + return 'CreateTableState.error(message: $message)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ErrorImpl && + (identical(other.message, message) || other.message == message)); + } + + @override + int get hashCode => Object.hash(runtimeType, message); + + /// Create a copy of CreateTableState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => + __$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function(String message) success, + required TResult Function(String message) error, + }) { + return error(message); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function(String message)? success, + TResult? Function(String message)? error, + }) { + return error?.call(message); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function(String message)? success, + TResult Function(String message)? error, + required TResult orElse(), + }) { + if (error != null) { + return error(message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Success value) success, + required TResult Function(_Error value) error, + }) { + return error(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Success value)? success, + TResult? Function(_Error value)? error, + }) { + return error?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Success value)? success, + TResult Function(_Error value)? error, + required TResult orElse(), + }) { + if (error != null) { + return error(this); + } + return orElse(); + } +} + +abstract class _Error implements CreateTableState { + const factory _Error(final String message) = _$ErrorImpl; + + String get message; + + /// Create a copy of CreateTableState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/presentation/table/blocs/create_table/create_table_event.dart b/lib/presentation/table/blocs/create_table/create_table_event.dart index 1278f35..08bde88 100644 --- a/lib/presentation/table/blocs/create_table/create_table_event.dart +++ b/lib/presentation/table/blocs/create_table/create_table_event.dart @@ -3,6 +3,9 @@ part of 'create_table_bloc.dart'; @freezed class CreateTableEvent with _$CreateTableEvent { const factory CreateTableEvent.started() = _Started; - const factory CreateTableEvent.createTable( - String tableName, Offset position) = _CreateTable; + const factory CreateTableEvent.createTable({ + required String tableName, + required int capacity, + required String location, + }) = _CreateTable; } diff --git a/lib/presentation/table/blocs/create_table/create_table_state.dart b/lib/presentation/table/blocs/create_table/create_table_state.dart index e697088..e3c4bce 100644 --- a/lib/presentation/table/blocs/create_table/create_table_state.dart +++ b/lib/presentation/table/blocs/create_table/create_table_state.dart @@ -7,4 +7,5 @@ class CreateTableState with _$CreateTableState { const factory CreateTableState.loading() = _Loading; // success const factory CreateTableState.success(String message) = _Success; + const factory CreateTableState.error(String message) = _Error; } diff --git a/lib/presentation/table/dialogs/form_table_new_dialog.dart b/lib/presentation/table/dialogs/form_table_new_dialog.dart new file mode 100644 index 0000000..8996adf --- /dev/null +++ b/lib/presentation/table/dialogs/form_table_new_dialog.dart @@ -0,0 +1,86 @@ +import 'package:enaklo_pos/core/components/buttons.dart'; +import 'package:enaklo_pos/core/components/custom_modal_dialog.dart'; +import 'package:enaklo_pos/core/components/custom_text_field.dart'; +import 'package:enaklo_pos/core/components/flushbar.dart'; +import 'package:enaklo_pos/core/components/spaces.dart'; +import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; +import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class FormTableNewDialog extends StatefulWidget { + const FormTableNewDialog({super.key}); + + @override + State createState() => _FormTableNewDialogState(); +} + +class _FormTableNewDialogState extends State { + TextEditingController tableNameController = TextEditingController(); + TextEditingController capacityController = TextEditingController(); + TextEditingController locationController = TextEditingController(); + + @override + Widget build(BuildContext context) { + return CustomModalDialog( + title: 'Tambah Meja', + subtitle: 'Silahkan isi data meja', + contentPadding: + const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0), + child: Column( + children: [ + CustomTextField( + controller: tableNameController, + label: 'Nama Meja', + ), + SpaceHeight(16), + CustomTextField( + controller: capacityController, + label: 'Kapasitas', + keyboardType: TextInputType.number, + ), + SpaceHeight(16), + CustomTextField( + controller: locationController, + label: 'Lokasi', + ), + SpaceHeight(24), + BlocListener( + listener: (context, state) { + state.maybeWhen( + orElse: () {}, + success: (message) { + context.pop(); + AppFlushbar.showSuccess(context, message); + }, + error: (message) { + AppFlushbar.showError(context, message); + }, + ); + }, + child: BlocBuilder( + builder: (context, state) { + return state.maybeWhen( + orElse: () => Button.filled( + onPressed: () { + context.read().add( + CreateTableEvent.createTable( + capacity: int.parse(capacityController.text), + location: locationController.text, + tableName: tableNameController.text, + ), + ); + }, + label: 'Simpan', + ), + loading: () => + Center(child: const CircularProgressIndicator()), + ); + }, + ), + ), + ], + ), + ); + } +} diff --git a/lib/presentation/table/pages/new_table_management_page.dart b/lib/presentation/table/pages/new_table_management_page.dart index 95fb0d9..8ddf07e 100644 --- a/lib/presentation/table/pages/new_table_management_page.dart +++ b/lib/presentation/table/pages/new_table_management_page.dart @@ -1,18 +1,13 @@ -import 'dart:developer'; - +import 'package:enaklo_pos/presentation/table/dialogs/form_table_new_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:enaklo_pos/core/components/components.dart'; import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; -import 'package:enaklo_pos/data/models/response/table_model.dart'; import 'package:enaklo_pos/presentation/table/blocs/change_position_table/change_position_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/widgets/table_widget.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:hive/hive.dart'; -import 'package:path_provider/path_provider.dart'; class TableManagementScreen extends StatefulWidget { const TableManagementScreen({super.key}); @@ -64,55 +59,9 @@ class _TableManagementScreenState extends State { onPressed: () { // show dialaog adn input table name showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Add Table'), - content: SingleChildScrollView( - child: ConstrainedBox( - constraints: BoxConstraints( - maxHeight: 180, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomTextField( - controller: tableNameController!, - label: 'Table Name', - ), - SpaceHeight(16), - Row( - children: [ - Expanded( - child: Button.outlined( - onPressed: () { - context.pop(); - }, - label: 'close', - ), - ), - SpaceWidth(16), - Expanded( - child: Button.filled( - onPressed: () { - context.read().add( - CreateTableEvent.createTable( - tableNameController!.text, - Offset(200, 200))); - context - .pop(); // close dialog after adding - }, - label: 'Add', - ), - ), - ], - ) - ], - ), - ), - ), - actions: []); - }); + context: context, + builder: (context) => FormTableNewDialog(), + ); }, ), ),