From af71edf665ed785cbce30313713e291e71f89a93 Mon Sep 17 00:00:00 2001 From: padmanto Date: Sun, 12 Jun 2022 07:09:50 +0700 Subject: [PATCH] Save and Refresh List --- lib/repository/mitra_repository.dart | 4 ++- lib/widget/fx_data_mitra.dart | 2 +- lib/widget/fx_mitra_add_dialog.dart | 47 ++++++++++++++++++++++++++--- lib/widget/fx_text_field.dart | 4 ++- lib/widget/provider/mitra_add_provider.dart | 5 +++ php-api/mitra/Md.php | 41 +++++++++++++++++++++++-- 6 files changed, 93 insertions(+), 10 deletions(-) diff --git a/lib/repository/mitra_repository.dart b/lib/repository/mitra_repository.dart index 44fc2f9..b734004 100644 --- a/lib/repository/mitra_repository.dart +++ b/lib/repository/mitra_repository.dart @@ -17,6 +17,7 @@ class MitraRepository extends BaseRepository { required String doctorID, required String doctorAddressID, required String login, + required String password, CancelToken? cancelToken, }) async { final param = { @@ -25,7 +26,8 @@ class MitraRepository extends BaseRepository { "mouID": mouID, "doctorID": doctorID, "doctorAddressID": doctorAddressID, - "login": login + "login": login, + "password": password }; final service = "${Constants.baseUrl}md/add"; diff --git a/lib/widget/fx_data_mitra.dart b/lib/widget/fx_data_mitra.dart index de4b2ef..948c4fa 100644 --- a/lib/widget/fx_data_mitra.dart +++ b/lib/widget/fx_data_mitra.dart @@ -63,7 +63,7 @@ class FxDataMitra extends HookConsumerWidget { await showDialog( context: context, builder: (context) { - return FxMitraAddDialog(); + return const FxMitraAddDialog(); }); }), ), diff --git a/lib/widget/fx_mitra_add_dialog.dart b/lib/widget/fx_mitra_add_dialog.dart index 2f77708..d58da2d 100644 --- a/lib/widget/fx_mitra_add_dialog.dart +++ b/lib/widget/fx_mitra_add_dialog.dart @@ -30,11 +30,26 @@ class FxMitraAddDialog extends HookConsumerWidget { final errorMou = useState(null); final errorLogin = useState(null); + final fcPassword = FocusNode(); + final fcRePassword = FocusNode(); + final errorPassword = useState(null); + final errorRePassword = useState(null); + final ctrlLogin = useTextEditingController(text: ""); + final ctrlPassword = useTextEditingController(text: ""); + final ctrlRePassword = useTextEditingController(text: ""); bool Function() validationError; validationError = () { bool haveError = false; + if (ctrlPassword.text == "") { + errorPassword.value = "Password is mandatory"; + haveError = true; + } + if (ctrlRePassword.text != ctrlPassword.text) { + errorRePassword.value = "Password confirmation error"; + haveError = true; + } if (company == null) { errorCompany.value = "Company is mandatory"; haveError = true; @@ -102,12 +117,31 @@ class FxMitraAddDialog extends HookConsumerWidget { errorMessage: errorLogin.value, ), const SizedBox(height: 10), + FxTextField( + ctrl: ctrlPassword, + fc: fcPassword, + hint: "Password", + label: "Password", + obscureText: true, + errorMessage: errorPassword.value, + ), + const SizedBox(height: 10), + FxTextField( + ctrl: ctrlRePassword, + fc: fcRePassword, + hint: "Retype Password", + label: "Retype Password", + obscureText: true, + errorMessage: errorRePassword.value, + ), + const SizedBox(height: 10), const FxTextField( - hint: "ID", - label: "ID", - isReadOnly: true, - isEnabled: false, - suffixText: "Auto Generated"), + hint: "ID", + label: "ID", + isReadOnly: true, + isEnabled: false, + suffixText: "Auto Generated", + ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.end, @@ -128,7 +162,10 @@ class FxMitraAddDialog extends HookConsumerWidget { doctorAddressID: doctorAddress!.mDoctorAddressID, login: ctrlLogin.text, + password: ctrlPassword.text, + query: "", ); + Navigator.of(context).pop(); } }, child: const Text("Save"), diff --git a/lib/widget/fx_text_field.dart b/lib/widget/fx_text_field.dart index eaf9994..e1b5683 100644 --- a/lib/widget/fx_text_field.dart +++ b/lib/widget/fx_text_field.dart @@ -9,7 +9,7 @@ class FxTextField extends StatelessWidget { final bool? isReadOnly; final bool? isEnabled; final String? suffixText; - + final bool obscureText; const FxTextField({ Key? key, this.ctrl, @@ -20,11 +20,13 @@ class FxTextField extends StatelessWidget { this.isReadOnly, this.isEnabled, this.suffixText, + this.obscureText = false, }) : super(key: key); @override Widget build(BuildContext context) { return TextField( + obscureText: obscureText, decoration: InputDecoration( border: OutlineInputBorder( borderRadius: BorderRadius.circular(10), diff --git a/lib/widget/provider/mitra_add_provider.dart b/lib/widget/provider/mitra_add_provider.dart index 4938506..121e5a2 100644 --- a/lib/widget/provider/mitra_add_provider.dart +++ b/lib/widget/provider/mitra_add_provider.dart @@ -6,6 +6,7 @@ import '../../provider/dio_provider.dart'; import '../../provider/local_auth_provider.dart'; import '../../repository/base_repository.dart'; import '../../repository/mitra_repository.dart'; +import '../../screen/md_lab_mitra/mitra_search_provider.dart'; final mitraAddProvider = StateNotifierProvider( (ref) => MitraAddNotifier(ref: ref), @@ -28,6 +29,8 @@ class MitraAddNotifier extends StateNotifier { required String doctorID, required String doctorAddressID, required String login, + required String password, + required String query, }) async { try { state = MitraAddStateLoading(); @@ -43,8 +46,10 @@ class MitraAddNotifier extends StateNotifier { doctorID: doctorID, doctorAddressID: doctorAddressID, login: login, + password: password, ); state = MitraAddStateDone(); + ref.read(mitraSearchProvider.notifier).search(query: query); } catch (e) { if (e is BaseRepositoryException) { state = MitraAddStateError(message: e.message); diff --git a/php-api/mitra/Md.php b/php-api/mitra/Md.php index 578fcae..13846ac 100644 --- a/php-api/mitra/Md.php +++ b/php-api/mitra/Md.php @@ -15,8 +15,45 @@ class Md extends MY_Controller function add() { $param = $this->sys_input; - $sql = "insert into "; - print_r($param); + $user = $this->sys_user; + $userID = $user["M_UserID"]; + + $this->db->trans_begin(); + $sql = "insert into mitra(MitraM_CompanyID, MitraM_DoctorID, + MitraM_DoctorAddressID,MitraUsername, + MitraPassword, MitraM_UserID, + MitraIDNo, MitraCommitment) + values(?,?, ?,?, ?,?, fn_generate_mitra_id(),'')"; + $qry = $this->db->query($sql, [ + $param["companyID"], $param["doctorID"], + $param["doctorAddressID"], $param["login"], + $param["password"], $userID + ]); + if (!$qry) { + echo json_encode([ + "status" => "ERR", + "message" => $this->db->error()["message"], + ]); + exit(); + } + $mitraID = $this->db->insert_id(); + $sql = "insert into mitra_mou(MitraMouMitraID,MitraMouM_MouID, + MitraMouM_UserID) + values(?,?,?)"; + + foreach ($param["mouID"] as $mouID) { + $qry = $this->db->query($sql, [$mitraID, $mouID, $userID]); + if (!$qry) { + echo json_encode([ + "status" => "ERR", + "message" => $this->db->error()["message"], + ]); + $this->db->trans_rollback(); + exit(); + } + } + $this->db->trans_commit(); + echo json_encode(["status" => "OK"]); } function corss()