Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
#Conflicts:
#	Splito/UI/Login/LoginView.swift
  • Loading branch information
cp-nirali-s committed Dec 5, 2024
2 parents 6b0b06a + 0fdac4c commit a5ba912
Show file tree
Hide file tree
Showing 47 changed files with 341 additions and 127 deletions.
9 changes: 4 additions & 5 deletions BaseStyle/BaseStyle/Views/AlertPrompt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Amisha Italiya on 22/02/24.
//

import Foundation
import SwiftUI

public struct AlertPrompt {
Expand All @@ -28,7 +27,7 @@ public struct AlertPrompt {
}
}

public struct Backport<Content> {
public struct AlertView<Content> {
public let content: Content

public init(content: Content) {
Expand All @@ -37,10 +36,10 @@ public struct Backport<Content> {
}

public extension View {
var backport: Backport<Self> { Backport(content: self) }
var alertView: AlertView<Self> { AlertView(content: self) }
}

public extension Backport where Content: View {
public extension AlertView where Content: View {
@ViewBuilder func alert(isPresented: Binding<Bool>, alertStruct: AlertPrompt) -> some View {
content
.alert(alertStruct.title.localized, isPresented: isPresented) {
Expand All @@ -55,7 +54,7 @@ public extension Backport where Content: View {
})
}
if alertStruct.positiveBtnTitle == nil && alertStruct.negativeBtnTitle == nil {
Button("Ok".localized, role: .cancel, action: {
Button("Ok", role: .cancel, action: {
isPresented.wrappedValue = false
})
}
Expand Down
2 changes: 1 addition & 1 deletion Data/Data/DI/Injector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Injector {
appAssembler = Assembler([AppAssembly()])
}

public func setTestAassembler(assemblies: [Assembly]) {
public func setTestAssembler(assemblies: [Assembly]) {
appAssembler = Assembler(assemblies)
}
}
Expand Down
10 changes: 7 additions & 3 deletions Data/Data/Model/ActivityLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public struct ActivityLog: Codable, Identifiable, Hashable {
public let expenseName: String?
public let payerName: String?
public let receiverName: String?
public let paymentReason: String?
public let amount: Double?

public init(type: ActivityType, groupId: String, activityId: String, groupName: String, actionUserName: String,
recordedOn: Timestamp, previousGroupName: String? = nil, removedMemberName: String? = nil,
expenseName: String? = nil, payerName: String? = nil, receiverName: String? = nil, amount: Double? = nil) {
public init(type: ActivityType, groupId: String, activityId: String, groupName: String,
actionUserName: String, recordedOn: Timestamp, previousGroupName: String? = nil,
removedMemberName: String? = nil, expenseName: String? = nil, payerName: String? = nil,
receiverName: String? = nil, paymentReason: String? = nil, amount: Double? = nil) {
self.type = type
self.groupId = groupId
self.activityId = activityId
Expand All @@ -43,6 +45,7 @@ public struct ActivityLog: Codable, Identifiable, Hashable {
self.expenseName = expenseName
self.payerName = payerName
self.receiverName = receiverName
self.paymentReason = paymentReason
self.amount = amount
}

Expand All @@ -59,6 +62,7 @@ public struct ActivityLog: Codable, Identifiable, Hashable {
case expenseName = "expense_name"
case payerName = "payer_name"
case receiverName = "receiver_name"
case paymentReason = "payment_reason"
case amount
}
}
Expand Down
10 changes: 7 additions & 3 deletions Data/Data/Model/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ public struct Transactions: Codable, Hashable, Identifiable {
public var updatedBy: String
public var note: String?
public var imageUrl: String?
public var reason: String?
public var amount: Double
public var date: Timestamp
public var updatedAt: Timestamp
public var isActive: Bool

public init(payerId: String, receiverId: String, addedBy: String, updatedBy: String, note: String? = nil,
imageUrl: String? = nil, amount: Double, date: Timestamp, updatedAt: Timestamp = Timestamp(), isActive: Bool = true) {
public init(payerId: String, receiverId: String, addedBy: String, updatedBy: String,
note: String? = nil, imageUrl: String? = nil, reason: String? = nil, amount: Double,
date: Timestamp, updatedAt: Timestamp = Timestamp(), isActive: Bool = true) {
self.payerId = payerId
self.receiverId = receiverId
self.addedBy = addedBy
self.updatedBy = updatedBy
self.note = note
self.imageUrl = imageUrl
self.reason = reason
self.amount = amount
self.date = date
self.updatedAt = updatedAt
Expand All @@ -42,8 +45,9 @@ public struct Transactions: Codable, Hashable, Identifiable {
case receiverId = "receiver_id"
case addedBy = "added_by"
case updatedBy = "updated_by"
case note = "note"
case note
case imageUrl = "image_url"
case reason
case amount
case date
case updatedAt = "updated_at"
Expand Down
1 change: 1 addition & 0 deletions Data/Data/Repository/ActivityLogRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct ActivityLogContext {
var currentUser: AppUser?
var payerName: String?
var receiverName: String?
var paymentReason: String?
var previousGroupName: String?
var removedMemberName: String?
}
16 changes: 8 additions & 8 deletions Data/Data/Repository/TransactionRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public class TransactionRepository: ObservableObject {
private func hasTransactionChanged(_ transaction: Transactions, oldTransaction: Transactions) -> Bool {
return oldTransaction.payerId != transaction.payerId || oldTransaction.receiverId != transaction.receiverId ||
oldTransaction.updatedBy != transaction.updatedBy || oldTransaction.note != transaction.note ||
oldTransaction.imageUrl != transaction.imageUrl || oldTransaction.amount != transaction.amount ||
oldTransaction.date.dateValue() != transaction.date.dateValue() ||
oldTransaction.imageUrl != transaction.imageUrl || oldTransaction.reason != transaction.reason ||
oldTransaction.amount != transaction.amount || oldTransaction.date.dateValue() != transaction.date.dateValue() ||
oldTransaction.updatedAt.dateValue() != transaction.updatedAt.dateValue() || oldTransaction.isActive != transaction.isActive
}

Expand All @@ -103,8 +103,9 @@ public class TransactionRepository: ObservableObject {
guard let self else { return nil }
let payerName = (user.id == transaction.payerId && memberId == transaction.payerId) ? (user.id == transaction.addedBy ? "You" : "you") : (memberId == transaction.payerId) ? "you" : members.payer.nameWithLastInitial
let receiverName = (memberId == transaction.receiverId) ? "you" : (memberId == transaction.receiverId) ? "you" : members.receiver.nameWithLastInitial
let context = ActivityLogContext(group: group, transaction: transaction, type: type, memberId: memberId,
currentUser: user, payerName: payerName, receiverName: receiverName)
let context = ActivityLogContext(group: group, transaction: transaction, type: type,
memberId: memberId, currentUser: user, payerName: payerName,
receiverName: receiverName, paymentReason: transaction.reason)

return await self.addActivityLog(context: context)
}
Expand All @@ -131,10 +132,9 @@ public class TransactionRepository: ObservableObject {
let actionUserName = (context.memberId == currentUser.id) ? "You" : currentUser.nameWithLastInitial
let amount: Double = (context.memberId == transaction.payerId) ? transaction.amount : (context.memberId == transaction.receiverId) ? -transaction.amount : 0

return ActivityLog(type: context.type, groupId: groupId, activityId: transactionId,
groupName: context.group?.name ?? "", actionUserName: actionUserName,
recordedOn: Timestamp(date: Date()), payerName: context.payerName,
receiverName: context.receiverName, amount: amount)
return ActivityLog(type: context.type, groupId: groupId, activityId: transactionId, groupName: context.group?.name ?? "",
actionUserName: actionUserName, recordedOn: Timestamp(date: Date()), payerName: context.payerName,
receiverName: context.receiverName, paymentReason: context.paymentReason, amount: amount)
}

private func addActivityLog(context: ActivityLogContext) async -> Error? {
Expand Down
15 changes: 14 additions & 1 deletion Splito/Localization/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
}
}
},
"%@ paid %@ for '%@'" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ paid %2$@ for '%3$@'"
}
}
}
},
"%@ people" : {
"extractionState" : "manual"
},
Expand Down Expand Up @@ -314,6 +324,9 @@
"Enter a description" : {
"extractionState" : "manual"
},
"Enter a reason for this payment" : {
"extractionState" : "manual"
},
"Enter a valid phone number." : {
"extractionState" : "manual"
},
Expand All @@ -339,7 +352,7 @@
"extractionState" : "manual"
},
"Enter your note here..." : {

"extractionState" : "manual"
},
"Enter your phone number" : {
"extractionState" : "manual"
Expand Down
2 changes: 1 addition & 1 deletion Splito/UI/Home/Account/AccountHomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct AccountHomeView: View {
}
.background(surfaceColor)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.sheet(isPresented: $viewModel.showShareSheet) {
MailComposeView(logFilePath: viewModel.logFilePath, showToast: viewModel.showMailSendToast)
}
Expand Down
2 changes: 1 addition & 1 deletion Splito/UI/Home/Account/User Profile/UserProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct UserProfileView: View {
.frame(maxWidth: isIpad ? 600 : nil, alignment: .center)
.frame(maxWidth: .infinity, alignment: .center)
.background(surfaceColor)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.toastView(toast: $viewModel.toast)
.toolbarRole(.editor)
.toolbar {
Expand Down
33 changes: 26 additions & 7 deletions Splito/UI/Home/ActivityLog/ActivityLogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ActivityLogView: View {
}
.background(surfaceColor)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Text("Activity")
Expand Down Expand Up @@ -192,6 +192,7 @@ private struct ActivityLogDescriptionView: View {
let type: ActivityType
let payerName: String
var receiverName: String
var paymentReason: String?
let groupName: String
var oldGroupName: String
let actionUserName: String
Expand All @@ -202,6 +203,7 @@ private struct ActivityLogDescriptionView: View {
self.type = activityLog.type
self.payerName = activityLog.payerName ?? "Someone"
self.receiverName = activityLog.receiverName ?? "Someone"
self.paymentReason = activityLog.paymentReason
self.groupName = activityLog.groupName
self.oldGroupName = activityLog.previousGroupName ?? ""
self.actionUserName = activityLog.actionUserName
Expand Down Expand Up @@ -276,18 +278,35 @@ private struct ActivityLogDescriptionView: View {
if actionUserName != payerName && actionUserName != receiverName {
transactionDescription()
} else if actionUserName != payerName {
highlightedText(actionUserName) + disabledText(" recorded a payment from ") +
highlightedText(payerName) + disabledText(" in") + highlightedText(" \"\(groupName)\".")
if let paymentReason, !paymentReason.isEmpty {
highlightedText(actionUserName) + disabledText(" recorded a payment from ") +
highlightedText(payerName) + disabledText(" for") + highlightedText(" \"\(paymentReason)\"") +
disabledText(" in") + highlightedText(" \"\(groupName)\".")
} else {
highlightedText(actionUserName) + disabledText(" recorded a payment from ") +
highlightedText(payerName) + disabledText(" in") + highlightedText(" \"\(groupName)\".")
}
} else {
highlightedText(payerName) + disabledText(" paid ") + highlightedText(receiverName) +
disabledText(" in") + highlightedText(" \"\(groupName)\".")
if let paymentReason, !paymentReason.isEmpty {
highlightedText(payerName) + disabledText(" paid ") + highlightedText(receiverName) + disabledText(" for") +
highlightedText(" \"\(paymentReason)\"") + disabledText(" in") + highlightedText(" \"\(groupName)\".")
} else {
highlightedText(payerName) + disabledText(" paid ") + highlightedText(receiverName) +
disabledText(" in") + highlightedText(" \"\(groupName)\".")
}
}
}

@ViewBuilder
private func transactionDescription(action: String = "added") -> some View {
highlightedText(actionUserName) + disabledText(" \(action) a payment from ") + highlightedText(payerName) +
disabledText(" to ") + highlightedText(receiverName) + disabledText(" in") + highlightedText(" \"\(groupName)\".")
if let paymentReason, !paymentReason.isEmpty {
highlightedText(actionUserName) + disabledText(" \(action) a payment from ") + highlightedText(payerName) +
disabledText(" to ") + highlightedText(receiverName) + disabledText(" for") +
highlightedText(" \"\(paymentReason)\"") + disabledText(" in") + highlightedText(" \"\(groupName)\".")
} else {
highlightedText(actionUserName) + disabledText(" \(action) a payment from ") + highlightedText(payerName) +
disabledText(" to ") + highlightedText(receiverName) + disabledText(" in") + highlightedText(" \"\(groupName)\".")
}
}

private func highlightedText(_ text: String) -> Text {
Expand Down
10 changes: 7 additions & 3 deletions Splito/UI/Home/Expense/AddExpenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct AddExpenseView: View {
.navigationTitle(viewModel.expenseId == nil ? "Add expense" : "Edit expense")
.navigationBarTitleDisplayMode(.inline)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.sheet(isPresented: $viewModel.showGroupSelection) {
NavigationStack {
SelectGroupView(viewModel: SelectGroupViewModel(selectedGroup: viewModel.selectedGroup,
Expand Down Expand Up @@ -78,8 +78,12 @@ struct AddExpenseView: View {
}
.sheet(isPresented: $viewModel.showAddNoteEditor) {
NavigationStack {
AddNoteView(viewModel: AddNoteViewModel(group: viewModel.selectedGroup, expense: viewModel.expense, note: viewModel.expenseNote,
handleSaveNoteTap: viewModel.handleNoteSaveBtnTap(note:)))
AddNoteView(viewModel: AddNoteViewModel(
group: viewModel.selectedGroup, expense: viewModel.expense, note: viewModel.expenseNote,
handleSaveNoteTap: { note, _ in
viewModel.handleNoteSaveBtnTap(note: note)
}
))
}
}
.sheet(isPresented: $viewModel.showImagePicker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ChooseMultiplePayerView: View {
.interactiveDismissDisabled()
.toolbar(.hidden, for: .navigationBar)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.onTapGesture {
UIApplication.shared.endEditing()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct ChoosePayerView: View {
.interactiveDismissDisabled()
.toolbar(.hidden, for: .navigationBar)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct SelectGroupView: View {
.interactiveDismissDisabled()
.toolbar(.hidden, for: .navigationBar)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ExpenseDetailsView: View {

ExpenseInfoView(viewModel: viewModel)

if let imageUrl = viewModel.expense?.imageUrl {
if let imageUrl = viewModel.expense?.imageUrl, !imageUrl.isEmpty {
VStack(spacing: 8) {
Text("Attachment:")
.font(.subTitle3())
Expand Down Expand Up @@ -60,7 +60,7 @@ struct ExpenseDetailsView: View {
}
.background(surfaceColor)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.fullScreenCover(isPresented: $viewModel.showEditExpenseSheet) {
NavigationStack {
AddExpenseView(viewModel: AddExpenseViewModel(router: viewModel.router, groupId: viewModel.groupId, expenseId: viewModel.expenseId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct ExpenseSplitOptionsView: View {
.interactiveDismissDisabled()
.toolbar(.hidden, for: .navigationBar)
.toastView(toast: $viewModel.toast)
.backport.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.alertView.alert(isPresented: $viewModel.showAlert, alertStruct: viewModel.alert)
.onTapGesture {
UIApplication.shared.endEditing()
}
Expand Down
Loading

0 comments on commit a5ba912

Please sign in to comment.