Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import com.woocommerce.android.util.DateUtils
import com.woocommerce.android.util.StringUtils
import org.wordpress.android.fluxc.model.metadata.WCMetaData
import org.wordpress.android.fluxc.model.metadata.get
import org.wordpress.android.fluxc.model.order.FeeLine
import org.wordpress.android.fluxc.model.order.FeeLineTaxStatus
import org.wordpress.android.fluxc.model.order.OrderAddress
import org.wordpress.android.fluxc.model.order.ShippingLine
import org.wordpress.android.fluxc.model.order.TaxLine
import org.wordpress.android.fluxc.model.order.WCLineTaxEntry
import org.wordpress.android.fluxc.network.rest.wpcom.wc.order.OrderMappingConst.CHARGE_ID_KEY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.woocommerce.android.ui.bookings

import com.woocommerce.android.ui.bookings.compose.BookingAppointmentDetailsModel
import com.woocommerce.android.ui.bookings.compose.BookingAttendanceStatus
import com.woocommerce.android.ui.bookings.compose.BookingCustomerDetailsModel
import com.woocommerce.android.ui.bookings.compose.BookingStatus
import com.woocommerce.android.ui.bookings.compose.BookingSummaryModel
import com.woocommerce.android.ui.bookings.list.BookingListItem
import com.woocommerce.android.util.CurrencyFormatter
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingCustomerInfo
import org.wordpress.android.fluxc.persistence.entity.BookingEntity
import java.time.Duration
import java.time.ZoneOffset
Expand All @@ -29,9 +31,8 @@ class BookingMapper @Inject constructor(
fun Booking.toBookingSummaryModel(): BookingSummaryModel {
return BookingSummaryModel(
date = summaryDateFormatter.format(start),
// TODO replace mocked values when product and customer data are available
name = "Women’s Haircut",
customerName = "Margarita Nikolaevna",
name = order.productInfo?.name ?: "-",
customerName = order.customerInfo?.fullName(),
attendanceStatus = BookingAttendanceStatus.BOOKED,
status = status.toUiModel()
)
Expand All @@ -57,6 +58,22 @@ class BookingMapper @Inject constructor(
)
}

fun BookingCustomerInfo?.toCustomerDetailsModel(): BookingCustomerDetailsModel {
if (this == null) return BookingCustomerDetailsModel.EMPTY

return BookingCustomerDetailsModel(
name = fullName(),
email = billingEmail,
phone = billingPhone,
billingAddressLines = listOfNotNull(
billingAddress1,
billingAddress2,
listOfNotNull(billingCity, billingState, billingPostcode).takeIf { it.isNotEmpty() }?.joinToString(" "),
billingCountry
)
)
}

private fun BookingEntity.Status.toUiModel(): BookingStatus = when (this) {
BookingEntity.Status.Paid -> BookingStatus.Paid
BookingEntity.Status.PendingConfirmation -> BookingStatus.PendingConfirmation
Expand All @@ -66,4 +83,8 @@ class BookingMapper @Inject constructor(
BookingEntity.Status.Unpaid -> BookingStatus.Unpaid
is BookingEntity.Status.Unknown -> BookingStatus.Unknown(this.key)
}

private fun BookingCustomerInfo.fullName(): String? {
return "${billingFirstName.orEmpty()} ${billingLastName.orEmpty()}".trim().ifEmpty { null }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,58 @@ fun BookingCustomerDetails(
.background(color = MaterialTheme.colorScheme.surfaceContainer)
) {
HorizontalDivider(thickness = 0.5.dp)
CustomerDetailsRow(value = model.name)
CustomerDetailsRow(
value = model.email,
trailingIcon = {
Icon(
painter = painterResource(R.drawable.ic_email),
contentDescription = stringResource(id = R.string.booking_customer_label_email),
tint = MaterialTheme.colorScheme.primary
)
},
modifier = Modifier.clickable {
ActivityUtils.sendEmail(context, model.email)
}
)
CustomerDetailsRow(
value = model.phone,
trailingIcon = {
Box {
CustomerDetailsRow(value = model.name ?: stringResource(R.string.orderdetail_customer_name_default))
model.email?.let { email ->
CustomerDetailsRow(
value = email,
trailingIcon = {
Icon(
painter = painterResource(R.drawable.ic_menu_more_vert),
contentDescription = stringResource(id = R.string.booking_customer_label_phone),
painter = painterResource(R.drawable.ic_email),
contentDescription = stringResource(id = R.string.booking_customer_label_email),
tint = MaterialTheme.colorScheme.primary
)
ContactDropdownMenu(
expanded = phoneMenuExpanded,
phone = model.phone,
onDismissRequest = { phoneMenuExpanded = false }
},
modifier = Modifier.clickable {
ActivityUtils.sendEmail(context, email)
}
)
}
model.phone?.let { phone ->
CustomerDetailsRow(
value = phone,
trailingIcon = {
Box {
Icon(
painter = painterResource(R.drawable.ic_menu_more_vert),
contentDescription = stringResource(id = R.string.booking_customer_label_phone),
tint = MaterialTheme.colorScheme.primary
)
ContactDropdownMenu(
expanded = phoneMenuExpanded,
phone = phone,
onDismissRequest = { phoneMenuExpanded = false }
)
}
},
modifier = Modifier.clickable { phoneMenuExpanded = true }
)
}
if (model.billingAddressLines.isNotEmpty()) {
Column(
modifier = Modifier
.padding(vertical = 12.dp, horizontal = 16.dp)
) {
BookingDetailsLabel(label = R.string.booking_billing_address_label)
model.billingAddressLines.forEach { line ->
Text(
text = line,
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
},
modifier = Modifier.clickable { phoneMenuExpanded = true }
)
Column(
modifier = Modifier
.padding(vertical = 12.dp, horizontal = 16.dp)
) {
BookingDetailsLabel(label = R.string.booking_billing_address_label)
model.billingAddressLines.forEach { line ->
Text(
text = line,
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
HorizontalDivider(thickness = 0.5.dp)
}
HorizontalDivider(thickness = 0.5.dp)
}
}
}
Expand Down Expand Up @@ -139,11 +145,20 @@ private fun CustomerDetailsRow(
}

data class BookingCustomerDetailsModel(
val name: String,
val email: String,
val phone: String,
val name: String?,
val email: String?,
val phone: String?,
val billingAddressLines: List<String>,
)
) {
companion object {
val EMPTY = BookingCustomerDetailsModel(
name = null,
email = null,
phone = null,
billingAddressLines = emptyList()
)
}
}

@LightDarkThemePreviews
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.woocommerce.android.R
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground

@Composable
Expand Down Expand Up @@ -44,7 +46,7 @@ fun BookingSummary(
style = MaterialTheme.typography.labelMedium.copy(fontSize = 13.sp),
)
Text(
text = model.customerName,
text = model.customerName ?: stringResource(R.string.orderdetail_customer_name_default),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.labelMedium.copy(fontSize = 13.sp),
)
Expand All @@ -67,7 +69,7 @@ fun BookingSummary(
data class BookingSummaryModel(
val date: String,
val name: String,
val customerName: String,
val customerName: String?,
val attendanceStatus: BookingAttendanceStatus,
val status: BookingStatus,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.woocommerce.android.ui.bookings.Booking
import com.woocommerce.android.ui.bookings.BookingMapper
import com.woocommerce.android.ui.bookings.BookingsRepository
import com.woocommerce.android.ui.bookings.compose.BookingAttendanceStatus
import com.woocommerce.android.ui.bookings.compose.BookingCustomerDetailsModel
import com.woocommerce.android.ui.bookings.compose.BookingPaymentDetailsModel
import com.woocommerce.android.viewmodel.ResourceProvider
import com.woocommerce.android.viewmodel.ScopedViewModel
Expand Down Expand Up @@ -70,16 +69,7 @@ class BookingDetailsViewModel @Inject constructor(
}
},
bookingsAppointmentDetails = booking.toAppointmentDetailsModel(),
bookingCustomerDetails = BookingCustomerDetailsModel(
name = "Margarita Nikolaevna",
email = "[email protected]",
phone = "+1 555-123-4567",
billingAddressLines = listOf(
"238 Willow Creek Drive",
"Montgomery AL 36109",
"United States"
)
),
bookingCustomerDetails = booking.order.customerInfo.toCustomerDetailsModel(),
bookingPaymentDetails = BookingPaymentDetailsModel(
service = "$55.00",
tax = "$4.50",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.wordpress.android.fluxc.model.LocalOrRemoteId
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingCustomerInfo
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingOrderInfo
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingProductInfo
import org.wordpress.android.fluxc.persistence.entity.BookingEntity
import java.time.Duration
import java.time.Instant
Expand Down Expand Up @@ -52,8 +55,9 @@ class BookingMapperTest : BaseUnitTest() {

// THEN
assertThat(model.date).isEqualTo(expectedDate)
assertThat(model.name).isEqualTo("Women’s Haircut")
assertThat(model.customerName).isEqualTo("Margarita Nikolaevna")
assertThat(model.name).isEqualTo(booking.order.productInfo?.name)
assertThat(model.customerName)
.isEqualTo("${booking.order.customerInfo?.billingFirstName} ${booking.order.customerInfo?.billingLastName}")
assertThat(model.attendanceStatus).isEqualTo(BookingAttendanceStatus.BOOKED)
assertThat(model.status).isEqualTo(BookingStatus.Confirmed)
}
Expand Down Expand Up @@ -131,7 +135,15 @@ class BookingMapperTest : BaseUnitTest() {
orderItemId = 1L,
parentId = 0L,
personCounts = listOf(1L),
localTimezone = "UTC"
localTimezone = "UTC",
order = BookingOrderInfo(
status = "completed",
productInfo = BookingProductInfo(name = "Women’s Haircut"),
customerInfo = BookingCustomerInfo(
billingFirstName = "Margarita",
billingLastName = "Nikolaevna"
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.wordpress.android.fluxc.model.LocalOrRemoteId
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingOrderInfo
import org.wordpress.android.fluxc.persistence.entity.BookingEntity
import java.time.Duration
import java.time.Instant
Expand Down Expand Up @@ -127,7 +128,8 @@ class BookingDetailsViewModelTest : BaseUnitTest() {
orderItemId = 1L,
parentId = 0L,
personCounts = listOf(1L),
localTimezone = ""
localTimezone = "",
order = BookingOrderInfo()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingOrderInfo
import org.wordpress.android.fluxc.persistence.entity.BookingEntity
import java.time.Duration
import java.time.Instant
Expand Down Expand Up @@ -220,6 +221,7 @@ class BookingListHandlerTest : BaseUnitTest() {
orderItemId = 1L,
parentId = 0L,
personCounts = listOf(1L),
localTimezone = ""
localTimezone = "",
order = BookingOrderInfo()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.wordpress.android.fluxc.model.LocalOrRemoteId
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingFilters
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingOrderInfo
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsFilterOption
import org.wordpress.android.fluxc.persistence.entity.BookingEntity
import java.time.Clock
Expand Down Expand Up @@ -345,7 +346,8 @@ class BookingListViewModelTest : BaseUnitTest() {
orderItemId = 1L,
parentId = 0L,
personCounts = listOf(1L),
localTimezone = ""
localTimezone = "",
order = BookingOrderInfo()
)
}
}
Loading