Commit d86c3328 authored by DatHV's avatar DatHV
Browse files

update auth logic

parent 5fb93f2d
...@@ -9,6 +9,7 @@ import '../../resouce/text_style.dart'; ...@@ -9,6 +9,7 @@ import '../../resouce/text_style.dart';
import '../../shared/router_gage.dart'; import '../../shared/router_gage.dart';
import '../pageDetail/campaign_detail_screen.dart'; import '../pageDetail/campaign_detail_screen.dart';
import '../pageDetail/model/detail_page_rule_type.dart'; import '../pageDetail/model/detail_page_rule_type.dart';
import 'delete_account_viewmodel.dart';
class DeleteAccountDialog extends StatefulWidget { class DeleteAccountDialog extends StatefulWidget {
const DeleteAccountDialog({super.key}); const DeleteAccountDialog({super.key});
...@@ -18,7 +19,7 @@ class DeleteAccountDialog extends StatefulWidget { ...@@ -18,7 +19,7 @@ class DeleteAccountDialog extends StatefulWidget {
} }
class _DeleteAccountDialogState extends State<DeleteAccountDialog> { class _DeleteAccountDialogState extends State<DeleteAccountDialog> {
bool agreed = false; final DeleteAccountViewModel _viewModel = DeleteAccountViewModel();
late TapGestureRecognizer _termConditionRecognizer; late TapGestureRecognizer _termConditionRecognizer;
@override @override
...@@ -60,7 +61,11 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> { ...@@ -60,7 +61,11 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> {
onTap: _onUnUsedVoucherPressed, onTap: _onUnUsedVoucherPressed,
child: Text( child: Text(
"Ưu đãi chưa sử dụng ", "Ưu đãi chưa sử dụng ",
style: AppTextStyle.link.copyWith(color: Colors.blue, decoration: TextDecoration.underline), style: AppTextStyle.link.copyWith(
color: Colors.blue, // ✅ Màu chữ
decoration: TextDecoration.underline, // ✅ Gạch chân
decorationColor: Colors.blue, // ✅ Gạch chân màu xanh
),
), ),
), ),
), ),
...@@ -88,8 +93,8 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> { ...@@ -88,8 +93,8 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> {
), ),
), ),
child: Checkbox( child: Checkbox(
value: agreed, value: _viewModel.agreed.value,
onChanged: (value) => setState(() => agreed = value ?? false), onChanged: (value) => setState(() => _viewModel.agreed.value = value ?? false),
visualDensity: const VisualDensity(horizontal: -4, vertical: -4), visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
), ),
), ),
...@@ -116,7 +121,7 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> { ...@@ -116,7 +121,7 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> {
width: double.infinity, width: double.infinity,
height: 40, height: 40,
child: ElevatedButton( child: ElevatedButton(
onPressed: agreed ? _onConfirmDelete : null, onPressed: _viewModel.agreed.value ? _onConfirmDelete : null,
style: AppButtonStyle.secondary, style: AppButtonStyle.secondary,
child: const Text("Xác nhận xoá"), child: const Text("Xác nhận xoá"),
), ),
...@@ -138,7 +143,7 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> { ...@@ -138,7 +143,7 @@ class _DeleteAccountDialogState extends State<DeleteAccountDialog> {
void _onConfirmDelete() { void _onConfirmDelete() {
if (DataPreference.instance.profile?.userAgreements?.hideDeleteAccount == false) { if (DataPreference.instance.profile?.userAgreements?.hideDeleteAccount == false) {
_viewModel.confirmDelete();
} else { } else {
DataPreference.instance.clearData(); DataPreference.instance.clearData();
Get.offAllNamed(onboardingScreen); Get.offAllNamed(onboardingScreen);
......
...@@ -18,7 +18,7 @@ class DeleteAccountViewModel extends RestfulApiViewModel { ...@@ -18,7 +18,7 @@ class DeleteAccountViewModel extends RestfulApiViewModel {
if (value.isSuccess) { if (value.isSuccess) {
final phone = DataPreference.instance.phone ?? ""; final phone = DataPreference.instance.phone ?? "";
Get.to( Get.to(
() => OtpScreen(repository: DeleteAccountOtpRepository(phone, value.data?.resendAfterSecond ?? 0)), () => OtpScreen(repository: DeleteAccountOtpRepository(phone, value.data?.resendAfterSecond ?? Constants.otpTtl)),
); );
} else { } else {
final mgs = value.errorMessage ?? Constants.commonError; final mgs = value.errorMessage ?? Constants.commonError;
......
...@@ -4,7 +4,9 @@ import 'package:mypoint_flutter_app/networking/restful_api_request.dart'; ...@@ -4,7 +4,9 @@ import 'package:mypoint_flutter_app/networking/restful_api_request.dart';
import 'package:mypoint_flutter_app/shared/router_gage.dart'; import 'package:mypoint_flutter_app/shared/router_gage.dart';
import '../../base/base_response_model.dart'; import '../../base/base_response_model.dart';
import '../../base/restful_api_viewmodel.dart'; import '../../base/restful_api_viewmodel.dart';
import '../../configs/constants.dart';
import '../../preference/data_preference.dart'; import '../../preference/data_preference.dart';
import '../../widgets/custom_toast_message.dart';
import '../splash/splash_screen_viewmodel.dart'; import '../splash/splash_screen_viewmodel.dart';
import 'otp_viewmodel.dart'; import 'otp_viewmodel.dart';
...@@ -25,6 +27,7 @@ class DeleteAccountOtpRepository extends RestfulApiViewModel implements IOtpRepo ...@@ -25,6 +27,7 @@ class DeleteAccountOtpRepository extends RestfulApiViewModel implements IOtpRepo
return client.verifyDeleteAccount(otpCode).then((value) { return client.verifyDeleteAccount(otpCode).then((value) {
hideLoading(); hideLoading();
if (value.isSuccess) { if (value.isSuccess) {
showToastMessage("Xóa tài khoản thành công");
DataPreference.instance.clearData(); DataPreference.instance.clearData();
Get.offAllNamed(onboardingScreen); Get.offAllNamed(onboardingScreen);
} }
...@@ -34,10 +37,15 @@ class DeleteAccountOtpRepository extends RestfulApiViewModel implements IOtpRepo ...@@ -34,10 +37,15 @@ class DeleteAccountOtpRepository extends RestfulApiViewModel implements IOtpRepo
@override @override
Future<int?> resendOtp() async { Future<int?> resendOtp() async {
// showLoading(); showLoading();
// return client.resendOTP(mfaToken).then((value) { client.requestOtpDeleteAccount().then((value) {
// hideLoading(); hideLoading();
// return value.data?.otpTtl; if (value.isSuccess) {
// }); otpTtl = value.data?.resendAfterSecond ?? Constants.otpTtl;
} else {
final mgs = value.errorMessage ?? Constants.commonError;
Get.snackbar("Thông báo", mgs);
}
});
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment