feat(gift): 받은 선물 상세 표시를 추가한다
This commit is contained in:
@@ -19,7 +19,10 @@ sealed interface GiftDetailText {
|
||||
CANCELED_LABEL,
|
||||
CANCELED_TITLE,
|
||||
CANCELED_BODY,
|
||||
DISPOSAL_NON_RETURN_GUIDANCE
|
||||
DISPOSAL_NON_RETURN_GUIDANCE,
|
||||
RECIPIENT_ADDRESS_COMPLETED_TITLE,
|
||||
RECIPIENT_DELIVERED_TITLE,
|
||||
RECIPIENT_ADDRESS_REMOVAL_GUIDANCE
|
||||
}
|
||||
|
||||
data class Raw(val value: String) : GiftDetailText
|
||||
@@ -41,7 +44,8 @@ data class GiftDetailUiModel(
|
||||
val recipientAddress: GiftDetailAddress?,
|
||||
val undeliverable: GiftDetailUndeliverable?,
|
||||
val cancellation: GiftDetailCancellation?,
|
||||
val actions: Set<GiftDetailAction>
|
||||
val actions: Set<GiftDetailAction>,
|
||||
val received: GiftDetailReceived?
|
||||
)
|
||||
|
||||
data class GiftDetailHero(val chip: GiftDetailText?, val title: GiftDetailText, val body: GiftDetailText?)
|
||||
@@ -70,4 +74,54 @@ data class GiftDetailUndeliverable(val title: GiftDetailText, val guidance: Gift
|
||||
|
||||
data class GiftDetailCancellation(val date: String?, val refundCan: Int?)
|
||||
|
||||
enum class GiftDetailAction { TRACKING, CANCEL, INQUIRY }
|
||||
sealed interface GiftDetailReceived {
|
||||
data class AddressForm(
|
||||
val pendingGiftRows: List<GiftDetailInfoRow>,
|
||||
val addressForm: GiftDetailAddressForm
|
||||
) : GiftDetailReceived
|
||||
|
||||
data class AddressCompleted(
|
||||
val hero: GiftDetailHero,
|
||||
val giftInfoRows: List<GiftDetailInfoRow>,
|
||||
val recipientAddress: GiftDetailAddress?
|
||||
) : GiftDetailReceived
|
||||
|
||||
data class Delivered(
|
||||
val hero: GiftDetailHero,
|
||||
val giftInfoRows: List<GiftDetailInfoRow>,
|
||||
val recipientAddress: GiftDetailAddress?,
|
||||
val recipientAddressGuidance: GiftDetailText?
|
||||
) : GiftDetailReceived
|
||||
|
||||
data class Undeliverable(
|
||||
val hero: GiftDetailHero,
|
||||
val reason: GiftDetailUndeliverable
|
||||
) : GiftDetailReceived
|
||||
}
|
||||
|
||||
data object GiftDetailAddressForm {
|
||||
val showsPrivacyNotice = true
|
||||
val fields = listOf(
|
||||
GiftDetailAddressFormField.NAME,
|
||||
GiftDetailAddressFormField.PHONE_NUMBER,
|
||||
GiftDetailAddressFormField.ZIP_CODE,
|
||||
GiftDetailAddressFormField.ADDRESS,
|
||||
GiftDetailAddressFormField.DETAIL_ADDRESS
|
||||
)
|
||||
val agreements = listOf(GiftDetailAddressAgreement.TERMS, GiftDetailAddressAgreement.PRIVACY)
|
||||
val cta = GiftDetailAddressFormCta.RECEIVE_GIFT
|
||||
}
|
||||
|
||||
enum class GiftDetailAddressFormField(val required: Boolean) {
|
||||
NAME(true),
|
||||
PHONE_NUMBER(true),
|
||||
ZIP_CODE(true),
|
||||
ADDRESS(true),
|
||||
DETAIL_ADDRESS(false)
|
||||
}
|
||||
|
||||
enum class GiftDetailAddressAgreement { TERMS, PRIVACY }
|
||||
|
||||
enum class GiftDetailAddressFormCta { RECEIVE_GIFT }
|
||||
|
||||
enum class GiftDetailAction { TRACKING, CANCEL, INQUIRY, POLICY }
|
||||
|
||||
@@ -20,9 +20,16 @@ object GiftDetailPresenter {
|
||||
"DELIVERED" to Key.DELIVERED_LABEL
|
||||
)
|
||||
private val knownStates = normalStates.keys + setOf("UNDELIVERABLE", "CANCELED")
|
||||
private val receivedAddressCompletedStates = setOf(
|
||||
"TRACKING_REGISTERED",
|
||||
"ARRIVED_AT_MAILBOX",
|
||||
"INSPECTION_COMPLETED"
|
||||
)
|
||||
private val utcPattern = Regex("([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2})(?:\\.[0-9]{1,9})?(?:Z|\\+00:00)")
|
||||
|
||||
fun present(detail: GiftDetailResponse, cancel: GiftCancelResponse? = null): GiftDetailUiModel {
|
||||
if (detail.direction == "RECEIVED") return presentReceived(detail)
|
||||
|
||||
val status = if (cancel != null) "CANCELED" else detail.status
|
||||
val info = detail.giftInfo
|
||||
val history = detail.statusTimeline.associateBy { it.status }
|
||||
@@ -99,13 +106,108 @@ object GiftDetailPresenter {
|
||||
},
|
||||
cancellation = cancellation,
|
||||
actions = buildSet {
|
||||
if (status in knownStates && detail.trackingRequired) add(GiftDetailAction.TRACKING)
|
||||
if (detail.direction == "SENT" && status in knownStates && detail.trackingRequired) add(GiftDetailAction.TRACKING)
|
||||
if (detail.direction == "SENT" && status == "RECEIVED") add(GiftDetailAction.CANCEL)
|
||||
add(GiftDetailAction.INQUIRY)
|
||||
}
|
||||
},
|
||||
received = null
|
||||
)
|
||||
}
|
||||
|
||||
private fun presentReceived(detail: GiftDetailResponse): GiftDetailUiModel {
|
||||
val shippingRequestedDate = formatCardDate(detail.giftInfo.shippingRequestedAt)
|
||||
val deliveredDate = formatCardDate(
|
||||
detail.statusTimeline.firstOrNull { it.status == "DELIVERED" }?.occurredAt
|
||||
)
|
||||
val received: GiftDetailReceived? = when (detail.status) {
|
||||
"CANCELED" -> null
|
||||
"UNDELIVERABLE" -> GiftDetailReceived.Undeliverable(
|
||||
hero = GiftDetailHero(Key.UNDELIVERABLE_LABEL, Key.UNDELIVERABLE_TITLE, Key.UNDELIVERABLE_BODY),
|
||||
reason = GiftDetailUndeliverable(
|
||||
detail.delivery.undeliverableReason?.let(::Raw) ?: Key.UNDELIVERABLE_LABEL,
|
||||
Key.DISPOSAL_NON_RETURN_GUIDANCE
|
||||
)
|
||||
)
|
||||
"DELIVERED" -> GiftDetailReceived.Delivered(
|
||||
hero = GiftDetailHero(Key.DELIVERED_LABEL, Key.RECIPIENT_DELIVERED_TITLE, null),
|
||||
giftInfoRows = receivedGiftRows(detail, shippingRequestedDate, deliveredDate),
|
||||
recipientAddress = detail.recipientAddress?.toUiModel(),
|
||||
recipientAddressGuidance = detail.recipientAddress?.let {
|
||||
Key.RECIPIENT_ADDRESS_REMOVAL_GUIDANCE
|
||||
}
|
||||
)
|
||||
else -> when {
|
||||
detail.recipientAddressRequired -> GiftDetailReceived.AddressForm(
|
||||
pendingGiftRows = receivedGiftRows(detail),
|
||||
addressForm = GiftDetailAddressForm
|
||||
)
|
||||
detail.status in receivedAddressCompletedStates -> GiftDetailReceived.AddressCompleted(
|
||||
hero = GiftDetailHero(null, Key.RECIPIENT_ADDRESS_COMPLETED_TITLE, null),
|
||||
giftInfoRows = receivedGiftRows(detail, shippingRequestedDate),
|
||||
recipientAddress = detail.recipientAddress?.toUiModel()
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
val hero = when (received) {
|
||||
null -> hero(detail.status, detail.statusName)
|
||||
is GiftDetailReceived.AddressForm -> GiftDetailHero(null, Key.RECEIVED_TITLE, Key.RECEIVED_BODY)
|
||||
is GiftDetailReceived.AddressCompleted -> received.hero
|
||||
is GiftDetailReceived.Delivered -> received.hero
|
||||
is GiftDetailReceived.Undeliverable -> received.hero
|
||||
}
|
||||
val recipientAddress = when (received) {
|
||||
is GiftDetailReceived.AddressCompleted -> received.recipientAddress
|
||||
is GiftDetailReceived.Delivered -> received.recipientAddress
|
||||
else -> null
|
||||
}
|
||||
val actions = when (received) {
|
||||
null -> setOf(GiftDetailAction.INQUIRY)
|
||||
is GiftDetailReceived.AddressForm -> emptySet()
|
||||
is GiftDetailReceived.AddressCompleted, is GiftDetailReceived.Delivered -> setOf(GiftDetailAction.INQUIRY)
|
||||
is GiftDetailReceived.Undeliverable -> setOf(GiftDetailAction.INQUIRY, GiftDetailAction.POLICY)
|
||||
}
|
||||
return GiftDetailUiModel(
|
||||
applicationNo = detail.applicationNo,
|
||||
status = detail.status,
|
||||
hero = hero,
|
||||
timeline = emptyList(),
|
||||
progressSegments = emptyList(),
|
||||
showProgress = false,
|
||||
cancellationRows = emptyList(),
|
||||
giftInfo = GiftDetailInfo(
|
||||
counterpartNickname = detail.giftInfo.senderNickname,
|
||||
sizeName = detail.giftInfo.sizeName,
|
||||
categoryName = detail.giftInfo.categoryName,
|
||||
paidCan = null,
|
||||
tracking = null,
|
||||
shippingRequestedDate = null,
|
||||
inspectionDate = null,
|
||||
deliveredDate = null,
|
||||
canceledDate = null
|
||||
),
|
||||
senderInfo = null,
|
||||
mailbox = null,
|
||||
recipientAddress = recipientAddress,
|
||||
undeliverable = (received as? GiftDetailReceived.Undeliverable)?.reason,
|
||||
cancellation = null,
|
||||
actions = actions,
|
||||
received = received
|
||||
)
|
||||
}
|
||||
|
||||
private fun receivedGiftRows(
|
||||
detail: GiftDetailResponse,
|
||||
shippingRequestedDate: String? = null,
|
||||
deliveredDate: String? = null
|
||||
): List<GiftDetailInfoRow> = listOfNotNull(
|
||||
detail.giftInfo.senderNickname?.let { GiftDetailInfoRow(R.string.gift_inbox_sender, Raw(it)) },
|
||||
GiftDetailInfoRow(R.string.gift_send_size, Raw(detail.giftInfo.sizeName)),
|
||||
GiftDetailInfoRow(R.string.gift_send_category, Raw(detail.giftInfo.categoryName)),
|
||||
shippingRequestedDate?.let { GiftDetailInfoRow(R.string.gift_detail_shipping_date, Raw(it)) },
|
||||
deliveredDate?.let { GiftDetailInfoRow(R.string.gift_detail_delivered_date, Raw(it)) }
|
||||
)
|
||||
|
||||
internal fun showsTrackingAction(state: GiftDetailUiState): Boolean {
|
||||
val detail = (state as? GiftDetailUiState.Content)?.detail ?: return false
|
||||
val model = present(detail)
|
||||
|
||||
Reference in New Issue
Block a user