Skip to content

Commit

Permalink
feature(mobile): add delete account
Browse files Browse the repository at this point in the history
  • Loading branch information
thaidmfinnick committed Jan 2, 2025
1 parent 7d7124e commit 1a0edba
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 30 deletions.
1 change: 1 addition & 0 deletions mobile/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ app.*.map.json

pubspec.lock
*/Podfile.lock
/android/key.properties

# FVM Version Cache
.fvm/
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class AuthSubscription extends AuthenticationEvent {}

class LogoutRequest extends AuthenticationEvent {}

class DeleteAccount extends AuthenticationEvent {}

class AutoLogin extends AuthenticationEvent {}

class UpdateInfo extends AuthenticationEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ class AuthenticationApi {
const String url = "/user/logout";
await dioConfigInterceptor.post(url, data: {"user_id": userId});
}

static Future<Map> deleteUser() async {
const String url = "/user/delete_user";
final Response response = await dioConfigInterceptor.post(url);
return response.data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ class AuthRepository {
}
}

static Future<void> deleteAccount() async {
try {
final Map res = await AuthenticationApi.deleteUser();
final bool isSuccess = res["success"];
if (isSuccess) {
await AuthRepository.logoutNoCredentials();
_controller.add(AuthenticationStatus.unauthorized);
} else {
_controller.add(AuthenticationStatus.authorized);
// _controller.add(AuthenticationStatus.authorized);
}
} catch (e) {
print('gndkjf:$e');
_controller.add(AuthenticationStatus.error);
}
}

static Future<void> logout() async {
await AuthRepository.logoutNoCredentials();
// await AuthenticationApi.logout(userId);
Expand Down
9 changes: 9 additions & 0 deletions mobile/lib/features/user/view/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ class _UserInfoState extends State<UserInfo> {
context.read<AuthenticationBloc>().add(LogoutRequest());
},
),
NavigationButton(
text: "Xóa tài khoản",
isWarning: true,
icon: PhosphorIcons.regular.userMinus,
onTap: () {
context.read<AuthenticationBloc>().add(DeleteAccount());
// context.read<AuthenticationBloc>().add(LogoutRequest());
},
),
],
),
),
Expand Down
118 changes: 118 additions & 0 deletions mobile/lib/widgets/confirm_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import 'package:flutter/material.dart';

class ConfirmCard extends StatelessWidget {
const ConfirmCard({
super.key,
this.user,
this.bigIcon,
required this.title,
required this.subtitle,
required this.dangerousTextInButton,
this.onClick,
});

final Map? user;
final Widget? bigIcon;
final String title;
final String subtitle;
final String dangerousTextInButton;
final VoidCallback? onClick;

// use with showDialog, showCupertinoDialog

@override
Widget build(BuildContext context) {
const Color backgroundColorHeader = Colors.white;
const Color colorBackButton = Color(0xFF1D2939);

return Material(
color : Colors.transparent,
child: Dialog(
child: Wrap(
children: [
Container(
// height: 270,
width: 327,
decoration: BoxDecoration(
color: backgroundColorHeader,
borderRadius: BorderRadius.circular(8)
),
padding: const EdgeInsets.only(left: 20, right: 20, top: 16, bottom: 10),
child: Column(children: [
// else if (bigIcon != null) bigIcon!
// else Container(),

const SizedBox(height: 14),

Text(title,
style: const TextStyle(fontSize: 16,
fontWeight: FontWeight.w700,
)),
const SizedBox(height: 12),
Text(subtitle,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Color(0xFF667085)
),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),

SizedBox(
height: 44,
width: 300,
child: ElevatedButton(
onPressed: () {
if (onClick != null) {
onClick!.call();
}
},
style: ButtonStyle(
backgroundColor: const WidgetStatePropertyAll(Color(0xFFFF3048)),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))
),
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 10))
),
child: Text(dangerousTextInButton,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
)
)
)
),
const SizedBox(height: 14),

SizedBox(
height: 44,
width: 300,
child: TextButton(
onPressed: () {
Navigator.pop(context);
},
style: ButtonStyle(
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))
),
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 10))
),
child: const Text("Hủy",
style: TextStyle(
color: colorBackButton,
fontSize: 16,
fontWeight: FontWeight.w600,
)
),
),
),
]),
),
],
),
),
);
}
}
79 changes: 49 additions & 30 deletions mobile/lib/widgets/navigation_button.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cecr_unwomen/widgets/confirm_card.dart';
import 'package:flutter/material.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';
Expand Down Expand Up @@ -61,38 +62,56 @@ class NavigationButton extends StatelessWidget {
margin: const EdgeInsets.only(bottom: 12),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () => onTap == null ? null : onTap!(),
onTap: () async {
if (isWarning) {
final bool? isConfirm = await showDialog(
context: context,
builder: (context) => ConfirmCard(
title: "Xác nhận ${text.toLowerCase()}",
subtitle: "Bạn có chắc chắn muốn thực hiện hành động này?",
dangerousTextInButton: "Xác nhận",
onClick: () {
Navigator.pop(context, true);
},
),
);
if (isConfirm == null) return;
onTap?.call();
} else {
onTap?.call();
}
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Row(
crossAxisAlignment: subTitleWidget != null ? CrossAxisAlignment.start : CrossAxisAlignment.center,
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: iconBgColor,
shape: BoxShape.circle,
),
child: Icon(icon, size: 20, color: iconColor),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Row(
crossAxisAlignment: subTitleWidget != null ? CrossAxisAlignment.start : CrossAxisAlignment.center,
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: iconBgColor,
shape: BoxShape.circle,
),
const SizedBox(width: 14),
Flexible(
child: subTitleWidget != null
? Column(
children: [
option,
subTitleWidget ?? Container(),
],
)
: option,
),
],
)),
child: Icon(icon, size: 20, color: iconColor),
),
const SizedBox(width: 14),
Flexible(
child: subTitleWidget != null
? Column(
children: [
option,
subTitleWidget ?? Container(),
],
)
: option,
),
],
)),
),
),
);
Expand Down

0 comments on commit 1a0edba

Please sign in to comment.