Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.woocommerce.android.R
import com.woocommerce.android.ui.bookings.filter.customer.BookingCustomerFilterPage
import com.woocommerce.android.ui.bookings.filter.type.BookingTypeFilterRoute
import com.woocommerce.android.ui.compose.component.Toolbar
import com.woocommerce.android.ui.compose.component.WCColoredButton
import com.woocommerce.android.ui.compose.preview.LightDarkThemePreviews
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsFilterOption

@Composable
fun BookingFilterListScreen(state: BookingFilterListUiState) {
Expand Down Expand Up @@ -128,7 +130,18 @@ private fun FiltersNavHost(
}
}
composable(BookingFilterPage.Customer.route) {
TODO()
BookingCustomerFilterPage { customer ->
customer.customerId?.let { id ->
state.onUpdateFilterOption(
BookingsFilterOption.Customer(
customerId = id,
customerName = "${customer.firstName} ${customer.lastName}".trim()
.ifBlank { customer.email }.orEmpty()
)
)
}
state.onClose()
}
}
composable(BookingFilterPage.ServiceEvent.route) {
TODO()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class BookingFilterListUiState(
val onClose: () -> Unit = {},
val onShowBookings: () -> Unit = {},
val openPage: (BookingFilterPage) -> Unit = {},
val onUpdateFilterOption: (BookingsFilterOption) -> Unit = {}
val onUpdateFilterOption: (BookingsFilterOption) -> Unit = {},
) {

val items: List<BookingFilterListItem> = availableBookingFilters().map { page ->
Expand Down Expand Up @@ -72,7 +72,7 @@ val BookingFilterPage.titleRes: Int
BookingFilterPage.AttendanceStatus -> R.string.bookings_filter_title_attendance_status
BookingFilterPage.PaymentStatus -> R.string.bookings_filter_title_payment_status
BookingFilterPage.BookingType -> R.string.bookings_filter_title_type
BookingFilterPage.Customer -> R.string.bookings_filter_customer_name
BookingFilterPage.Customer -> R.string.bookings_filter_customer
BookingFilterPage.Location -> R.string.bookings_filter_location
BookingFilterPage.DateTime -> R.string.bookings_filter_title_date
BookingFilterPage.ServiceEvent -> R.string.bookings_filter_title_service_event
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.woocommerce.android.ui.bookings.filter.customer

import androidx.compose.runtime.Composable
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import com.woocommerce.android.model.Order
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListSelectionScreen

@Composable
fun BookingCustomerFilterPage(
onCustomerSelected: (Order.Customer) -> Unit,
) {
val viewModel = hiltViewModel { factory: BookingCustomerFilterViewModel.Factory ->
factory.create(onCustomerSelected)
}

CustomerListSelectionScreen(
viewModel = viewModel,
handleInsets = false,
showToolbar = false
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.woocommerce.android.ui.bookings.filter.customer

import androidx.lifecycle.SavedStateHandle
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.model.Order
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListGetSupportedSearchModes
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListIsAdvancedSearchSupported
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListRepository
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListSelectionViewModel
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListViewModelMapper
import com.woocommerce.android.util.StringUtils
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dagger.hilt.android.lifecycle.HiltViewModel

@Suppress("LongParameterList")
@HiltViewModel(assistedFactory = BookingCustomerFilterViewModel.Factory::class)
class BookingCustomerFilterViewModel @AssistedInject constructor(
savedStateHandle: SavedStateHandle,
repository: CustomerListRepository,
mapper: CustomerListViewModelMapper,
isAdvancedSearchSupported: CustomerListIsAdvancedSearchSupported,
getSupportedSearchModes: CustomerListGetSupportedSearchModes,
analyticsTracker: AnalyticsTrackerWrapper,
stringUtils: StringUtils,
@Assisted private val onCustomerSelected: (Order.Customer) -> Unit
) : CustomerListSelectionViewModel(
savedStateHandle,
repository,
mapper,
isAdvancedSearchSupported,
getSupportedSearchModes,
analyticsTracker,
stringUtils
) {
override fun exitWithCustomer(customer: Order.Customer) {
this.onCustomerSelected.invoke(customer)
}

@AssistedFactory
interface Factory {
fun create(onCustomerSelected: (Order.Customer) -> Unit): BookingCustomerFilterViewModel
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CustomerListDialogFragment : DialogFragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
WooThemeWithBackground {
OrderCustomerListScreen(viewModel = viewModel, handleInsets = true)
CustomerListSelectionScreen(viewModel = viewModel, handleInsets = true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ import org.wordpress.android.fluxc.model.customer.WCCustomerModel
* bug https://issuetracker.google.com/issues/411868840 the insets are re-applied when the keyboard is shown.
*/
@Composable
fun OrderCustomerListScreen(
fun CustomerListSelectionScreen(
viewModel: CustomerListSelectionViewModel,
handleInsets: Boolean
handleInsets: Boolean,
showToolbar: Boolean = true
) {
val state by viewModel.viewState.observeAsState()
state?.let {
OrderCustomerListScreen(
CustomerListSelectionScreen(
state = it,
handleInsets = handleInsets,
showToolbar = showToolbar,
onNavigateBack = viewModel::onNavigateBack,
onAddCustomerClicked = viewModel::onAddCustomerClicked,
onCustomerSelected = viewModel::onCustomerSelected,
Expand All @@ -55,9 +57,10 @@ fun OrderCustomerListScreen(
}

@Composable
fun OrderCustomerListScreen(
private fun CustomerListSelectionScreen(
state: CustomerListViewState,
handleInsets: Boolean,
showToolbar: Boolean,
onNavigateBack: () -> Unit,
onAddCustomerClicked: () -> Unit,
onCustomerSelected: (WCCustomerModel) -> Unit,
Expand All @@ -68,12 +71,14 @@ fun OrderCustomerListScreen(
) {
Scaffold(
topBar = {
Toolbar(
title = stringResource(id = R.string.order_creation_add_customer),
navigationIcon = Icons.AutoMirrored.Filled.ArrowBack,
onNavigationButtonClick = onNavigateBack,
windowInsets = if (handleInsets) AppBarDefaults.topAppBarWindowInsets else WindowInsets(0),
)
if (showToolbar) {
Toolbar(
title = stringResource(id = R.string.order_creation_add_customer),
navigationIcon = Icons.AutoMirrored.Filled.ArrowBack,
onNavigationButtonClick = onNavigateBack,
windowInsets = if (handleInsets) AppBarDefaults.topAppBarWindowInsets else WindowInsets(0),
)
}
},
floatingActionButton = {
if (state.showFab) CustomerListAddCustomerButton(onAddCustomerClicked)
Expand Down Expand Up @@ -111,7 +116,7 @@ private fun CustomerListAddCustomerButton(onClick: () -> Unit) {
@Composable
fun OrderCustomerListScreenPreview() {
WooThemeWithBackground {
OrderCustomerListScreen(
CustomerListSelectionScreen(
state = CustomerListViewState(
searchHint = R.string.order_creation_customer_search_hint,
searchQuery = "",
Expand Down Expand Up @@ -171,6 +176,7 @@ fun OrderCustomerListScreenPreview() {
),
),
handleInsets = false,
showToolbar = true,
onNavigateBack = {},
onAddCustomerClicked = {},
onCustomerSelected = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.wordpress.android.fluxc.model.customer.WCCustomerModel
import javax.inject.Inject

@HiltViewModel
class CustomerListSelectionViewModel @Inject constructor(
open class CustomerListSelectionViewModel @Inject constructor(
savedState: SavedStateHandle,
private val repository: CustomerListRepository,
private val mapper: CustomerListViewModelMapper,
Expand Down Expand Up @@ -85,26 +85,30 @@ class CustomerListSelectionViewModel @Inject constructor(
val billingCountry = repository.getCountry(billingAddress.country)
val billingState = repository.getState(billingAddress.country, billingAddress.state)

triggerEvent(
CustomerSelected(
Order.Customer(
customerId = wcCustomer.remoteCustomerId.value,
firstName = wcCustomer.firstName,
lastName = wcCustomer.lastName,
email = wcCustomer.email,
billingAddress = mapper.mapFromOrderAddressToAddress(
billingAddress,
billingCountry,
billingState
),
shippingAddress = mapper.mapFromOrderAddressToAddress(
shippingAddress,
shippingCountry,
shippingState
),
username = wcCustomer.username
)
exitWithCustomer(
Order.Customer(
customerId = wcCustomer.remoteCustomerId.value,
firstName = wcCustomer.firstName,
lastName = wcCustomer.lastName,
email = wcCustomer.email,
billingAddress = mapper.mapFromOrderAddressToAddress(
billingAddress,
billingCountry,
billingState
),
shippingAddress = mapper.mapFromOrderAddressToAddress(
shippingAddress,
shippingCountry,
shippingState
),
username = wcCustomer.username
)
)
}

protected open fun exitWithCustomer(customer: Order.Customer) {
triggerEvent(
CustomerSelected(customer)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OrderCustomerListFragment : BaseFragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
WooThemeWithBackground {
OrderCustomerListScreen(viewModel = viewModel, handleInsets = false)
CustomerListSelectionScreen(viewModel = viewModel, handleInsets = false)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4242,7 +4242,7 @@
<string name="bookings_filter_title_attendance_status">Attendance status</string>
<string name="bookings_filter_title_payment_status">Payment status</string>
<string name="bookings_filter_title_type">Booking type</string>
<string name="bookings_filter_customer_name">Customer name</string>
<string name="bookings_filter_customer">Customer</string>
<string name="bookings_filter_location">Location</string>
<string name="bookings_filter_title_date">Date &amp; time</string>
<string name="bookings_filter_title_service_event">Service / Event</string>
Expand Down