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-1207] Pledge Button on Project Page #1951

Merged
merged 6 commits into from
Feb 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 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 inPostCampaignPledgingPhase
}

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

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

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

Expand Down
8 changes: 8 additions & 0 deletions Library/SharedFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ public func rewardsCarouselCanNavigateToReward(_ reward: Reward, in project: Pro
let isAvailableForNewBacker = rewardIsAvailable(project: project, reward: reward) && !isBacking
let isAvailableForExistingBackerToEdit = (isBacking && reward.hasAddOns)

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

return [
project.state == .live,
isAvailableForNewBacker || isAvailableForExistingBackerToEdit
Expand Down
16 changes: 12 additions & 4 deletions Library/ViewModels/PledgeCTAContainerViewViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,29 @@ private func pledgeCTA(project: Project, backing: Backing?) -> PledgeStateCTATyp
return .prelaunch(saved: projectIsSaved, watchCount: project.watchesCount ?? 0)
}

let isInPostCampaign = featurePostCampaignPledgeEnabled() && project.isInPostCampaignPledgingPhase

guard let projectBacking = backing, project.personalization.isBacking == .some(true) else {
if currentUserIsCreator(of: project) {
return PledgeStateCTAType.viewYourRewards
}

if isInPostCampaign {
return PledgeStateCTAType.pledge
}

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

// NB: Add error case back once correctly returned
switch (project.state, projectBacking.status) {
case (.live, _):
switch (project.state, projectBacking.status, isInPostCampaign) {
case (.live, _, _):
return .manage
case (.successful, .errored):
case (.successful, _, true):
return .viewBacking
case (.successful, .errored, _):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong here, but I think a user could have an errored backing even if the project is in a post campaign state. If that's the case, we'd want to check the errored case first, in which case I don't think we actually need any custom post campaign logic at all?

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

Expand Down Expand Up @@ -144,8 +147,11 @@ private func buttonStyleType(project: Project, reward: Reward) -> ButtonStyleTyp
return .black
}
return .none
case .nonBacked(.nonLive):
case .nonBacked(.nonLive),
.backed(.inPostCampaignPledgingPhase):
return .none
case .nonBacked(.inPostCampaignPledgingPhase):
return .green
}

return .green
Expand Down