Skip to content

Commit e3ae13e

Browse files
committed
feat(flipcash): add success modals to single verification flows
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 111ee98 commit e3ae13e

File tree

4 files changed

+74
-20
lines changed

4 files changed

+74
-20
lines changed

apps/flipcash/core/src/main/res/values/strings.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,25 @@
329329
<string name="error_title_failedToSendCodeToEmail">Failed To Send</string>
330330
<string name="error_description_failedToSendCodeToEmail">Something went wrong. Please ensure that your email address is entered correctly</string>
331331

332+
<string name="prompt_title_phoneVerifiedSuccessfully">Verification Successful</string>
333+
<string name="prompt_description_phoneVerifiedSuccessfully">Your phone number has been successfully linked to your profile</string>
334+
<string name="prompt_title_emailVerifiedSuccessfully">Verification Successful</string>
335+
<string name="prompt_description_emailVerifiedSuccessfully">Your email address has been successfully linked to your profile</string>
336+
<string name="prompt_title_phoneUnlinked">Phone Number Unlinked</string>
337+
<string name="prompt_description_phoneUnlinked">Your phone number has been successfully unlinked from your profile</string>
338+
<string name="prompt_title_emailUnlinked">Email Address Unlinked</string>
339+
<string name="prompt_description_emailUnlinked">Your email address has been successfully unlinked from your profile</string>
340+
341+
<string name="error_title_failedToUnlinkEmail">Unable To Unlink Email Address</string>
342+
<string name="error_description_failedToUnlinkEmailNonePresent">No email is linked to your profile</string>
343+
<string name="error_description_failedToUnlinkEmail">Unable to unlink your email. Please try again</string>
344+
<string name="error_title_failedToUnlinkPhone">Unable To Unlink Phone Number</string>
345+
<string name="error_description_failedToUnlinkPhoneNonePresent">No phone number is linked to your profile</string>
346+
<string name="error_description_failedToUnlinkPhone">Unable to unlink your phone number. Please try again</string>
347+
348+
<string name="action_unlinkPhone">Unlink Phone</string>
349+
<string name="action_unlinkEmail">Unlink Email</string>
350+
332351
<string name="title_email">Email</string>
333352
<string name="action_openMail">Open Mail</string>
334353
<string name="title_checkYourInbox">Check your inbox</string>

apps/flipcash/features/contact-verification/src/main/kotlin/com/flipcash/app/contact/verification/VerificationFlowScreen.kt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.CompositionLocalProvider
66
import androidx.compose.runtime.remember
77
import androidx.compose.runtime.staticCompositionLocalOf
8+
import androidx.compose.ui.platform.LocalContext
89
import cafe.adriel.voyager.core.annotation.ExperimentalVoyagerApi
910
import cafe.adriel.voyager.core.lifecycle.LifecycleEffectOnce
1011
import cafe.adriel.voyager.core.registry.ScreenRegistry
@@ -18,6 +19,9 @@ import com.flipcash.app.contact.verification.email.EmailVerificationScreen
1819
import com.flipcash.app.contact.verification.phone.PhoneVerificationScreen
1920
import com.flipcash.app.core.NavScreenProvider
2021
import com.flipcash.app.core.verification.email.EmailDeeplinkOrigin
22+
import com.flipcash.features.contact.verification.R
23+
import com.getcode.manager.BottomBarAction
24+
import com.getcode.manager.BottomBarManager
2125
import com.getcode.navigation.core.LocalCodeNavigator
2226
import com.getcode.navigation.modal.ModalScreen
2327
import kotlinx.parcelize.IgnoredOnParcel
@@ -29,6 +33,7 @@ class VerificationFlowScreen(
2933
private val target: NavScreenProvider? = null,
3034
private val includePhone: Boolean = true,
3135
private val includeEmail: Boolean = true,
36+
private val showSuccess: Boolean = target == null && (includePhone xor includeEmail),
3237
private val emailAddress: String? = null,
3338
private val emailVerificationCode: String? = null,
3439
): ModalScreen, Parcelable {
@@ -39,12 +44,41 @@ class VerificationFlowScreen(
3944
@Composable
4045
override fun ModalContent() {
4146
val codeNavigator = LocalCodeNavigator.current
42-
43-
fun goToTargetOrReturn() {
47+
val context = LocalContext.current
48+
fun showSuccess() {
49+
if (includePhone) {
50+
BottomBarManager.showMessage(
51+
title = context.getString(R.string.prompt_title_phoneVerifiedSuccessfully),
52+
subtitle = context.getString(R.string.prompt_description_phoneVerifiedSuccessfully),
53+
actions = listOf(
54+
BottomBarAction(text = context.getString(android.R.string.ok))
55+
),
56+
type = BottomBarManager.BottomBarMessageType.SUCCESS,
57+
) {
58+
codeNavigator.pop()
59+
}
60+
} else {
61+
BottomBarManager.showMessage(
62+
title = context.getString(R.string.prompt_title_emailVerifiedSuccessfully),
63+
subtitle = context.getString(R.string.prompt_description_emailVerifiedSuccessfully),
64+
actions = listOf(
65+
BottomBarAction(text = context.getString(android.R.string.ok))
66+
),
67+
type = BottomBarManager.BottomBarMessageType.SUCCESS,
68+
) {
69+
codeNavigator.pop()
70+
}
71+
}
72+
}
73+
fun goToTargetOrReturn(wasSuccessful: Boolean) {
4474
if (target != null) {
4575
codeNavigator.replace(ScreenRegistry.get(target))
4676
} else {
47-
codeNavigator.pop()
77+
if (wasSuccessful && showSuccess) {
78+
showSuccess()
79+
} else {
80+
codeNavigator.pop()
81+
}
4882
}
4983
}
5084

@@ -55,7 +89,7 @@ class VerificationFlowScreen(
5589

5690
val screens = buildScreenSet(includePhone, includeEmail, emailAddress, emailVerificationCode)
5791
if (screens.isEmpty()) {
58-
goToTargetOrReturn()
92+
goToTargetOrReturn(false)
5993
return
6094
}
6195

@@ -69,11 +103,11 @@ class VerificationFlowScreen(
69103
if (includeEmail) {
70104
navigator.push(EmailVerificationScreen())
71105
} else {
72-
goToTargetOrReturn()
106+
goToTargetOrReturn(wasSuccessful = true)
73107
}
74108
}
75109
VerificationFlowStep.Email -> {
76-
goToTargetOrReturn()
110+
goToTargetOrReturn(wasSuccessful = true)
77111
}
78112
}
79113
}

apps/flipcash/features/lab/src/main/kotlin/com/flipcash/app/lab/internal/LabsScreenContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
4444
modifier = Modifier
4545
.fillMaxWidth()
4646
.padding(horizontal = CodeTheme.dimens.inset),
47-
text = "Unlink Phone",
47+
text = stringResource(R.string.action_unlinkPhone),
4848
buttonState = ButtonState.Subtle,
4949
onClick = viewModel::unlinkPhone
5050
)
@@ -53,7 +53,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
5353
modifier = Modifier
5454
.fillMaxWidth()
5555
.padding(horizontal = CodeTheme.dimens.inset),
56-
text = "Unlink Email",
56+
text = stringResource(R.string.action_unlinkEmail),
5757
buttonState = ButtonState.Subtle,
5858
onClick = viewModel::unlinkEmail
5959
)

apps/flipcash/features/lab/src/main/kotlin/com/flipcash/app/lab/internal/LabsScreenViewModel.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.flipcash.app.lab.internal
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import com.flipcash.features.lab.R
56
import com.flipcash.services.controllers.ContactVerificationController
67
import com.flipcash.services.models.ContactMethod
78
import com.flipcash.services.user.AuthState
@@ -34,22 +35,22 @@ class LabsScreenViewModel @Inject constructor(
3435
val email = userManager.profile?.verifiedEmailAddress
3536
if (email == null) {
3637
BottomBarManager.showError(
37-
title = "Unable to Unlink Email Address",
38-
message = "No email is linked to your profile"
38+
title = resources.getString(R.string.error_title_failedToUnlinkEmail),
39+
message = resources.getString(R.string.error_description_failedToUnlinkEmailNonePresent)
3940
)
4041
return@launch
4142
}
4243
val method = ContactMethod.Email(email)
4344
contactController.unlink(method)
4445
.onFailure {
4546
BottomBarManager.showError(
46-
title = "Something Went Wrong",
47-
message = "Unable to unlink your email. Please try again"
47+
title = resources.getString(R.string.error_title_failedToUnlinkEmail),
48+
message = resources.getString(R.string.error_description_failedToUnlinkEmail)
4849
)
4950
}.onSuccess {
5051
BottomBarManager.showMessage(
51-
title = "Success",
52-
subtitle = "Your email has been unlinked",
52+
title = resources.getString(R.string.prompt_title_emailUnlinked),
53+
subtitle = resources.getString(R.string.prompt_description_emailUnlinked),
5354
actions = listOf(
5455
BottomBarAction(text = resources.getString(android.R.string.ok))
5556
),
@@ -62,22 +63,22 @@ class LabsScreenViewModel @Inject constructor(
6263
val phone = userManager.profile?.verifiedPhoneNumber
6364
if (phone == null) {
6465
BottomBarManager.showError(
65-
title = "Unable to Unlink Phone Number",
66-
message = "No phone number is linked to your profile"
66+
title = resources.getString(R.string.error_title_failedToUnlinkPhone),
67+
message = resources.getString(R.string.error_description_failedToUnlinkPhoneNonePresent)
6768
)
6869
return@launch
6970
}
7071
val method = ContactMethod.Phone(phone)
7172
contactController.unlink(method)
7273
.onFailure {
7374
BottomBarManager.showError(
74-
title = "Something Went Wrong",
75-
message = "Unable to unlink your phone number. Please try again"
75+
title = resources.getString(R.string.error_title_failedToUnlinkPhone),
76+
message = resources.getString(R.string.error_description_failedToUnlinkPhone)
7677
)
7778
}.onSuccess {
7879
BottomBarManager.showMessage(
79-
title = "Success",
80-
subtitle = "Your phone number has been unlinked",
80+
title = resources.getString(R.string.prompt_title_phoneUnlinked),
81+
subtitle = resources.getString(R.string.prompt_description_phoneUnlinked),
8182
actions = listOf(
8283
BottomBarAction(text = resources.getString(android.R.string.ok))
8384
),

0 commit comments

Comments
 (0)