Skip to content

Commit

Permalink
Merge pull request #1315 from HedvigInsurance/feature/drulle/GEN-1924…
Browse files Browse the repository at this point in the history
…-add-repair-cost

GEN-1924: Add repairCostAmount and design for SubmitClaimCheckoutScreen
  • Loading branch information
juliaendre authored May 14, 2024
2 parents a7395b4 + 6824a8a commit 83e71c3
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 213 deletions.
41 changes: 31 additions & 10 deletions Projects/Claims/GraphQL/Octopus/StartClaimsFlow.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,13 @@ fragment FlowClaimPhoneNumberStepFragment on FlowClaimPhoneNumberStep {
}
fragment FlowClaimSingleItemCheckoutStepFragment on FlowClaimSingleItemCheckoutStep {
id
price {
...MoneyFragment
}
depreciation {
...MoneyFragment
}
deductible {
...MoneyFragment
compensation {
...FlowClaimSingleItemCheckoutCompensationFragment
}
payoutAmount {
...MoneyFragment
singleItemStep {
...FlowClaimSingleItemStepFragment
}

availableCheckoutMethods {
id
...FlowClaimAutomaticAutogiroPayoutFragment
Expand Down Expand Up @@ -187,6 +182,7 @@ fragment FlowClaimSingleItemStepFragment on FlowClaimSingleItemStep {
itemModelId
}
customName
purchasePriceApplicable
}

fragment FlowClaimSuccessStepFragment on FlowClaimSuccessStep {
Expand Down Expand Up @@ -247,3 +243,28 @@ fragment FlowClaimConfirmEmergencyOptionFragment on FlowClaimConfirmEmergencyOpt
displayName
displayValue: value
}

fragment FlowClaimSingleItemCheckoutCompensationFragment on FlowClaimSingleItemCheckoutCompensation {
id
deductible {
...MoneyFragment
}
payoutAmount {
...MoneyFragment
}

... on FlowClaimSingleItemCheckoutRepairCompensation {
repairCost {
...MoneyFragment
}
}

... on FlowClaimSingleItemCheckoutValueCompensation {
price {
...MoneyFragment
}
depreciation {
...MoneyFragment
}
}
}
4 changes: 2 additions & 2 deletions Projects/Claims/Sources/Journeys/ClaimJourneys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ClaimJourneys {
openSummaryScreen().addDismissClaimsFlow().configureTitle(L10n.Claims.Summary.Screen.title)
} else if case .openDamagePickerScreen = navigationAction {
openDamagePickerScreen().configureTitle(L10n.Claims.Item.Screen.Damage.button)
} else if case .openCheckoutNoRepairScreen = navigationAction {
} else if case .openClaimCheckoutScreen = navigationAction {
openCheckoutNoRepairScreen().addDismissClaimsFlow()
.configureTitle(L10n.Claims.Payout.Summary.title)
} else if case .openFailureSceen = navigationAction {
Expand Down Expand Up @@ -433,7 +433,7 @@ public class ClaimJourneys {
private static func openCheckoutNoRepairScreen() -> some JourneyPresentation {
HostingJourney(
SubmitClaimStore.self,
rootView: SubmitClaimCheckoutNoRepairScreen()
rootView: SubmitClaimCheckoutScreen()
) {
action in
if case .navigationAction(.openCheckoutTransferringScreen) = action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@ import hGraphQL

public struct FlowClaimSingleItemCheckoutStepModel: FlowClaimStepModel {
let id: String
let deductible: MonetaryAmount
let depreciation: MonetaryAmount
let payoutAmount: MonetaryAmount
let price: MonetaryAmount
let compensation: Compensation
let payoutMethods: [AvailableCheckoutMethod]
var selectedPayoutMethod: AvailableCheckoutMethod?
let singleItemModel: FlowClamSingleItemStepModel?

init(
id: String,
payoutMethods: [AvailableCheckoutMethod],
selectedPayoutMethod: AvailableCheckoutMethod? = nil,
compensation: Compensation,
singleItemModel: FlowClamSingleItemStepModel?
) {
self.id = id
self.payoutMethods = payoutMethods
self.selectedPayoutMethod = selectedPayoutMethod
self.compensation = compensation
self.singleItemModel = singleItemModel
}

init(
with data: OctopusGraphQL.FlowClaimSingleItemCheckoutStepFragment
) {
self.id = data.id
self.deductible = .init(fragment: data.deductible.fragments.moneyFragment)
self.depreciation = .init(fragment: data.depreciation.fragments.moneyFragment)
self.payoutAmount = .init(fragment: data.payoutAmount.fragments.moneyFragment)
self.price = .init(fragment: data.price.fragments.moneyFragment)
self.compensation = .init(with: data.compensation.fragments.flowClaimSingleItemCheckoutCompensationFragment)
if let singleItemFragment = data.singleItemStep?.fragments.flowClaimSingleItemStepFragment {
self.singleItemModel = .init(with: singleItemFragment)
} else {
self.singleItemModel = nil
}

self.payoutMethods = data.availableCheckoutMethods.compactMap({
let id = $0.id
Expand All @@ -32,7 +46,7 @@ public struct FlowClaimSingleItemCheckoutStepModel: FlowClaimStepModel {
}

public func returnSingleItemCheckoutInfo() -> OctopusGraphQL.FlowClaimSingleItemCheckoutInput? {
return selectedPayoutMethod?.getCheckoutInput(forAmount: Double(payoutAmount.floatAmount))
return selectedPayoutMethod?.getCheckoutInput(forAmount: Double(compensation.payoutAmount.floatAmount))
}
}

Expand Down Expand Up @@ -74,6 +88,16 @@ struct ClaimAutomaticAutogiroPayoutModel: Codable, Equatable, Hashable {
let amount: MonetaryAmount
let displayName: String

init(
id: String,
amount: MonetaryAmount,
displayName: String
) {
self.id = id
self.amount = amount
self.displayName = displayName
}

init(
with data: OctopusGraphQL.FlowClaimAutomaticAutogiroPayoutFragment
) {
Expand All @@ -82,3 +106,74 @@ struct ClaimAutomaticAutogiroPayoutModel: Codable, Equatable, Hashable {
self.amount = .init(fragment: data.amount.fragments.moneyFragment)
}
}

struct Compensation: Codable, Equatable, Hashable {
let id: String
let deductible: MonetaryAmount
let payoutAmount: MonetaryAmount
let repairCompensation: RepairCompensation?
let valueCompensation: ValueCompensation?

init(
with data: OctopusGraphQL.FlowClaimSingleItemCheckoutCompensationFragment
) {
self.id = data.id
self.deductible = .init(fragment: data.deductible.fragments.moneyFragment)
self.payoutAmount = .init(fragment: data.payoutAmount.fragments.moneyFragment)

self.repairCompensation = .init(with: data.asFlowClaimSingleItemCheckoutRepairCompensation)
self.valueCompensation = .init(with: data.asFlowClaimSingleItemCheckoutValueCompensation)
}

init(
id: String,
deductible: MonetaryAmount,
payoutAmount: MonetaryAmount,
repairCompensation: RepairCompensation?,
valueCompensation: ValueCompensation?
) {
self.id = id
self.deductible = deductible
self.payoutAmount = payoutAmount
self.repairCompensation = repairCompensation
self.valueCompensation = valueCompensation
}

struct RepairCompensation: Codable, Equatable, Hashable {
let repairCost: MonetaryAmount

init?(
with data: OctopusGraphQL.FlowClaimSingleItemCheckoutCompensationFragment
.AsFlowClaimSingleItemCheckoutRepairCompensation?
) {
guard let data else {
return nil
}
self.repairCost = .init(fragment: data.repairCost.fragments.moneyFragment)
}
}

struct ValueCompensation: Codable, Equatable, Hashable {
let depreciation: MonetaryAmount
let price: MonetaryAmount

init(
depreciation: MonetaryAmount,
price: MonetaryAmount
) {
self.depreciation = depreciation
self.price = price
}

init?(
with data: OctopusGraphQL.FlowClaimSingleItemCheckoutCompensationFragment
.AsFlowClaimSingleItemCheckoutValueCompensation?
) {
guard let data else {
return nil
}
self.depreciation = .init(fragment: data.depreciation.fragments.moneyFragment)
self.price = .init(fragment: data.price.fragments.moneyFragment)
}
}
}
46 changes: 46 additions & 0 deletions Projects/Claims/Sources/Models/FlowClamSingleItemStepModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ public struct FlowClamSingleItemStepModel: FlowClaimStepModel {
var selectedItemModel: String?
var selectedItemProblems: [String]?
let defaultItemProblems: [String]?
let purchasePriceApplicable: Bool

init(
id: String,
availableItemBrandOptions: [ClaimFlowItemBrandOptionModel],
availableItemModelOptions: [ClaimFlowItemModelOptionModel],
availableItemProblems: [ClaimFlowItemProblemOptionModel],
customName: String? = nil,
prefferedCurrency: String?,
purchaseDate: String? = nil,
purchasePrice: Double? = nil,
currencyCode: String?,
selectedItemBrand: String? = nil,
selectedItemModel: String? = nil,
selectedItemProblems: [String]? = nil,
defaultItemProblems: [String]?,
purchasePriceApplicable: Bool
) {
self.id = id
self.availableItemBrandOptions = availableItemBrandOptions
self.availableItemModelOptions = availableItemModelOptions
self.availableItemProblems = availableItemProblems
self.customName = customName
self.prefferedCurrency = prefferedCurrency
self.purchaseDate = purchaseDate
self.purchasePrice = purchasePrice
self.currencyCode = currencyCode
self.selectedItemBrand = selectedItemBrand
self.selectedItemModel = selectedItemModel
self.selectedItemProblems = selectedItemProblems
self.defaultItemProblems = defaultItemProblems
self.purchasePriceApplicable = purchasePriceApplicable
}

init(
with data: OctopusGraphQL.FlowClaimSingleItemStepFragment
Expand All @@ -35,6 +68,7 @@ public struct FlowClamSingleItemStepModel: FlowClaimStepModel {
self.currencyCode = data.purchasePrice?.currencyCode.rawValue
self.selectedItemBrand = data.selectedItemBrand
self.selectedItemModel = data.selectedItemModel
self.purchasePriceApplicable = data.purchasePriceApplicable

if self.selectedItemModel == nil && self.customName == nil {
let currentDeviceName = UIDevice.modelName.lowercased()
Expand Down Expand Up @@ -167,6 +201,18 @@ public struct ClaimFlowItemModelOptionModel: Codable, Equatable, Hashable {
let itemTypeId: String
let itemModelId: String

init(
displayName: String,
itemBrandId: String,
itemTypeId: String,
itemModelId: String
) {
self.displayName = displayName
self.itemBrandId = itemBrandId
self.itemTypeId = itemTypeId
self.itemModelId = itemModelId
}

init(
with model: OctopusGraphQL.FlowClaimSingleItemStepFragment.AvailableItemModel
) {
Expand Down
4 changes: 2 additions & 2 deletions Projects/Claims/Sources/SubmitClaimAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public enum SubmitClaimsNavigationAction: ActionProtocol, Hashable {
case openModelPicker
case openBrandPicker
case openPriceInput
case openCheckoutNoRepairScreen
case openClaimCheckoutScreen
case openCheckoutTransferringScreen
case openFailureSceen
case openUpdateAppScreen
Expand Down Expand Up @@ -157,7 +157,7 @@ extension ClaimsStepModelAction {
case .setSummaryStep:
return .openSummaryScreen
case .setSingleItemCheckoutStep:
return .openCheckoutNoRepairScreen
return .openClaimCheckoutScreen
case .setSuccessStep:
return .openSuccessScreen
case .setFailedStep:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public struct SubmitClaimSingleItem: View {
VStack(spacing: 4) {
displayBrandAndModelField(singleItemStep: singleItemStep)
displayDateField(claim: singleItemStep)
displayPurchasePriceField(claim: singleItemStep)
if let singleItemStep, singleItemStep.purchasePriceApplicable {
displayPurchasePriceField(claim: singleItemStep)
}
displayDamageField(claim: singleItemStep)
}
InfoCard(text: L10n.claimsSingleItemNoticeLabel, type: .info)
Expand Down
Loading

0 comments on commit 83e71c3

Please sign in to comment.