Skip to content

Commit 99ed8b3

Browse files
Merge pull request #14834 from woocommerce/issue/WOOMOB-1469-bookings-customer-filter
[WOOMOB-1469] Booking Customer Filter
2 parents a62c55a + 1cd15fb commit 99ed8b3

File tree

9 files changed

+126
-37
lines changed

9 files changed

+126
-37
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/filter/BookingFilterListScreen.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ import androidx.navigation.compose.NavHost
2828
import androidx.navigation.compose.composable
2929
import androidx.navigation.compose.rememberNavController
3030
import com.woocommerce.android.R
31+
import com.woocommerce.android.ui.bookings.filter.customer.BookingCustomerFilterPage
3132
import com.woocommerce.android.ui.bookings.filter.type.BookingTypeFilterRoute
3233
import com.woocommerce.android.ui.compose.Render
3334
import com.woocommerce.android.ui.compose.component.Toolbar
3435
import com.woocommerce.android.ui.compose.component.WCColoredButton
3536
import com.woocommerce.android.ui.compose.preview.LightDarkThemePreviews
3637
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
38+
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsFilterOption
3739

3840
@Composable
3941
fun BookingFilterListScreen(state: BookingFilterListUiState) {
@@ -131,7 +133,18 @@ private fun FiltersNavHost(
131133
}
132134
}
133135
composable(BookingFilterPage.Customer.route) {
134-
TODO()
136+
BookingCustomerFilterPage { customer ->
137+
customer.customerId?.let { id ->
138+
state.onUpdateFilterOption(
139+
BookingsFilterOption.Customer(
140+
customerId = id,
141+
customerName = "${customer.firstName} ${customer.lastName}".trim()
142+
.ifBlank { customer.email }.orEmpty()
143+
)
144+
)
145+
}
146+
state.onClose()
147+
}
135148
}
136149
composable(BookingFilterPage.ServiceEvent.route) {
137150
TODO()

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/filter/BookingFilterListUiState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ data class BookingFilterListUiState(
2929
val onClose: () -> Unit = {},
3030
val onShowBookings: () -> Unit = {},
3131
val openPage: (BookingFilterPage) -> Unit = {},
32-
val onUpdateFilterOption: (BookingsFilterOption) -> Unit = {}
32+
val onUpdateFilterOption: (BookingsFilterOption) -> Unit = {},
3333
) {
3434

3535
val items: List<BookingFilterListItem> = availableBookingFilters().map { page ->
@@ -81,7 +81,7 @@ val BookingFilterPage.titleRes: Int
8181
BookingFilterPage.AttendanceStatus -> R.string.bookings_filter_title_attendance_status
8282
BookingFilterPage.PaymentStatus -> R.string.bookings_filter_title_payment_status
8383
BookingFilterPage.BookingType -> R.string.bookings_filter_title_type
84-
BookingFilterPage.Customer -> R.string.bookings_filter_customer_name
84+
BookingFilterPage.Customer -> R.string.bookings_filter_customer
8585
BookingFilterPage.Location -> R.string.bookings_filter_location
8686
BookingFilterPage.DateTime -> R.string.bookings_filter_title_date
8787
BookingFilterPage.ServiceEvent -> R.string.bookings_filter_title_service_event
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.woocommerce.android.ui.bookings.filter.customer
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
5+
import com.woocommerce.android.model.Order
6+
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListSelectionScreen
7+
8+
@Composable
9+
fun BookingCustomerFilterPage(
10+
onCustomerSelected: (Order.Customer) -> Unit,
11+
) {
12+
val viewModel = hiltViewModel { factory: BookingCustomerFilterViewModel.Factory ->
13+
factory.create(onCustomerSelected)
14+
}
15+
16+
CustomerListSelectionScreen(
17+
viewModel = viewModel,
18+
handleInsets = false,
19+
showToolbar = false
20+
)
21+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.woocommerce.android.ui.bookings.filter.customer
2+
3+
import androidx.lifecycle.SavedStateHandle
4+
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
5+
import com.woocommerce.android.model.Order
6+
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListGetSupportedSearchModes
7+
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListIsAdvancedSearchSupported
8+
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListRepository
9+
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListSelectionViewModel
10+
import com.woocommerce.android.ui.orders.creation.customerlist.CustomerListViewModelMapper
11+
import com.woocommerce.android.util.StringUtils
12+
import dagger.assisted.Assisted
13+
import dagger.assisted.AssistedFactory
14+
import dagger.assisted.AssistedInject
15+
import dagger.hilt.android.lifecycle.HiltViewModel
16+
17+
@Suppress("LongParameterList")
18+
@HiltViewModel(assistedFactory = BookingCustomerFilterViewModel.Factory::class)
19+
class BookingCustomerFilterViewModel @AssistedInject constructor(
20+
savedStateHandle: SavedStateHandle,
21+
repository: CustomerListRepository,
22+
mapper: CustomerListViewModelMapper,
23+
isAdvancedSearchSupported: CustomerListIsAdvancedSearchSupported,
24+
getSupportedSearchModes: CustomerListGetSupportedSearchModes,
25+
analyticsTracker: AnalyticsTrackerWrapper,
26+
stringUtils: StringUtils,
27+
@Assisted private val onCustomerSelected: (Order.Customer) -> Unit
28+
) : CustomerListSelectionViewModel(
29+
savedStateHandle,
30+
repository,
31+
mapper,
32+
isAdvancedSearchSupported,
33+
getSupportedSearchModes,
34+
analyticsTracker,
35+
stringUtils
36+
) {
37+
override fun exitWithCustomer(customer: Order.Customer) {
38+
this.onCustomerSelected.invoke(customer)
39+
}
40+
41+
@AssistedFactory
42+
interface Factory {
43+
fun create(onCustomerSelected: (Order.Customer) -> Unit): BookingCustomerFilterViewModel
44+
}
45+
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/customerlist/CustomerListDialogFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CustomerListDialogFragment : DialogFragment() {
4141
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
4242
setContent {
4343
WooThemeWithBackground {
44-
OrderCustomerListScreen(viewModel = viewModel, handleInsets = true)
44+
CustomerListSelectionScreen(viewModel = viewModel, handleInsets = true)
4545
}
4646
}
4747
}
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ import org.wordpress.android.fluxc.model.customer.WCCustomerModel
3535
* bug https://issuetracker.google.com/issues/411868840 the insets are re-applied when the keyboard is shown.
3636
*/
3737
@Composable
38-
fun OrderCustomerListScreen(
38+
fun CustomerListSelectionScreen(
3939
viewModel: CustomerListSelectionViewModel,
40-
handleInsets: Boolean
40+
handleInsets: Boolean,
41+
showToolbar: Boolean = true
4142
) {
4243
val state by viewModel.viewState.observeAsState()
4344
state?.let {
44-
OrderCustomerListScreen(
45+
CustomerListSelectionScreen(
4546
state = it,
4647
handleInsets = handleInsets,
48+
showToolbar = showToolbar,
4749
onNavigateBack = viewModel::onNavigateBack,
4850
onAddCustomerClicked = viewModel::onAddCustomerClicked,
4951
onCustomerSelected = viewModel::onCustomerSelected,
@@ -55,9 +57,10 @@ fun OrderCustomerListScreen(
5557
}
5658

5759
@Composable
58-
fun OrderCustomerListScreen(
60+
private fun CustomerListSelectionScreen(
5961
state: CustomerListViewState,
6062
handleInsets: Boolean,
63+
showToolbar: Boolean,
6164
onNavigateBack: () -> Unit,
6265
onAddCustomerClicked: () -> Unit,
6366
onCustomerSelected: (WCCustomerModel) -> Unit,
@@ -68,12 +71,14 @@ fun OrderCustomerListScreen(
6871
) {
6972
Scaffold(
7073
topBar = {
71-
Toolbar(
72-
title = stringResource(id = R.string.order_creation_add_customer),
73-
navigationIcon = Icons.AutoMirrored.Filled.ArrowBack,
74-
onNavigationButtonClick = onNavigateBack,
75-
windowInsets = if (handleInsets) AppBarDefaults.topAppBarWindowInsets else WindowInsets(0),
76-
)
74+
if (showToolbar) {
75+
Toolbar(
76+
title = stringResource(id = R.string.order_creation_add_customer),
77+
navigationIcon = Icons.AutoMirrored.Filled.ArrowBack,
78+
onNavigationButtonClick = onNavigateBack,
79+
windowInsets = if (handleInsets) AppBarDefaults.topAppBarWindowInsets else WindowInsets(0),
80+
)
81+
}
7782
},
7883
floatingActionButton = {
7984
if (state.showFab) CustomerListAddCustomerButton(onAddCustomerClicked)
@@ -111,7 +116,7 @@ private fun CustomerListAddCustomerButton(onClick: () -> Unit) {
111116
@Composable
112117
fun OrderCustomerListScreenPreview() {
113118
WooThemeWithBackground {
114-
OrderCustomerListScreen(
119+
CustomerListSelectionScreen(
115120
state = CustomerListViewState(
116121
searchHint = R.string.order_creation_customer_search_hint,
117122
searchQuery = "",
@@ -171,6 +176,7 @@ fun OrderCustomerListScreenPreview() {
171176
),
172177
),
173178
handleInsets = false,
179+
showToolbar = true,
174180
onNavigateBack = {},
175181
onAddCustomerClicked = {},
176182
onCustomerSelected = {},

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/customerlist/CustomerListSelectionViewModel.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.wordpress.android.fluxc.model.customer.WCCustomerModel
1515
import javax.inject.Inject
1616

1717
@HiltViewModel
18-
class CustomerListSelectionViewModel @Inject constructor(
18+
open class CustomerListSelectionViewModel @Inject constructor(
1919
savedState: SavedStateHandle,
2020
private val repository: CustomerListRepository,
2121
private val mapper: CustomerListViewModelMapper,
@@ -85,26 +85,30 @@ class CustomerListSelectionViewModel @Inject constructor(
8585
val billingCountry = repository.getCountry(billingAddress.country)
8686
val billingState = repository.getState(billingAddress.country, billingAddress.state)
8787

88-
triggerEvent(
89-
CustomerSelected(
90-
Order.Customer(
91-
customerId = wcCustomer.remoteCustomerId.value,
92-
firstName = wcCustomer.firstName,
93-
lastName = wcCustomer.lastName,
94-
email = wcCustomer.email,
95-
billingAddress = mapper.mapFromOrderAddressToAddress(
96-
billingAddress,
97-
billingCountry,
98-
billingState
99-
),
100-
shippingAddress = mapper.mapFromOrderAddressToAddress(
101-
shippingAddress,
102-
shippingCountry,
103-
shippingState
104-
),
105-
username = wcCustomer.username
106-
)
88+
exitWithCustomer(
89+
Order.Customer(
90+
customerId = wcCustomer.remoteCustomerId.value,
91+
firstName = wcCustomer.firstName,
92+
lastName = wcCustomer.lastName,
93+
email = wcCustomer.email,
94+
billingAddress = mapper.mapFromOrderAddressToAddress(
95+
billingAddress,
96+
billingCountry,
97+
billingState
98+
),
99+
shippingAddress = mapper.mapFromOrderAddressToAddress(
100+
shippingAddress,
101+
shippingCountry,
102+
shippingState
103+
),
104+
username = wcCustomer.username
107105
)
108106
)
109107
}
108+
109+
protected open fun exitWithCustomer(customer: Order.Customer) {
110+
triggerEvent(
111+
CustomerSelected(customer)
112+
)
113+
}
110114
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/customerlist/OrderCustomerListFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OrderCustomerListFragment : BaseFragment() {
3535
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
3636
setContent {
3737
WooThemeWithBackground {
38-
OrderCustomerListScreen(viewModel = viewModel, handleInsets = false)
38+
CustomerListSelectionScreen(viewModel = viewModel, handleInsets = false)
3939
}
4040
}
4141
}

WooCommerce/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4242,7 +4242,7 @@
42424242
<string name="bookings_filter_title_attendance_status">Attendance status</string>
42434243
<string name="bookings_filter_title_payment_status">Payment status</string>
42444244
<string name="bookings_filter_title_type">Booking type</string>
4245-
<string name="bookings_filter_customer_name">Customer name</string>
4245+
<string name="bookings_filter_customer">Customer</string>
42464246
<string name="bookings_filter_location">Location</string>
42474247
<string name="bookings_filter_title_date">Date &amp; time</string>
42484248
<string name="bookings_filter_title_service_event">Service / Event</string>

0 commit comments

Comments
 (0)