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

IOS-2926 Membership x Multiplayer | Add membership upgrade buttons in request actions #1580

Merged
merged 1 commit into from
Jun 6, 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
1 change: 1 addition & 0 deletions Anytype/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ internal enum Loc {
internal static let button = Loc.tr("Localizable", "Membership.Upgrade.Button")
internal static let moreMembers = Loc.tr("Localizable", "Membership.Upgrade.MoreMembers")
internal static let moreSpaces = Loc.tr("Localizable", "Membership.Upgrade.MoreSpaces")
internal static let noMoreMembers = Loc.tr("Localizable", "Membership.Upgrade.NoMoreMembers")
internal static func spacesLimit(_ p1: Int) -> String {
return Loc.tr("Localizable", "Membership.Upgrade.SpacesLimit", p1)
}
Expand Down
3 changes: 2 additions & 1 deletion Anytype/Resources/Strings/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,8 @@ Please provide specific details of your needs here.";
"Membership.Upgrade.Button" = "Contact Anytype Team";

"Membership.Upgrade.MoreSpaces" = "Upgrade to add more spaces";
"Membership.Upgrade.MoreMembers" = "You can’t add more members";
"Membership.Upgrade.MoreMembers" = "Upgrade to add more members";
"Membership.Upgrade.NoMoreMembers" = "You can’t add more members";


"Membership.Banner.Title1" = "Build the Vision Together";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct MembershipUpgradeEmailBottomAlert: View {
message: Loc.Membership.Upgrade.text
) {
BottomAlertButton(
text: Loc.Membership.Upgrade.text,
text: Loc.Membership.Upgrade.button,
style: .primary
) {
action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ struct SpaceShareView: View {
}
.anytypeShareView(item: $model.shareInviteLink)
.snackbar(toastBarData: $model.toastBarData)
.anytypeSheet(item: $model.requestAlertModel) { model in
SpaceRequestAlert(data: model)
.anytypeSheet(item: $model.requestAlertModel) { alertModel in
SpaceRequestAlert(data: alertModel) {
model.onUpgradeTap()
}
}
.anytypeSheet(item: $model.changeAccessAlertModel) { model in
SpaceChangeAccessView(model: model)
Expand Down Expand Up @@ -78,7 +80,7 @@ struct SpaceShareView: View {

private var upgradeView: some View {
VStack(alignment: .leading, spacing: 0) {
AnytypeText(Loc.Membership.Upgrade.moreMembers, style: .caption1Regular)
AnytypeText(Loc.Membership.Upgrade.noMoreMembers, style: .caption1Regular)
.foregroundColor(Color.Text.primary)
Spacer.fixedHeight(12)
StandardButton("\(MembershipConstants.membershipSymbol.rawValue) \(Loc.upgrade)", style: .upgradeBadge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,56 @@ struct SpaceRequestAlert: View {
@StateObject private var model: SpaceRequestAlertModel
@Environment(\.dismiss) private var dismiss

init(data: SpaceRequestAlertData) {
_model = StateObject(wrappedValue: SpaceRequestAlertModel(data: data))
init(data: SpaceRequestAlertData, onMembershipUpgradeTap: @escaping () -> ()) {
_model = StateObject(wrappedValue: SpaceRequestAlertModel(
data: data,
onMembershipUpgradeTap: onMembershipUpgradeTap
))
}

var body: some View {
BottomAlertView(title: model.title, message: "") {
if model.showUpgradeButton {
upgradeActions
} else {
defaultActions
}
}
.throwTask {
try await model.onAppear()
}
}

private var defaultActions: [BottomAlertButton] {
[
BottomAlertButton(text: Loc.SpaceShare.ViewRequest.viewAccess, style: .secondary, disable: !model.canAddReaded) {
try await model.onViewAccess()
dismiss()
}
},
BottomAlertButton(text: Loc.SpaceShare.ViewRequest.editAccess, style: .secondary, disable: !model.canAddWriter) {
try await model.onEditAccess()
dismiss()
},
BottomAlertButton(text: Loc.SpaceShare.ViewRequest.reject, style: .warning) {
try await model.onReject()
dismiss()
}
]
}

private var upgradeActions: [BottomAlertButton] {
[
BottomAlertButton(
text: "\(MembershipConstants.membershipSymbol.rawValue) \(Loc.Membership.Upgrade.moreMembers)",
style: .primary
) {
model.onMembershipUpgrade()
dismiss()
},
BottomAlertButton(text: Loc.SpaceShare.ViewRequest.reject, style: .warning) {
try await model.onReject()
dismiss()
}
}
.throwTask {
try await model.onAppear()
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ final class SpaceRequestAlertModel: ObservableObject {
private var workspaceStorage: WorkspacesStorageProtocol

private let data: SpaceRequestAlertData
private let onMembershipUpgradeTap: () -> ()

@Published var title = ""
@Published var canAddReaded = false
@Published var canAddWriter = false
var showUpgradeButton: Bool {
!canAddWriter && !canAddReaded
}

init(data: SpaceRequestAlertData) {
init(data: SpaceRequestAlertData, onMembershipUpgradeTap: @escaping () -> ()) {
self.data = data
self.onMembershipUpgradeTap = onMembershipUpgradeTap
title = Loc.SpaceShare.ViewRequest.title(
data.participantName.withPlaceholder,
data.spaceName.withPlaceholder
Expand Down Expand Up @@ -63,4 +68,8 @@ final class SpaceRequestAlertModel: ObservableObject {
identity: data.participantIdentity
)
}

func onMembershipUpgrade() {
onMembershipUpgradeTap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ struct NotificationCoordinatorView: View {
}
.anytypeShareView(item: $model.exportSpaceUrl)
.anytypeSheet(item: $model.spaceRequestAlert) {
SpaceRequestAlert(data: $0)
SpaceRequestAlert(data: $0) {
model.onMembershipUpgrateTap()
}
}
.membershipUpgrade(isPresented: $model.showMembershipUpgrade, reason: .numberOfSpaceMembers)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class NotificationCoordinatorViewModel: ObservableObject {
@Published var spaceIdForDeleteAlert: StringIdentifiable?
@Published var exportSpaceUrl: URL?
@Published var spaceRequestAlert: SpaceRequestAlertData?
@Published var showMembershipUpgrade = false

func onAppear() {
Task {
Expand All @@ -38,6 +39,10 @@ final class NotificationCoordinatorViewModel: ObservableObject {
self.dismissAllPresented = dismissAllPresented
}

func onMembershipUpgrateTap() {
showMembershipUpgrade = true
}

// MARK: - Private

private func handle(events: [NotificationEvent]) async {
Expand Down
Loading