-
Notifications
You must be signed in to change notification settings - Fork 133
[WOOMOB-1396] - Booking's customer section actions #14692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AdamGrzybkowski
merged 8 commits into
trunk
from
issue/WOOMOB-1396_custom_section_actions
Oct 6, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c63f1d
Align icons for email&phone with the order screen
AdamGrzybkowski bb13aa4
Extract sendSms function to ActivityUtils
AdamGrzybkowski 8bff5bb
Create ContactDropdownMenu composable to show contact options
AdamGrzybkowski b16d619
Extract logic to check for available phone contact options
AdamGrzybkowski f388102
Use PhoneContactOptionsUtils in the Order screen
AdamGrzybkowski fc5caaa
Use PhoneContactOptionsUtils in the Booking screen
AdamGrzybkowski ee32e2e
Invoke sendEmail action on contact email tap
AdamGrzybkowski 5b0008b
Recaulculate contact options on each resume
AdamGrzybkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...mmerce/src/main/kotlin/com/woocommerce/android/ui/bookings/compose/ContactDropdownMenu.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.woocommerce.android.ui.bookings.compose | ||
|
||
import android.content.Context | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.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.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.compose.LifecycleEventEffect | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.util.ActivityUtils | ||
import com.woocommerce.android.util.PhoneContactOption | ||
import com.woocommerce.android.util.getAvailablePhoneContactOptions | ||
import com.woocommerce.android.util.stringRes | ||
import org.wordpress.android.util.ToastUtils | ||
|
||
@Composable | ||
fun ContactDropdownMenu( | ||
expanded: Boolean, | ||
phone: String, | ||
onDismissRequest: () -> Unit, | ||
) { | ||
val context = LocalContext.current | ||
var contactOptions by remember { mutableStateOf(emptyList<PhoneContactOption>()) } | ||
|
||
// Update the available contact options when the composable enters the RESUMED state | ||
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { | ||
contactOptions = context.getAvailablePhoneContactOptions() | ||
} | ||
|
||
DropdownMenu( | ||
expanded = expanded, | ||
onDismissRequest = onDismissRequest | ||
) { | ||
contactOptions.forEach { contactOption -> | ||
DropdownMenuItem( | ||
text = { Text(stringResource(contactOption.stringRes)) }, | ||
onClick = { | ||
contactOption.action(context, phone) | ||
onDismissRequest() | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
private val PhoneContactOption.action: (Context, String) -> Unit | ||
get() = when (this) { | ||
PhoneContactOption.CALL -> { | ||
// This is the lambda being returned. It must define its parameters. | ||
{ context, phone -> | ||
ActivityUtils.dialPhoneNumber(context, phone) { | ||
ToastUtils.showToast(context, R.string.error_no_phone_app) | ||
} | ||
} | ||
} | ||
|
||
PhoneContactOption.SMS -> { | ||
{ context, phone -> | ||
ActivityUtils.sendSms(context, phone) { | ||
ToastUtils.showToast(context, R.string.error_no_sms_app) | ||
} | ||
} | ||
} | ||
|
||
PhoneContactOption.WHATSAPP -> { | ||
{ context, phone -> | ||
ActivityUtils.openWhatsApp(context, phone) | ||
} | ||
} | ||
|
||
PhoneContactOption.TELEGRAM -> { | ||
{ context, phone -> | ||
ActivityUtils.openTelegram(context, phone) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
WooCommerce/src/main/kotlin/com/woocommerce/android/util/PhoneContactOptionsUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.woocommerce.android.util | ||
|
||
import android.content.Context | ||
import androidx.annotation.StringRes | ||
import com.woocommerce.android.R | ||
|
||
private const val WHATSAPP_PACKAGE_NAME = "com.whatsapp" | ||
private const val TELEGRAM_PACKAGE_NAME = "org.telegram.messenger" | ||
|
||
fun Context.getAvailablePhoneContactOptions(): List<PhoneContactOption> { | ||
return buildList { | ||
add(PhoneContactOption.CALL) | ||
add(PhoneContactOption.SMS) | ||
if (ActivityUtils.isAppInstalled(this@getAvailablePhoneContactOptions, WHATSAPP_PACKAGE_NAME)) { | ||
add(PhoneContactOption.WHATSAPP) | ||
} | ||
if (ActivityUtils.isAppInstalled(this@getAvailablePhoneContactOptions, TELEGRAM_PACKAGE_NAME)) { | ||
add(PhoneContactOption.TELEGRAM) | ||
} | ||
} | ||
} | ||
|
||
enum class PhoneContactOption { | ||
CALL, SMS, WHATSAPP, TELEGRAM | ||
} | ||
|
||
val PhoneContactOption.stringRes: Int | ||
@StringRes get() = when (this) { | ||
PhoneContactOption.CALL -> R.string.orderdetail_call_customer | ||
PhoneContactOption.SMS -> R.string.orderdetail_message_customer | ||
PhoneContactOption.WHATSAPP -> R.string.orderdetail_message_customer_using_whatsapp | ||
PhoneContactOption.TELEGRAM -> R.string.orderdetail_message_customer_using_telegram | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Removing the onEmailClick and onPhoneClick callbacks hardcodes side effects (email intent, phone actions) inside the composable, reducing testability and flexibility (e.g., adding analytics, logging, or alternative behaviors). Consider reintroducing callbacks (with sensible defaults) so the UI remains a pure presenter while delegating side effects to higher layers.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to mention that too. Adding analytics would indeed be easier if we handled actions in the view models. But it’s not a major concern, we can revisit it when we implement analytics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I think there are pros and cons, like always. This way, the component is very easy to drop and use, without needing to implement the actions every time.