Browse Source

Save and Refresh List

main
padmanto 2 years ago
parent
commit
af71edf665
  1. 4
      lib/repository/mitra_repository.dart
  2. 2
      lib/widget/fx_data_mitra.dart
  3. 39
      lib/widget/fx_mitra_add_dialog.dart
  4. 4
      lib/widget/fx_text_field.dart
  5. 5
      lib/widget/provider/mitra_add_provider.dart
  6. 41
      php-api/mitra/Md.php

4
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";

2
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();
});
}),
),

39
lib/widget/fx_mitra_add_dialog.dart

@ -30,11 +30,26 @@ class FxMitraAddDialog extends HookConsumerWidget {
final errorMou = useState<String?>(null);
final errorLogin = useState<String?>(null);
final fcPassword = FocusNode();
final fcRePassword = FocusNode();
final errorPassword = useState<String?>(null);
final errorRePassword = useState<String?>(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"),
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"),

4
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),

5
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<MitraAddNotifier, MitraAddState>(
(ref) => MitraAddNotifier(ref: ref),
@ -28,6 +29,8 @@ class MitraAddNotifier extends StateNotifier<MitraAddState> {
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<MitraAddState> {
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);

41
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()

Loading…
Cancel
Save