Skip to content

Commit

Permalink
[MBL-1669][MBL-1715] Add delivery address object to the graph query f…
Browse files Browse the repository at this point in the history
…or PPO/format result for PPO card (#2124)

* add delivery address object to the graph query for PPO, make address field hidden if not part of the PPO card return

* lint
  • Loading branch information
mtgriego authored Sep 9, 2024
1 parent 35cacbc commit b84688c
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 34 deletions.
8 changes: 8 additions & 0 deletions app/src/main/graphql/fragments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ fragment ppoCard on Backing {
}
deliveryAddress {
id
addressLine1
addressLine2
city
region
postalCode
phoneNumber
recipientName
countryCode
}
project {
name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.kickstarter.features.pledgedprojectsoverview.data

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
class DeliveryAddress private constructor(
val addressID: String?,
val addressLine1: String?,
val addressLine2: String?,
val city: String?,
val region: String?,
val postalCode: String?,
val countryCode: String?,
val phoneNumber: String?,
val recipientName: String?
) : Parcelable {

fun addressId() = this.addressID
fun addressLine1() = this.addressLine1
fun addressLine2() = this.addressLine2
fun city() = this.city
fun region() = this.region
fun postalCode() = this.postalCode
fun countryCode() = this.countryCode
fun phoneNumber() = this.phoneNumber
fun recipientName() = this.recipientName

@Parcelize
data class Builder(
var addressID: String? = null,
var addressLine1: String? = null,
var addressLine2: String? = null,
var city: String? = null,
var region: String? = null,
var postalCode: String? = null,
var countryCode: String? = null,
var phoneNumber: String? = null,
var recipientName: String? = null
) : Parcelable {

fun addressId(addressID: String?) = apply { this.addressID = addressID }
fun addressLine1(addressLine1: String?) = apply { this.addressLine1 = addressLine1 }
fun addressLine2(addressLine2: String?) = apply { this.addressLine2 = addressLine2 }
fun city(city: String?) = apply { this.city = city }
fun region(region: String?) = apply { this.region = region }
fun postalCode(postalCode: String?) = apply { this.postalCode = postalCode }
fun countryCode(countryCode: String?) = apply { this.countryCode = countryCode }
fun phoneNumber(phoneNumber: String?) = apply { this.phoneNumber = phoneNumber }
fun recipientName(recipientName: String?) = apply { this.recipientName = recipientName }

fun build() = DeliveryAddress(
addressID = addressID,
addressLine1 = addressLine1,
addressLine2 = addressLine2,
city = city,
region = region,
postalCode = postalCode,
countryCode = countryCode,
phoneNumber = phoneNumber,
recipientName = recipientName
)
}

fun toBuilder() = Builder(
addressID = addressID,
addressLine1 = addressLine1,
addressLine2 = addressLine2,
city = city,
region = region,
postalCode = postalCode,
countryCode = countryCode,
phoneNumber = phoneNumber,
recipientName = recipientName
)

companion object {
@JvmStatic
fun builder() = Builder()
}

override fun equals(other: Any?): Boolean {
var equals = super.equals(other)
if (other is DeliveryAddress) {
equals = addressId() == other.addressId() &&
addressLine1() == other.addressLine1() &&
addressLine2() == other.addressLine2() &&
city() == other.city() &&
region() == other.region() &&
postalCode() == other.postalCode() &&
countryCode() == other.countryCode() &&
phoneNumber() == other.phoneNumber() &&
recipientName() == other.recipientName()
}
return equals
}

/* Formats the address to be:
recipientName
addressLine1
addressLine2 (optional)
city, region postalCode
countryCode (optional)
phoneNumber (optional)
*/
fun getFormattedAddress(): String {
return "${recipientName ?: ""}\n${addressLine1 ?: ""}\n" + if (!addressLine2.isNullOrEmpty()) "${addressLine2}\n" else "" + "${city ?: ""}, ${region ?: ""} ${postalCode ?: ""}\n" + if (!countryCode.isNullOrEmpty()) "${countryCode}\n" else "" + if (!phoneNumber.isNullOrEmpty()) "$phoneNumber" else ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import type.CurrencyCode

@Parcelize
class PPOCard private constructor(
val address: String?,
val addressID: String?,
val deliveryAddress: DeliveryAddress?,
val amount: String?,
val backingId: String?,
val backingDetailsUrl: String?,
Expand All @@ -29,8 +28,7 @@ class PPOCard private constructor(

) : Parcelable {

fun address() = this.address
fun addressID() = this.addressID
fun deliveryAddress() = this.deliveryAddress
fun amount() = this.amount
fun backingDetailsUrl() = this.backingDetailsUrl
fun backingId() = this.backingId
Expand All @@ -51,8 +49,7 @@ class PPOCard private constructor(

@Parcelize
data class Builder(
var address: String? = null,
var addressID: String? = null,
var deliveryAddress: DeliveryAddress? = null,
var amount: String? = null,
var backingDetailsUrl: String? = null,
var backingId: String? = null,
Expand All @@ -72,8 +69,7 @@ class PPOCard private constructor(
var viewType: PPOCardViewType? = null,
) : Parcelable {

fun address(address: String?) = apply { this.address = address }
fun addressID(addressID: String?) = apply { this.addressID = addressID }
fun deliveryAddress(deliveryAddress: DeliveryAddress?) = apply { this.deliveryAddress = deliveryAddress }
fun amount(amount: String?) = apply { this.amount = amount }
fun backingDetailsUrl(backingDetailsUrl: String?) = apply { this.backingDetailsUrl = backingDetailsUrl }
fun backingId(backingId: String?) = apply { this.backingId = backingId }
Expand All @@ -93,8 +89,7 @@ class PPOCard private constructor(
fun viewType(viewType: PPOCardViewType?) = apply { this.viewType = viewType }

fun build() = PPOCard(
address = address,
addressID = addressID,
deliveryAddress = deliveryAddress,
amount = amount,
backingDetailsUrl = backingDetailsUrl,
backingId = backingId,
Expand All @@ -116,8 +111,7 @@ class PPOCard private constructor(
}

fun toBuilder() = Builder(
address = address,
addressID = addressID,
deliveryAddress = deliveryAddress,
amount = amount,
backingDetailsUrl = backingDetailsUrl,
backingId = backingId,
Expand Down Expand Up @@ -146,8 +140,7 @@ class PPOCard private constructor(
var equals = super.equals(other)
if (other is PPOCard) {
equals = backingId() == other.backingId() &&
address() == other.address() &&
addressID() == other.addressID() &&
deliveryAddress() == other.deliveryAddress() &&
amount() == other.amount() &&
clientSecret() == other.clientSecret() &&
currencyCode() == other.currencyCode() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class PPOCardFactory private constructor() {

fun ppoCard(
backingID: String?,
addressID: String?,
address: String?,
deliveryAddress: DeliveryAddress?,
amount: String?,
currencyCode: CurrencyCode?,
currencySymbol: String?,
Expand All @@ -24,8 +23,7 @@ class PPOCardFactory private constructor() {
): PPOCard {
return PPOCard.builder()
.backingId(backingID)
.address(address)
.addressID(addressID)
.deliveryAddress(deliveryAddress)
.amount(amount)
.currencySymbol(currencySymbol)
.currencyCode(currencyCode)
Expand All @@ -40,12 +38,45 @@ class PPOCardFactory private constructor() {
.build()
}

fun deliveryAddress(
addressID: String?,
addressLine1: String?,
addressLine2: String?,
city: String?,
region: String?,
postalCode: String?,
countryCode: String?,
phoneNumber: String?,
recipientName: String?
): DeliveryAddress {
return DeliveryAddress.builder()
.addressId(addressID)
.addressLine1(addressLine1)
.addressLine2(addressLine2)
.city(city)
.region(region)
.postalCode(postalCode)
.countryCode(countryCode)
.phoneNumber(phoneNumber)
.recipientName(recipientName)
.build()
}

fun confirmAddressCard(): PPOCard {
return ppoCard(
backingID = "1234",
amount = "12.0",
address = "Firsty Lasty\n123 First Street, Apt #5678\nLos Angeles, CA 90025-1234\nUnited States",
addressID = "12234",
deliveryAddress = deliveryAddress(
addressID = "12234",
addressLine1 = "123 First Street, Apt #5678",
addressLine2 = null,
city = "Los Angeles",
region = "CA",
postalCode = "90025-1234",
countryCode = "United States",
phoneNumber = "(555) 555-5555",
recipientName = "Firsty Lasty"
),
currencySymbol = "$",
currencyCode = CurrencyCode.USD,
projectName = "Super Duper Project",
Expand All @@ -63,8 +94,17 @@ class PPOCardFactory private constructor() {
return ppoCard(
backingID = "1234",
amount = "$12.00",
address = "Firsty Lasty\n123 First Street, Apt #5678\nLos Angeles, CA 90025-1234\nUnited States",
addressID = "12234",
deliveryAddress = deliveryAddress(
addressID = "12234",
addressLine1 = "123 First Street, Apt #5678",
addressLine2 = null,
city = "Los Angeles",
region = "CA",
postalCode = "90025-1234",
countryCode = "United States",
phoneNumber = "(555) 555-5555",
recipientName = "Firsty Lasty"
),
currencySymbol = "$",
currencyCode = CurrencyCode.USD,
projectName = "Super Duper Project",
Expand All @@ -83,8 +123,17 @@ class PPOCardFactory private constructor() {
return ppoCard(
backingID = "1234",
amount = "$12.00",
address = "Firsty Lasty\n123 First Street, Apt #5678\nLos Angeles, CA 90025-1234\nUnited States",
addressID = "12234",
deliveryAddress = deliveryAddress(
addressID = "12234",
addressLine1 = "123 First Street, Apt #5678",
addressLine2 = null,
city = "Los Angeles",
region = "CA",
postalCode = "90025-1234",
countryCode = "United States",
phoneNumber = "(555) 555-5555",
recipientName = "Firsty Lasty"
),
currencySymbol = "$",
currencyCode = CurrencyCode.USD,
projectName = "Super Duper Project",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fun PPOCardView(
sendAMessageClickAction = sendAMessageClickAction
)

if (viewType == PPOCardViewType.CONFIRM_ADDRESS) {
if (viewType == PPOCardViewType.CONFIRM_ADDRESS && !shippingAddress.isNullOrEmpty()) {
Spacer(modifier = Modifier.height(dimensions.paddingSmall))

ShippingAddressView(
Expand Down Expand Up @@ -319,7 +319,6 @@ fun CreatorNameSendMessageView(
)
.clickable { sendAMessageClickAction.invoke() }
) {
// TODO: Replace with translated string
Text(
text = stringResource(id = R.string.send_a_message_fpo),
color = colors.textAccentGreen,
Expand Down Expand Up @@ -413,7 +412,6 @@ fun ConfirmAddressButtonsView(isConfirmButtonEnabled: Boolean, onEditAddressClic
.padding(dimensions.paddingSmall)
.testTag(PPOCardViewTestTag.CONFIRM_ADDRESS_BUTTONS_VIEW.name)
) {
// TODO: Replace with translated strings
KSPrimaryBlackButton(
modifier = Modifier
.weight(0.5f),
Expand All @@ -437,7 +435,6 @@ fun ConfirmAddressButtonsView(isConfirmButtonEnabled: Boolean, onEditAddressClic

@Composable
fun FixPaymentButtonView(onFixPaymentClicked: () -> Unit) {
// TODO: Replace with translated string
KSSecondaryRedButton(
modifier = Modifier.padding(dimensions.paddingMediumSmall),
onClickAction = { onFixPaymentClicked.invoke() },
Expand All @@ -449,7 +446,6 @@ fun FixPaymentButtonView(onFixPaymentClicked: () -> Unit) {

@Composable
fun AuthenticateCardButtonView(onAuthenticateCardClicked: () -> Unit) {
// TODO: Replace with translated string
KSSecondaryRedButton(
modifier = Modifier.padding(dimensions.paddingMediumSmall),
onClickAction = { onAuthenticateCardClicked.invoke() },
Expand All @@ -461,7 +457,6 @@ fun AuthenticateCardButtonView(onAuthenticateCardClicked: () -> Unit) {

@Composable
fun TakeSurveyButtonView(onAuthenticateCardClicked: () -> Unit) {
// TODO: Replace with translated string
KSPrimaryGreenButton(
modifier = Modifier.padding(dimensions.paddingMediumSmall),
onClickAction = { onAuthenticateCardClicked.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,16 @@ fun PledgedProjectsOverviewScreen(
imageContentDescription = it.imageContentDescription(),
creatorName = it.creatorName(),
sendAMessageClickAction = { onSendMessageClick(it.projectSlug() ?: "", it.projectId ?: "", ppoCards.itemSnapshotList.toList(), totalAlerts, it.creatorID() ?: "") },
shippingAddress = it.address() ?: "", // TODO replace with formatted address from PPO response
shippingAddress = it.deliveryAddress()?.getFormattedAddress() ?: "",
onActionButtonClicked = {
onPrimaryActionButtonClicked(it)
},
onSecondaryActionButtonClicked = {
when (it.viewType()) {
PPOCardViewType.CONFIRM_ADDRESS -> {
analyticEvents?.trackPPOConfirmAddressInitiateCTAClicked(projectID = it.projectId ?: "", ppoCards.itemSnapshotList.items, totalAlerts)
confirmedAddress = it.address() ?: ""
addressID = it.addressID ?: ""
confirmedAddress = it.deliveryAddress()?.getFormattedAddress() ?: ""
addressID = it.deliveryAddress()?.addressId() ?: ""
backingID = it.backingId ?: ""
projectID = it.projectId ?: ""
openConfirmAddressAlertDialog.value = true
Expand Down
Loading

0 comments on commit b84688c

Please sign in to comment.