Skip to content

Commit

Permalink
Merge pull request #12310 from woocommerce/12269-open-zendesk-support…
Browse files Browse the repository at this point in the history
…-form

[Woo POS] Open Zendesk support form from toolbar
  • Loading branch information
samiuelson authored Aug 16, 2024
2 parents b25be4a + 20e5be1 commit 3107fb1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ enum class HelpOrigin(private val stringValue: String) {
ORDERS_LIST("origin:orders-list"),
BLAZE_CAMPAIGN_CREATION("origin:blaze-native-campaign-creation"),
CONNECTIVITY_TOOL("origin:connectivity-tool"),
APPLICATION_PASSWORD_TUTORIAL("origin:application-password-tutorial");
APPLICATION_PASSWORD_TUTORIAL("origin:application-password-tutorial"),
POS("origin:point-of-sale");

override fun toString(): String {
return stringValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.Conne
import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.MenuItemClicked
import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnOutsideOfToolbarMenuClicked
import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnToolbarMenuClicked
import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
Expand All @@ -26,6 +27,7 @@ import javax.inject.Inject
class WooPosToolbarViewModel @Inject constructor(
private val cardReaderFacade: WooPosCardReaderFacade,
private val childrenToParentEventSender: WooPosChildrenToParentEventSender,
private val getSupportFacade: WooPosGetSupportFacade,
) : ViewModel() {
private val _state = MutableStateFlow(
WooPosToolbarState(
Expand Down Expand Up @@ -75,7 +77,7 @@ class WooPosToolbarViewModel @Inject constructor(
hideMenu()

when (event.menuItem.title) {
R.string.woopos_get_support_title -> TODO()
R.string.woopos_get_support_title -> getSupportFacade.openSupportForm()
R.string.woopos_exit_confirmation_title ->
viewModelScope.launch {
childrenToParentEventSender.sendToParent(ChildToParentEvent.ExitPosClicked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade
import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme
import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

Expand All @@ -25,12 +26,16 @@ class WooPosActivity : AppCompatActivity() {
@Inject
lateinit var wooPosCardReaderFacade: WooPosCardReaderFacade

@Inject
lateinit var wooPosGetSupportFacade: WooPosGetSupportFacade

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

lifecycle.addObserver(wooPosCardReaderFacade)
lifecycle.addObserver(wooPosGetSupportFacade)

setContent {
WooPosTheme {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.woocommerce.android.ui.woopos.support

import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.woocommerce.android.support.help.HelpOrigin
import com.woocommerce.android.support.requests.SupportRequestFormActivity
import dagger.hilt.android.scopes.ActivityRetainedScoped
import javax.inject.Inject

@ActivityRetainedScoped
class WooPosGetSupportFacade @Inject constructor() : DefaultLifecycleObserver {
private var activity: AppCompatActivity? = null

override fun onCreate(owner: LifecycleOwner) {
this.activity = owner as AppCompatActivity
}

override fun onDestroy(owner: LifecycleOwner) {
this.activity = null
}

fun openSupportForm() {
val intent = SupportRequestFormActivity.createIntent(
context = activity!!,
origin = HelpOrigin.POS,
extraTags = ArrayList()
)
activity!!.startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.woocommerce.android.cardreader.connection.CardReaderStatus
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade
import com.woocommerce.android.ui.woopos.home.ChildToParentEvent
import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender
import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade
import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
Expand All @@ -26,6 +27,7 @@ class WooPosToolbarViewModelTest {
private val cardReaderFacade: WooPosCardReaderFacade = mock {
onBlocking { readerStatus }.thenReturn(flowOf(CardReaderStatus.NotConnected()))
}
private val getSupportFacade: WooPosGetSupportFacade = mock()
private val childrenToParentEventSender: WooPosChildrenToParentEventSender = mock()

@Test
Expand Down Expand Up @@ -165,8 +167,25 @@ class WooPosToolbarViewModelTest {
verify(cardReaderFacade, times(3)).connectToReader()
}

@Test
fun `when get support clicked, then should open support form`() {
val viewModel = createViewModel()

viewModel.onUiEvent(
WooPosToolbarUIEvent.MenuItemClicked(
WooPosToolbarState.Menu.MenuItem(
title = R.string.woopos_get_support_title,
icon = R.drawable.woopos_ic_get_support,
)
)
)

verify(getSupportFacade).openSupportForm()
}

private fun createViewModel() = WooPosToolbarViewModel(
cardReaderFacade,
childrenToParentEventSender
childrenToParentEventSender,
getSupportFacade,
)
}

0 comments on commit 3107fb1

Please sign in to comment.