Skip to content

Commit

Permalink
MBL-1477 Confirm address CTA (#2061)
Browse files Browse the repository at this point in the history
* MBL-1477 Confirm address CTA

* Lint and comments

* Fix merge conflicts

* Resolve conflicts with Leigh's message creator PR

* Remove unused scaffoldstate

* Remove unused coroutinescope

* Fix test

* Add FPO string
  • Loading branch information
ycheng-kickstarter authored Jun 24, 2024
1 parent 207fb92 commit d7220c1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class PledgedProjectsOverviewActivity : AppCompatActivity() {
errorSnackBarHostState = snackbarHostState,
ppoCards = ppoCardPagingSource,
totalAlerts = totalAlerts.value,
onAddressConfirmed = { viewModel.showSnackbarAndRefreshCardsList() },
onSendMessageClick = { projectName -> viewModel.onMessageCreatorClicked(projectName) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import androidx.compose.material.SnackbarHost
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
Expand All @@ -25,6 +29,7 @@ import androidx.paging.PagingData
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import com.kickstarter.R
import com.kickstarter.ui.compose.designsystem.KSAlertDialog
import com.kickstarter.ui.compose.designsystem.KSTheme
import com.kickstarter.ui.compose.designsystem.KSTheme.colors
import com.kickstarter.ui.compose.designsystem.KSTheme.dimensions
Expand All @@ -50,6 +55,7 @@ private fun PledgedProjectsOverviewScreenPreview() {
ppoCards = ppoCardList,
totalAlerts = 10,
onBackPressed = {},
onAddressConfirmed = {},
onSendMessageClick = {},
errorSnackBarHostState = SnackbarHostState()
)
Expand All @@ -61,12 +67,16 @@ private fun PledgedProjectsOverviewScreenPreview() {
fun PledgedProjectsOverviewScreen(
modifier: Modifier,
onBackPressed: () -> Unit,
onAddressConfirmed: () -> Unit,
lazyColumnListState: LazyListState,
errorSnackBarHostState: SnackbarHostState,
ppoCards: LazyPagingItems<PPOCardDataMock>,
totalAlerts: Int = 0,
onSendMessageClick: (projectName: String) -> Unit
) {
val openConfirmAddressAlertDialog = remember { mutableStateOf(false) }
var confirmedAddress by remember { mutableStateOf("") } // TODO: This is either the original shipping address or the user-edited address

Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
Expand Down Expand Up @@ -128,7 +138,10 @@ fun PledgedProjectsOverviewScreen(
shippingAddress = it.shippingAddress,
showBadge = it.showBadge,
onActionButtonClicked = { },
onSecondaryActionButtonClicked = { },
onSecondaryActionButtonClicked = {
confirmedAddress = it.shippingAddress
openConfirmAddressAlertDialog.value = true
},
timeNumberForAction = it.timeNumberForAction
)
}
Expand All @@ -140,6 +153,28 @@ fun PledgedProjectsOverviewScreen(
}
}
}

when {
openConfirmAddressAlertDialog.value -> {
KSAlertDialog(
setShowDialog = { openConfirmAddressAlertDialog.value = it },
headlineText = "Confirm your address:",
bodyText = confirmedAddress,
leftButtonText = "Cancel",
leftButtonAction = { openConfirmAddressAlertDialog.value = false },
rightButtonText = "Confirm",
rightButtonAction = {
openConfirmAddressAlertDialog.value = false

// Call confirm address API
// TODO: MBL-1556 Add network call to confirm address

// Show snackbar and refresh list
onAddressConfirmed()
}
)
}
}
}

enum class PledgedProjectsOverviewScreenTestTag {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class PledgedProjectsOverviewViewModel(environment: Environment) : ViewModel() {
val ppoCardsState: StateFlow<PagingData<PPOCardDataMock>> = ppoCards.asStateFlow()
val totalAlertsState: StateFlow<Int> = totalAlerts.asStateFlow()

fun showSnackbarAndRefreshCardsList() {
snackbarMessage.invoke(R.string.address_confirmed_snackbar_text)

// TODO: MBL-1556 refresh the PPO list (i.e. requery the PPO list).
}

val projectFlow: SharedFlow<Project>
get() = mutableProjectFlow
.asSharedFlow()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@
<!-- PPO Mock Strings -->
<string name="project_alerts_fpo">Project Alerts</string>
<string name="alerts_fpo">Alerts (%1$s)</string>
<string name="address_confirmed_snackbar_text">Address confirmed! Need to change your address before it locks? Visit your backing details on our website.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class PledgedProjectsOverviewScreenTest : KSRobolectricTestCase() {
lazyColumnListState = rememberLazyListState(),
ppoCards = ppoCardList,
errorSnackBarHostState = SnackbarHostState(),
onSendMessageClick = {}
onSendMessageClick = {},
onAddressConfirmed = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() {
R.string.Something_went_wrong_please_try_again
)
}

@Test
fun `emits_snackbar_when_confirms_address`() =
runTest {
var snackbarAction = 0
viewModel.provideSnackbarMessage { snackbarAction = it }
viewModel.showSnackbarAndRefreshCardsList()

// Should equal address confirmed string id
assertEquals(
snackbarAction,
R.string.address_confirmed_snackbar_text
)
}
}

0 comments on commit d7220c1

Please sign in to comment.