Skip to content

Commit

Permalink
fix permission denied error while delete account
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Jul 16, 2024
1 parent c90c267 commit d9867bc
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 43 deletions.
2 changes: 2 additions & 0 deletions app/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
"settings_other_option_contact_support_text": "Contact support",
"settings_other_option_about_us_text": "About us",
"settings_other_option_sign_out_text": "Sign out",
"settings_sign_out_alert_title": "See you soon!",
"settings_sign_out_alert_description": "Are you sure you want to sign out?",

"message_add_member_to_send_message_title": "Add members to send messages",
"message_add_member_to_send_message_subtitle": "At least one member needs to join your space to be able to chat.",
Expand Down
9 changes: 8 additions & 1 deletion app/lib/ui/components/profile_picture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ProfileImage extends StatefulWidget {
final String firstLetter;
final TextStyle? style;
final Color? backgroundColor;
final Color? borderColor;

const ProfileImage({
super.key,
Expand All @@ -18,6 +19,7 @@ class ProfileImage extends StatefulWidget {
required this.firstLetter,
this.style,
this.backgroundColor,
this.borderColor,
});

@override
Expand All @@ -42,7 +44,12 @@ class _ProfileImageState extends State<ProfileImage> {
fit: BoxFit.cover,
)
: Container(
color: widget.backgroundColor ?? context.colorScheme.containerInverseHigh,
decoration: BoxDecoration(
color: widget.backgroundColor ??
context.colorScheme.containerInverseHigh,
border: Border.all(width: 0.5, color: widget.borderColor ?? Colors.transparent),
borderRadius: BorderRadius.circular(widget.size / 2),
),
child: Center(
child: Text(
widget.firstLetter,
Expand Down
37 changes: 29 additions & 8 deletions app/lib/ui/flow/home/components/home_top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {

late AnimationController _animationController;
late Animation<double> _animation;
late AnimationController _buttonController;

@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 500),
duration: const Duration(milliseconds: 150),
);

_buttonController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
upperBound: 0.5,
);

_animation = CurvedAnimation(
Expand All @@ -57,14 +64,23 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
@override
void dispose() {
_animationController.dispose();
_buttonController.dispose();
super.dispose();
}

void performAnimation() {
if (expand) {
_animationController.forward();
} else {
_animationController.reverse();
_animationController.reverse(from: 1.0).orCancel;
}
}

void performArrowButtonAnimation() {
if (expand) {
_buttonController.reverse(from: 0.5);
} else {
_buttonController.forward(from: 0.0);
}
}

Expand Down Expand Up @@ -146,6 +162,7 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
setState(() {
expand = !expand;
performAnimation();
performArrowButtonAnimation();
});
},
child: Container(
Expand All @@ -172,12 +189,13 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
if (widget.fetchingInviteCode || (widget.selectedSpace == null && widget.loading)) ...[
const AppProgressIndicator(size: AppProgressIndicatorSize.small)
] else ...[
Icon(
expand
? Icons.keyboard_arrow_down_rounded
: Icons.keyboard_arrow_up_rounded,
color: context.colorScheme.textPrimary,
),
RotationTransition(
turns: Tween(begin: 0.0, end: 1.0).animate(_buttonController),
child: Icon(
Icons.keyboard_arrow_up_rounded,
color: context.colorScheme.textPrimary,
),
)
],
],
),
Expand Down Expand Up @@ -253,6 +271,9 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
setState(() {
selectedIndex = index;
widget.onSpaceItemTap(space);
expand = false;
performAnimation();
performArrowButtonAnimation();
});
},
child: Container(
Expand Down
10 changes: 6 additions & 4 deletions app/lib/ui/flow/setting/profile/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
context, context.l10n.edit_profile_email_title, state.email, enabled: state.enableEmail),
const SizedBox(height: 16),
_textFields(
context, context.l10n.edit_profile_phone_title, state.phone, enabled: state.enablePhone),
context, context.l10n.edit_profile_phone_title, state.phone, enabled: state.enablePhone, isPhoneNumber: true),
],
),
_deleteAccountButton(context),
_deleteAccountButton(context, state),
],
);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
}

Widget _textFields(BuildContext context, String title,
TextEditingController controller, {bool enabled = true}) {
TextEditingController controller, {bool enabled = true, bool isPhoneNumber = false}) {
return AppTextField(
controller: controller,
label: title,
Expand All @@ -258,10 +258,11 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
),
enabled: enabled,
onChanged: (text) => notifier.onChange(),
keyboardType: isPhoneNumber ? TextInputType.number : TextInputType.name,
);
}

Widget _deleteAccountButton(BuildContext context) {
Widget _deleteAccountButton(BuildContext context, EditProfileViewState state) {
return BottomStickyOverlay(
child: PrimaryButton(
context.l10n.edit_profile_delete_account_title,
Expand All @@ -271,6 +272,7 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
showIcon: true,
foreground: context.colorScheme.alert,
background: context.colorScheme.containerLow,
progress: state.deletingAccount,
onPressed: () {
showConfirmation(
context,
Expand Down
12 changes: 6 additions & 6 deletions app/lib/ui/flow/setting/profile/profile_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ class EditProfileViewNotifier extends StateNotifier<EditProfileViewState> {
lastName: TextEditingController(text: user?.last_name),
email: TextEditingController(text: user?.email),
phone: TextEditingController(text: user?.phone),
enableEmail: user?.auth_type == LOGIN_TYPE_GOOGLE,
enablePhone: user?.auth_type == LOGIN_TYPE_PHONE,
enableEmail: user?.auth_type == LOGIN_TYPE_PHONE,
enablePhone: user?.auth_type == LOGIN_TYPE_GOOGLE,
profileUrl: user?.profile_image ?? '',
));

void deleteAccount() {
void deleteAccount() async {
try {
state = state.copyWith(deletingAccount: true);
spaceService.deleteUserSpaces();
authService.deleteAccount();
state = state.copyWith(deletingAccount: true, accountDeleted: true);
await spaceService.deleteUserSpaces();
await authService.deleteAccount(currentUserId: user?.id);
state = state.copyWith(deletingAccount: false, accountDeleted: true);
} catch (error, stack) {
logger.e(
'EditProfileViewState: error while delete account',
Expand Down
16 changes: 12 additions & 4 deletions app/lib/ui/flow/setting/setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:yourspace_flutter/ui/components/resume_detector.dart';
import 'package:yourspace_flutter/ui/flow/setting/setting_view_model.dart';

import '../../../gen/assets.gen.dart';
import '../../components/alert.dart';

class SettingScreen extends ConsumerStatefulWidget {
const SettingScreen({super.key});
Expand All @@ -37,7 +38,6 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
title: context.l10n.settings_title,
body: ResumeDetector(
onResume: () {
notifier.getUser();
notifier.getUserSpace();
}, child: _body(context, state)),
);
Expand Down Expand Up @@ -81,7 +81,7 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
const SizedBox(height: 16),
Container(
decoration: BoxDecoration(
color: context.colorScheme.containerLowOnSurface,
color: context.colorScheme.containerNormal,
borderRadius: BorderRadius.circular(16),
),
padding: const EdgeInsets.all(16),
Expand All @@ -91,7 +91,9 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
profileImageUrl: profileImageUrl,
firstLetter: firstLetter,
style: AppTextStyle.header3
.copyWith(color: context.colorScheme.textPrimaryDark),
.copyWith(color: context.colorScheme.textPrimary),
backgroundColor: context.colorScheme.containerHigh,
borderColor: context.colorScheme.textSecondary,
),
const SizedBox(width: 16),
Text(
Expand Down Expand Up @@ -220,7 +222,13 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
title: context.l10n.settings_other_option_sign_out_text,
icon: Assets.images.icSignOut,
onTap: () {
notifier.signOut();
showConfirmation(
context,
confirmBtnText: context.l10n.settings_other_option_sign_out_text,
title: context.l10n.settings_sign_out_alert_title,
message: context.l10n.settings_sign_out_alert_description,
onConfirm: () => notifier.signOut(),
);
}),
],
);
Expand Down
17 changes: 11 additions & 6 deletions app/lib/ui/flow/space/join/join_space_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
),
),
const SizedBox(height: 40),
_inviteCode(context),
_inviteCode(context, state),
const SizedBox(height: 40),
Text(
context.l10n.join_space_get_code_from_space_text,
Expand All @@ -81,7 +81,7 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
]);
}

Widget _inviteCode(BuildContext context) {
Widget _inviteCode(BuildContext context, JoinSpaceViewState state) {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
double containerWidth = (constraints.maxWidth - 48) / 7;
Expand All @@ -90,7 +90,7 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (int i = 0; i < 3; i++) ...[
_buildCodeBox(context, containerWidth, i),
_buildCodeBox(context, containerWidth, i, state),
const SizedBox(width: 4),
],
Text(
Expand All @@ -101,7 +101,7 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
),
const SizedBox(width: 8),
for (int i = 3; i < 6; i++) ...[
_buildCodeBox(context, containerWidth, i),
_buildCodeBox(context, containerWidth, i, state),
const SizedBox(width: 4),
],
],
Expand All @@ -110,7 +110,7 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
);
}

Widget _buildCodeBox(BuildContext context, double width, int index) {
Widget _buildCodeBox(BuildContext context, double width, int index, JoinSpaceViewState state) {
return Container(
width: width,
height: 64,
Expand Down Expand Up @@ -140,7 +140,12 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
if (text.isEmpty) {
if (index > 0) _focusNodes[index - 1].requestFocus();
} else {
if (index < 5) _focusNodes[index + 1].requestFocus();
if (index < 5) {
_focusNodes[index + 1].requestFocus();
} else {
final inviteCode = _controllers.map((controller) => controller.text.trim()).join();
notifier.joinSpace(inviteCode);
}
}
_updateJoinSpaceButtonState();
},
Expand Down
2 changes: 1 addition & 1 deletion app/lib/ui/flow/space/join/join_space_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class JoinSpaceViewNotifier extends StateNotifier<JoinSpaceViewState> {

Future<void> joinSpace(String code) async {
try {
state = state.copyWith(verifying: true);
state = state.copyWith(verifying: true, errorInvalidInvitationCode: false, alreadySpaceMember: false);
final invitation = await spaceInvitationService.getInvitation(code);
if (invitation == null) {
state =
Expand Down
8 changes: 6 additions & 2 deletions data/lib/api/auth/api_user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ApiUserService {
}

Future<void> deleteUser(String userId) async {
await _userRef.doc(userId).delete();
await _db.collection("users").doc(userId).delete();
}

Future<void> registerFcmToken(String userId, String token) async {
Expand Down Expand Up @@ -165,12 +165,16 @@ class ApiUserService {
}

Future<void> signOut() async {
clearPreference();
await FirebaseAuth.instance.signOut();
}

void clearPreference() {
// locationManager.stopLocationTracking();
userJsonNotifier.state = null;
userSessionJsonNotifier.state = null;
onBoardNotifier.state = false;
currentUserSpaceId.state = null;
FirebaseAuth.instance.signOut();
// locationManager.stopService();
}
}
6 changes: 3 additions & 3 deletions data/lib/service/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class AuthService {
return userService.getUserStream(currentUserId ?? _currentUser?.id ?? '');
}

Future<void> deleteAccount() {
userService.signOut();
return userService.deleteUser(_currentUser?.id ?? '');
Future<void> deleteAccount({String? currentUserId}) async {
await userService.deleteUser(currentUserId ?? _currentUser?.id ?? '');
userService.clearPreference();
}
}
1 change: 1 addition & 0 deletions data/lib/service/space_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class SpaceService {
Future<void> deleteUserSpaces() async {
final userId = currentUser?.id ?? '';
final allSpace = await getUserSpaces(userId);
if (allSpace.isEmpty) return;
final ownSpace = allSpace.where((space) => space?.admin_id == userId).toList();
final joinedSpace = allSpace.where((space) => space?.admin_id != userId).toList();

Expand Down
16 changes: 8 additions & 8 deletions style/lib/button/primary_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ class PrimaryButton extends StatelessWidget {
mainAxisSize: expanded ? MainAxisSize.max : MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Visibility(
visible: showIcon,
child: Padding(
padding: const EdgeInsets.only(right: 8),
child: Icon(
Icons.delete_outline_rounded, color: context.colorScheme.alert, size: 20,),
),
),
Visibility(
visible: progress,
child: Padding(
Expand All @@ -84,6 +76,14 @@ class PrimaryButton extends StatelessWidget {
),
),
),
Visibility(
visible: showIcon,
child: Padding(
padding: const EdgeInsets.only(right: 8),
child: Icon(
Icons.delete_outline_rounded, color: context.colorScheme.alert, size: 20,),
),
),
Text(
text,
style: AppTextStyle.button.copyWith(
Expand Down

0 comments on commit d9867bc

Please sign in to comment.