Skip to content

Commit

Permalink
build 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DyNamite-TNT-1 committed Nov 12, 2023
1 parent 1e07175 commit 13c3891
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 80 deletions.
2 changes: 2 additions & 0 deletions assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"VALIDATE_USERNAME_E001": "Please enter name",
"VALIDATE_ADDRESS_E001": "Please enter address",
"cannot_connect_server": "Cannot connect to server",
"VALIDATE_INPUT_EMPTY": "Input is empty",
"VALIDATE_FORMAT_E001:": "Wrong format",

"booking": "Booking",
"sign_in": "Sign In",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"VALIDATE_USERNAME_E001": "Vui lòng nhập họ và tên",
"VALIDATE_ADDRESS_E001": "Vui lòng nhập địa chỉ",
"cannot_connect_server": "Không thể kết nối tới máy chủ",
"VALIDATE_INPUT_EMPTY": "Trường nhập không được trống",
"VALIDATE_FORMAT_E001:" :"Sai định dạng",

"booking": "Đặt bàn",
"sign_in": "Đăng nhập",
Expand Down
23 changes: 20 additions & 3 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class Api {
static const String http = "http://";

static String getProtocol() {
const bool useSsl = false;
const bool useSsl = true;
String protocol = (useSsl ? Api.https : Api.http);
return protocol;
}

static String localHost() {
// return "restaurantbe-production.up.railway.app";
return "localhost:3005";
return "restaurantbe-production.up.railway.app";
// return "localhost:3005";
}

static String branchGetter() {
Expand Down Expand Up @@ -58,6 +58,8 @@ class Api {
static String requestAllReservationUrl = "/reservation/get/all";
static String requestDetailReservationUrl = "/reservation/get/detail";
static String requestCancelReservationUrl = "/reservation/cancel";
static String requestChangeScheduleReservationUrl =
"/reservation/change-schedule";

//table
static String requestTableUrl = "/table/get";
Expand Down Expand Up @@ -310,6 +312,21 @@ class Api {
return ResultModel.fromJson(result);
}

static Future<ResultModel> requestChangeScheduleReservation({
required int reservationId,
required String schedule,
String tagRequest = HTTPManager.DEFAULT_CANCEL_TAG,
}) async {
final result = await httpManager.patch(
data: {
"newSchedule": schedule,
},
url: appendBranch("$requestChangeScheduleReservationUrl/$reservationId"),
cancelTag: tagRequest,
);
return ResultModel.fromJson(result);
}

//service
static Future<ResultModel> requestListService({
int limit = kLimit,
Expand Down
2 changes: 1 addition & 1 deletion lib/enum/reservation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enum ReservationStatus {
notPayPreFee("Chưa đặt cọc", -2, Color(0XFFF1C232)),
rejected("Đã hủy", -1, Color(0XFFBE2020)),
pending("Xác nhận đặt bàn", 0,Color(0XFF10B759)),
approved("Đã duyệt", 1, Color(0XFF5B47FB)),
pendingChanged("Xác nhận đổi bàn", 1, Color(0XFF5B47FB)),
finishes("Kết thúc", 2, Color(0XFF8B008B));

final String name;
Expand Down
8 changes: 7 additions & 1 deletion lib/models/service/reservation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ReservationDetailModel {
final String schedule;
final int preFee;
final String preFeeStr;
final int refundFee;
final String refundFeeStr;
final String deadline;
final UserModel? userModel;
final List<DishDetailModel> menus;
Expand All @@ -26,6 +28,8 @@ class ReservationDetailModel {
this.reservationId = 0,
this.preFee = 0,
this.preFeeStr = "",
this.refundFee = 0,
this.refundFeeStr = "",
this.deadline = "",
this.countGuest = 0,
this.note = "",
Expand Down Expand Up @@ -59,7 +63,7 @@ class ReservationDetailModel {
}
}

List<DishDetailModel> get drinks {
List<DishDetailModel> get drinks {
if (menus.isEmpty) {
return [];
} else {
Expand All @@ -72,6 +76,8 @@ class ReservationDetailModel {
reservationId: ParseTypeData.ensureInt(json["reservationId"]),
preFee: ParseTypeData.ensureInt(json["preFee"]),
preFeeStr: ParseTypeData.ensureString(json["preFeeStr"]),
refundFee: ParseTypeData.ensureInt(json["refundFee"]),
refundFeeStr: ParseTypeData.ensureString(json["refundFeeStr"]),
deadline: ParseTypeData.ensureString(json["deadline"]),
countGuest: ParseTypeData.ensureInt(json["countGuest"]),
note: ParseTypeData.ensureString(json["note"]),
Expand Down
3 changes: 1 addition & 2 deletions lib/screens/messenger/messenger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class _MessengerScreenState extends State<MessengerScreen> {
return !mounted || messengerBloc.isClosed;
}

_addSocketListener() {
UtilLogger.log("add socket listener");
void _addSocketListener() {
SocketClient.socket!.on('receiver-message', (data) {
if (!isServiceClosed) {
Map<String, dynamic> messageData = data as Map<String, dynamic>;
Expand Down
166 changes: 93 additions & 73 deletions lib/screens/reservation/reservation_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class _ReservationDetailScreenState extends State<ReservationDetailScreen> {
ReservationDetailBloc(ReservationDetailState());
String tagRequestReservation = "";
String tagCancelReservation = "";
String tagChangeSchedule = "";
bool isOpenDishList = true;
bool isOpenDrinkList = true;
bool isOpenServiceList = true;
Expand All @@ -49,6 +50,7 @@ class _ReservationDetailScreenState extends State<ReservationDetailScreen> {
super.dispose();
Api.cancelRequest(tag: tagRequestReservation);
Api.cancelRequest(tag: tagCancelReservation);
Api.cancelRequest(tag: tagChangeSchedule);
}

bool get isServiceClosed {
Expand Down Expand Up @@ -94,89 +96,95 @@ class _ReservationDetailScreenState extends State<ReservationDetailScreen> {
}
}

Future<bool> _changeSchedule(String schedule) async {
Api.cancelRequest(tag: tagChangeSchedule);
ResultModel result = await Api.requestChangeScheduleReservation(
reservationId: widget.id,
schedule: DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(
DateFormat("yyyy/MM/dd hh:mm")
.parse(schedule)
.subtract(Duration(hours: 7)),
),
);
if (mounted) {
Fluttertoast.showToast(
msg: result.message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: primaryColor,
textColor: Colors.white,
fontSize: 16.0,
webBgColor: result.isSuccess ? successColorToast : dangerColorToast,
);
}
if (result.isSuccess) {
_requestDetailReservation();
return true;
}
return false;
}

_openEditDialog() {
TextEditingController scheduleController = TextEditingController();
FocusNode scheduleNode = FocusNode();
ReservationDetailState state = _reservationDetailBloc.state;
scheduleController.text = DateFormat("dd/MM/yyyy HH:mm").format(state
.reservationDetailModel!.schedule
.toDateTime()
.add(Duration(hours: 7)));
bool isErrValidate = false;
scheduleController.text = DateFormat("yyyy/MM/dd HH:mm")
.format(state.reservationDetailModel!.schedule.toDateTime());
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext ct) {
return StatefulBuilder(builder: (context, newState) {
return AppDialogInput(
title: Translate.of(context).translate("change_schedule"),
buttonDoneTitle: Translate.of(context).translate("apply"),
buttonCancelTitle: Translate.of(context).translate("cancel"),
onDone: () async {},
onCancel: () {
context.pop();
return AppDialogInput(
title: Translate.of(context).translate("change_schedule"),
buttonDoneTitle: Translate.of(context).translate("apply"),
buttonCancelTitle: Translate.of(context).translate("cancel"),
onDone: () async {
String errorText = "";
if (scheduleController.text.trim().isEmpty) {
errorText =
Translate.of(context).translate("VALIDATE_INPUT_EMPTY");
}
if (errorText.isNotEmpty) {
Fluttertoast.showToast(
msg: errorText,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: primaryColor,
textColor: Colors.white,
fontSize: 16.0,
webBgColor: dangerColorToast,
);
} else {
bool canPop = await _changeSchedule(scheduleController.text);
if (canPop && mounted) {
context.pop();
}
}
},
onCancel: () {
context.pop();
},
child: StatefulBuilder(
builder: (context, setState) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
AppInput2(
name: "schedule",
keyboardType: TextInputType.name,
controller: scheduleController,
placeHolder:
Translate.of(context).translate("yyyy/MM/dd HH:mm"),
focusNode: scheduleNode,
),
],
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
AppInput2(
name: "schedule",
keyboardType: TextInputType.name,
controller: scheduleController,
placeHolder:
Translate.of(context).translate("dd/MM/yyyy HH:mm"),
focusNode: scheduleNode,
onChanged: (p0) {
// newState(() {
// if (p0.isEmpty) {
// isErrValidate = true;
// } else {
// isErrValidate = false;
// }
// });
print(isErrValidate);
},
),
if (isErrValidate) _buildError(context, "Lỗi trống")
],
),
);
});
},
);
}

Widget _buildError(BuildContext context, String errorText) {
return Container(
margin: EdgeInsets.symmetric(
vertical: kPadding10 / 2,
),
padding: EdgeInsets.symmetric(
horizontal: kPadding10,
),
decoration: BoxDecoration(
color: Color(0XFFFF4444).withOpacity(0.8),
borderRadius: BorderRadius.circular(kCornerNormal),
border: Border.all(
color: Color(0XFFFF4444),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Center(
child: Text(
errorText,
maxLines: 2,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.white,
),
),
),
),
],
),
);
},
);
}

Expand Down Expand Up @@ -552,6 +560,18 @@ class _ReservationDetailScreenState extends State<ReservationDetailScreen> {
SizedBox(
height: kPadding10,
),
if (state.reservationDetailModel!.status == -1)
Column(
children: [
_buildRowInfo(context,
leftTag: "Phí hoàn trả:",
rightValue:
"${state.reservationDetailModel!.refundFeeStr} VNĐ"),
SizedBox(
height: kPadding10,
),
],
),
Row(
children: [
Expanded(
Expand Down
1 change: 1 addition & 0 deletions lib/screens/setting/setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class _SettingScreenState extends State<SettingScreen> {
),
children: [
_buildChangeLanguage(context),
Text("version: 1.0.1"),
],
),
)
Expand Down

0 comments on commit 13c3891

Please sign in to comment.