Skip to content

Commit

Permalink
show the correct pledge CTA on project and rewards pages for PCP
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkicks committed Feb 20, 2024
1 parent 8aa9945 commit 60ebf16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Library/RewardCellProjectBackingStateType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum RewardCellProjectBackingStateType: Equatable {
public enum ProjectState {
case nonLive
case live
case successful
}

case backedError
Expand All @@ -13,13 +14,20 @@ public enum RewardCellProjectBackingStateType: Equatable {

static func state(with project: Project) -> RewardCellProjectBackingStateType {
guard let backing = project.personalization.backing else {
if featurePostCampaignPledgeEnabled(), project.postCampaignPledgingEnabled,
project.isInPostCampaignPledgingPhase {
return (.nonBacked(live: .successful))
}

return .nonBacked(live: project.state == .live ? .live : .nonLive)
}

// NB: Add error case back once correctly returned
switch (project.state, backing.status) {
case(.live, _):
return .backed(live: .live)
case (.successful, _):
return .backed(live: .successful)
case (_, _):
return .backed(live: .nonLive)
}
Expand Down
9 changes: 9 additions & 0 deletions Library/SharedFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ public func rewardsCarouselCanNavigateToReward(_ reward: Reward, in project: Pro
let isAvailableForNewBacker = rewardIsAvailable(project: project, reward: reward) && !isBacking
let isAvailableForExistingBackerToEdit = (isBacking && reward.hasAddOns)

if featurePostCampaignPledgeEnabled(), project.postCampaignPledgingEnabled,
project.isInPostCampaignPledgingPhase {
return [
project.state == .successful,
isAvailableForNewBacker || isAvailableForExistingBackerToEdit
]
.allSatisfy(isTrue)
}

return [
project.state == .live,
isAvailableForNewBacker || isAvailableForExistingBackerToEdit
Expand Down
5 changes: 5 additions & 0 deletions Library/ViewModels/PledgeCTAContainerViewViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ private func pledgeCTA(project: Project, backing: Backing?) -> PledgeStateCTATyp
return PledgeStateCTAType.viewYourRewards
}

if featurePostCampaignPledgeEnabled(), project.postCampaignPledgingEnabled,
project.isInPostCampaignPledgingPhase {
return PledgeStateCTAType.pledge
}

return project.state == .live ? PledgeStateCTAType.pledge : PledgeStateCTAType.viewRewards
}

Expand Down
6 changes: 5 additions & 1 deletion Library/ViewModels/RewardCardContainerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ private func pledgeButtonTitle(project: Project, reward: Reward) -> String? {
case (.nonBacked(.live), _, true):
return Strings.Select()
case (.backed(.nonLive), false, _),
(.nonBacked(.nonLive), _, _):
(.nonBacked(.nonLive), _, _), (.backed(live: .successful), _, _):
return nil
case (_, _, false):
return Strings.No_longer_available()
case (.nonBacked(.successful), _, _):
return Strings.Select()
}
}

Expand Down Expand Up @@ -146,6 +148,8 @@ private func buttonStyleType(project: Project, reward: Reward) -> ButtonStyleTyp
return .none
case .nonBacked(.nonLive):
return .none
case .nonBacked(live: .successful), .backed(live: .successful):
return .green
}

return .green
Expand Down

0 comments on commit 60ebf16

Please sign in to comment.