Skip to content
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

[MBL-1714] "Estimated Shipping" Showing When There's No Estimated Shipping #2151

Merged
merged 2 commits into from
Sep 9, 2024
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 @@ -274,9 +274,10 @@ final class NoShippingPledgeViewController: UIViewController,

self.viewModel.outputs.configureEstimatedShippingView
.observeForUI()
.observeValues { [weak self] strings in
let (estimatedShippingText, estimatedConversionText) = strings
self?.configureEstimatedShippingView(estimatedShippingText, estimatedConversionText)
.observeValues { [weak self] estimatedShippingText, estimatedConversionText in
guard let shippingText = estimatedShippingText else { return }

self?.configureEstimatedShippingView(shippingText, estimatedConversionText)
}

self.viewModel.outputs.estimatedShippingViewHidden
Expand Down Expand Up @@ -434,10 +435,10 @@ final class NoShippingPledgeViewController: UIViewController,
self.pledgeDisclaimerView.configure(with: ("icon-not-a-store", attributedText))
}

private func configureEstimatedShippingView(_ estimatedCost: String, _ aboutConversion: String) {
private func configureEstimatedShippingView(_ estimatedCost: String, _ aboutConversion: String?) {
let estimatedShippingView = EstimatedShippingCheckoutView(
estimatedCost: estimatedCost,
aboutConversion: aboutConversion
aboutConversion: aboutConversion ?? ""
)

self.estimatedShippingViewContainer.rootView = estimatedShippingView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ final class NoShippingPostCampaignCheckoutViewController: UIViewController,

self.viewModel.outputs.configureEstimatedShippingView
.observeForUI()
.observeValues { [weak self] strings in
let (estimatedShippingText, estimatedConversionText) = strings
self?.configureEstimatedShippingView(estimatedShippingText, estimatedConversionText)
.observeValues { [weak self] estimatedShippingText, estimatedConversionText in
guard let shippingText = estimatedShippingText else { return }

self?.configureEstimatedShippingView(shippingText, estimatedConversionText)
}

self.viewModel.outputs.showWebHelp
Expand Down Expand Up @@ -341,10 +342,10 @@ final class NoShippingPostCampaignCheckoutViewController: UIViewController,
}
}

private func configureEstimatedShippingView(_ estimatedCost: String, _ aboutConversion: String) {
private func configureEstimatedShippingView(_ estimatedCost: String, _ aboutConversion: String?) {
let estimatedShippingView = EstimatedShippingCheckoutView(
estimatedCost: estimatedCost,
aboutConversion: aboutConversion
aboutConversion: aboutConversion ?? ""
)

self.estimatedShippingViewContainer.rootView = estimatedShippingView
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public final class RewardAddOnCardView: UIView {
self.includedItemsStackView.rac.hidden = self.viewModel.outputs.includedItemsStackViewHidden
self.includedItemsLabel.rac.attributedText = self.viewModel.outputs.includedItemsLabelAttributedText
self.estimatedShippingStackView.rac.hidden = self.viewModel.outputs.estimatedShippingStackViewHidden
self.estimatedShippingLabel.rac.text = self.viewModel.outputs.estimatedShippingLabelText
self.amountLabel.rac.attributedText = self.viewModel.outputs.amountLabelAttributedText
self.pillsView.rac.hidden = self.viewModel.outputs.pillsViewHidden
self.quantityLabel.rac.text = self.viewModel.outputs.quantityLabelText
Expand Down Expand Up @@ -243,6 +242,14 @@ public final class RewardAddOnCardView: UIView {
self.viewModel.outputs.generateNotificationWarningFeedback
.observeForUI()
.observeValues { generateNotificationWarningFeedback() }

self.viewModel.outputs.estimatedShippingLabelText
.observeForUI()
.observeValues { [weak self] text in
guard let labelText = text else { return }

self?.estimatedShippingLabel.text = labelText
}
}

// MARK: - Private Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ public final class RewardCardView: UIView {
|> baseRewardLabelStyle
|> sectionTitleLabelStyle

// TODO: Translate string
_ = self.estimatedShippingTitleLabel
|> \.text %~ { _ in "Estimated Shipping" }
|> \.text .~ Strings.Estimated_Shipping()
|> \.textColor .~ UIColor.ksr_support_400

_ = self.estimatedShippingLabel
Expand Down Expand Up @@ -199,7 +198,6 @@ public final class RewardCardView: UIView {
self.minimumPriceConversionLabel.rac.text = self.viewModel.outputs.conversionLabelText
self.descriptionLabel.rac.text = self.viewModel.outputs.descriptionLabelText
self.estimatedShippingStackView.rac.hidden = self.viewModel.outputs.estimatedShippingStackViewHidden
self.estimatedShippingLabel.rac.text = self.viewModel.outputs.estimatedShippingLabelText
self.estimatedDeliveryStackView.rac.hidden = self.viewModel.outputs.estimatedDeliveryStackViewHidden
self.estimatedDeliveryDateLabel.rac.text = self.viewModel.outputs.estimatedDeliveryDateLabelText
self.rewardLocationStackView.rac.hidden = self.viewModel.outputs.rewardLocationStackViewHidden
Expand Down Expand Up @@ -234,6 +232,14 @@ public final class RewardCardView: UIView {
.observeValues { [weak self] values in
self?.configurePillsView(values)
}

self.viewModel.outputs.estimatedShippingLabelText
.observeForUI()
.observeValues { [weak self] text in
guard let labelText = text else { return }

self?.estimatedShippingLabel.text = labelText
}
}

// MARK: - Private Helpers
Expand Down
10 changes: 5 additions & 5 deletions Library/SharedFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,13 @@ public func estimatedShippingText(
for rewards: [Reward],
project: Project,
selectedShippingRule: ShippingRule
) -> String {
) -> String? {
let (estimatedMin, estimatedMax) = estimatedMinMax(
from: rewards,
selectedShippingRule: selectedShippingRule
)

guard estimatedMin > 0, estimatedMax > 0 else { return "" }
guard estimatedMin > 0, estimatedMax > 0 else { return nil }

let currentCountry = project.stats.currentCountry ?? Project.Country.us

Expand Down Expand Up @@ -700,15 +700,15 @@ public func estimatedShippingConversionText(
for rewards: [Reward],
project: Project,
selectedShippingRule: ShippingRule
) -> String {
guard project.stats.needsConversion else { return "" }
) -> String? {
guard project.stats.needsConversion else { return nil }

let (estimatedMin, estimatedMax) = estimatedMinMax(
from: rewards,
selectedShippingRule: selectedShippingRule
)

guard estimatedMin > 0, estimatedMax > 0 else { return "" }
guard estimatedMin > 0, estimatedMax > 0 else { return nil }

let convertedMin = estimatedMin * Double(project.stats.currentCurrencyRate ?? project.stats.staticUsdRate)
let convertedMax = estimatedMax * Double(project.stats.currentCurrencyRate ?? project.stats.staticUsdRate)
Expand Down
8 changes: 4 additions & 4 deletions Library/ViewModels/NoShippingPledgeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public protocol NoShippingPledgeViewModelInputs {

public protocol NoShippingPledgeViewModelOutputs {
var beginSCAFlowWithClientSecret: Signal<String, Never> { get }
var configureEstimatedShippingView: Signal<(String, String), Never> { get }
var configureEstimatedShippingView: Signal<(String?, String?), Never> { get }
var configureLocalPickupViewWithData: Signal<PledgeLocalPickupViewData, Never> { get }
var configurePaymentMethodsViewControllerWithValue: Signal<PledgePaymentMethodsValue, Never> { get }
var configurePledgeAmountViewWithData: Signal<PledgeAmountViewConfigData, Never> { get }
Expand Down Expand Up @@ -315,7 +315,7 @@ public class NoShippingPledgeViewModel: NoShippingPledgeViewModelType, NoShippin

self.configureEstimatedShippingView = Signal.combineLatest(project, rewards, selectedShippingRule)
.map { project, rewards, shippingRule in
guard let rule = shippingRule else { return ("", "") }
guard let rule = shippingRule else { return (nil, nil) }

return (
estimatedShippingText(for: rewards, project: project, selectedShippingRule: rule),
Expand All @@ -326,7 +326,7 @@ public class NoShippingPledgeViewModel: NoShippingPledgeViewModelType, NoShippin
self.estimatedShippingViewHidden = Signal.combineLatest(self.configureEstimatedShippingView, baseReward)
.map { estimatedShippingStrings, reward in
let (estimatedShipping, _) = estimatedShippingStrings
return reward.shipping.enabled == false || estimatedShipping.isEmpty
return reward.shipping.enabled == false || estimatedShipping == nil
}

// MARK: - Apple Pay
Expand Down Expand Up @@ -1014,7 +1014,7 @@ public class NoShippingPledgeViewModel: NoShippingPledgeViewModelType, NoShippin
// MARK: - Outputs

public let beginSCAFlowWithClientSecret: Signal<String, Never>
public let configureEstimatedShippingView: Signal<(String, String), Never>
public let configureEstimatedShippingView: Signal<(String?, String?), Never>
public let configureLocalPickupViewWithData: Signal<PledgeLocalPickupViewData, Never>
public let configurePaymentMethodsViewControllerWithValue: Signal<PledgePaymentMethodsValue, Never>
public let configurePledgeAmountViewWithData: Signal<PledgeAmountViewConfigData, Never>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol NoShippingPostCampaignCheckoutViewModelInputs {
}

public protocol NoShippingPostCampaignCheckoutViewModelOutputs {
var configureEstimatedShippingView: Signal<(String, String), Never> { get }
var configureEstimatedShippingView: Signal<(String?, String?), Never> { get }
var configurePaymentMethodsViewControllerWithValue: Signal<PledgePaymentMethodsValue, Never> { get }
var configurePledgeRewardsSummaryViewWithData: Signal<
(PostCampaignRewardsSummaryViewData, Double?, PledgeSummaryViewData),
Expand Down Expand Up @@ -111,7 +111,7 @@ public class NoShippingPostCampaignCheckoutViewModel: NoShippingPostCampaignChec

self.configureEstimatedShippingView = Signal.combineLatest(project, rewards, selectedShippingRule)
.map { project, rewards, shippingRule in
guard let rule = shippingRule else { return ("", "") }
guard let rule = shippingRule else { return (nil, nil) }

return (
estimatedShippingText(for: rewards, project: project, selectedShippingRule: rule),
Expand All @@ -122,7 +122,7 @@ public class NoShippingPostCampaignCheckoutViewModel: NoShippingPostCampaignChec
self.estimatedShippingViewHidden = Signal.combineLatest(self.configureEstimatedShippingView, baseReward)
.map { estimatedShippingStrings, reward in
let (estimatedShipping, _) = estimatedShippingStrings
return reward?.shipping.enabled == false || estimatedShipping.isEmpty
return reward?.shipping.enabled == false || estimatedShipping == nil
}

// MARK: Validate Checkout Details On Submit
Expand Down Expand Up @@ -512,7 +512,7 @@ public class NoShippingPostCampaignCheckoutViewModel: NoShippingPostCampaignChec

// MARK: - Outputs

public let configureEstimatedShippingView: Signal<(String, String), Never>
public let configureEstimatedShippingView: Signal<(String?, String?), Never>
public let configurePaymentMethodsViewControllerWithValue: Signal<PledgePaymentMethodsValue, Never>
public let configurePledgeRewardsSummaryViewWithData: Signal<(
PostCampaignRewardsSummaryViewData,
Expand Down
12 changes: 7 additions & 5 deletions Library/ViewModels/RewardAddOnCardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol RewardAddOnCardViewModelOutputs {
var generateNotificationWarningFeedback: Signal<Void, Never> { get }
var includedItemsLabelAttributedText: Signal<NSAttributedString, Never> { get }
var includedItemsStackViewHidden: Signal<Bool, Never> { get }
var estimatedShippingLabelText: Signal<String, Never> { get }
var estimatedShippingLabelText: Signal<String?, Never> { get }
var estimatedShippingStackViewHidden: Signal<Bool, Never> { get }
var notifiyDelegateDidSelectQuantity: Signal<(SelectedRewardQuantity, SelectedRewardId), Never> { get }
var pillsViewHidden: Signal<Bool, Never> { get }
Expand Down Expand Up @@ -57,7 +57,7 @@ public final class RewardAddOnCardViewModel: RewardAddOnCardViewModelType, Rewar
let project: Signal<Project, Never> = configData.map(\.project)
let reward: Signal<Reward, Never> = configData.map(\.reward)
let selectedQuantities: Signal<SelectedRewardQuantities, Never> = configData.map(\.selectedQuantities)
let shippingRule: Signal<ShippingRule, Never> = configData.map(\.shippingRule).skipNil()
let shippingRule: Signal<ShippingRule?, Never> = configData.map(\.shippingRule)

let projectAndReward = Signal.zip(project, reward)
let projectRewardShippingRule = configData.map {
Expand Down Expand Up @@ -105,12 +105,14 @@ public final class RewardAddOnCardViewModel: RewardAddOnCardViewModelType, Rewar

self.estimatedShippingLabelText = Signal.combineLatest(reward, project, shippingRule)
.map { reward, project, shippingRule in
estimatedShippingText(for: [reward], project: project, selectedShippingRule: shippingRule)
guard let shipping = shippingRule else { return nil }

return estimatedShippingText(for: [reward], project: project, selectedShippingRule: shipping)
}

self.estimatedShippingStackViewHidden = Signal.combineLatest(reward, self.estimatedShippingLabelText)
.map { reward, text in
reward.shipping.enabled == false || text.isEmpty
reward.shipping.enabled == false || text == nil
}

self.reloadPills = projectAndReward.map(pillValues(project:reward:))
Expand Down Expand Up @@ -200,7 +202,7 @@ public final class RewardAddOnCardViewModel: RewardAddOnCardViewModelType, Rewar
public let generateNotificationWarningFeedback: Signal<Void, Never>
public let includedItemsLabelAttributedText: Signal<NSAttributedString, Never>
public let includedItemsStackViewHidden: Signal<Bool, Never>
public let estimatedShippingLabelText: Signal<String, Never>
public let estimatedShippingLabelText: Signal<String?, Never>
public let estimatedShippingStackViewHidden: Signal<Bool, Never>
public let notifiyDelegateDidSelectQuantity: Signal<(SelectedRewardQuantity, SelectedRewardId), Never>
public let pillsViewHidden: Signal<Bool, Never>
Expand Down
21 changes: 13 additions & 8 deletions Library/ViewModels/RewardCardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public protocol RewardCardViewModelOutputs {
var estimatedShippingStackViewHidden: Signal<Bool, Never> { get }
var estimatedDeliveryStackViewHidden: Signal<Bool, Never> { get }
var estimatedDeliveryDateLabelText: Signal<String, Never> { get }
var estimatedShippingLabelText: Signal<String, Never> { get }
var estimatedShippingLabelText: Signal<String?, Never> { get }
var includedItemsStackViewHidden: Signal<Bool, Never> { get }
var items: Signal<[String], Never> { get }
var pillCollectionViewHidden: Signal<Bool, Never> { get }
Expand Down Expand Up @@ -62,7 +62,7 @@ public final class RewardCardViewModel: RewardCardViewModelType, RewardCardViewM

let project: Signal<Project, Never> = configData.map(\.project)
let reward: Signal<Reward, Never> = configData.map(\.reward)
let currentShippingRule: Signal<ShippingRule, Never> = configData.map(\.currentShippingRule).skipNil()
let currentShippingRule: Signal<ShippingRule?, Never> = configData.map(\.currentShippingRule)

let projectAndReward = Signal.zip(project, reward)

Expand Down Expand Up @@ -130,16 +130,21 @@ public final class RewardCardViewModel: RewardCardViewModelType, RewardCardViewM

self.estimatedShippingLabelText = Signal.combineLatest(reward, project, currentShippingRule)
.map { reward, project, shippingRule in
estimatedShippingText(for: [reward], project: project, selectedShippingRule: shippingRule)
guard let shipping = shippingRule else { return nil }

return estimatedShippingText(for: [reward], project: project, selectedShippingRule: shipping)
}

self.estimatedDeliveryDateLabelText = reward.map(estimatedDeliveryDateText(with:)).skipNil()
self.rewardLocationPickupLabelText = reward.map { $0.localPickup?.displayableName }.skipNil()

self.estimatedShippingStackViewHidden = Signal.combineLatest(reward, self.estimatedShippingLabelText)
.map { reward, text in
reward.shipping.enabled == false || text.isEmpty
}
self.estimatedShippingStackViewHidden = Signal.combineLatest(
reward,
self.estimatedShippingLabelText.signal
)
.map { reward, text in
reward.shipping.enabled == false || text == nil
}
}

private let configDataProperty = MutableProperty<RewardCardViewData?>(nil)
Expand All @@ -159,7 +164,7 @@ public final class RewardCardViewModel: RewardCardViewModelType, RewardCardViewM
public let estimatedShippingStackViewHidden: Signal<Bool, Never>
public let estimatedDeliveryStackViewHidden: Signal<Bool, Never>
public let estimatedDeliveryDateLabelText: Signal<String, Never>
public let estimatedShippingLabelText: Signal<String, Never>
public let estimatedShippingLabelText: Signal<String?, Never>
public let items: Signal<[String], Never>
public let includedItemsStackViewHidden: Signal<Bool, Never>
public let pillCollectionViewHidden: Signal<Bool, Never>
Expand Down