Skip to content

Commit 793c3cd

Browse files
authored
Merge pull request #103 from MarketPlace-O2O-Platform/Fix#102/UnauthenticatedErrorHandling
[Fix] 비로그인 상태 에러 시 팝업 뷰 표시 기능 추가
2 parents 56178b9 + 85850e7 commit 793c3cd

8 files changed

Lines changed: 276 additions & 185 deletions

File tree

MarketPlace/Model/CouponBasicModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct CouponBasicModel: Codable, Identifiable {
1919
var thumbnail: String
2020
var isAvailable: Bool
2121
var isMemberIssued: Bool
22+
var couponType: String
2223

2324
var id: Int { couponId }
2425
}

MarketPlace/Model/CouponModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct CouponNewModel: Codable, Identifiable {
3636
}
3737

3838
struct CouponValidModel: Codable, Identifiable {
39-
let couponId: Int
39+
var couponId: Int
4040
let couponName: String
4141
let couponDescription: String
4242
let deadLine: String?

MarketPlace/View/Components/CouponInfoCell.swift

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@ import SwiftUI
22

33
struct CouponInfoCell: View {
44
@ObservedObject var viewModel: CouponInfoCellViewModel
5+
@EnvironmentObject var loginViewModel: LoginViewModel
56

7+
@Binding var isLoginRequiredPopupVisible: Bool
8+
@Binding var isPopupVisible: Bool
9+
@Binding var coupon: CouponBasicModel
10+
611
var isMemberIssued: Bool { return viewModel.coupon.isMemberIssued }
712

8-
init(viewModel: CouponInfoCellViewModel) {
13+
init(
14+
viewModel: CouponInfoCellViewModel,
15+
isLoginRequiredPopupVisible: Binding<Bool>,
16+
isPopupVisible: Binding<Bool>,
17+
coupon: Binding<CouponBasicModel>
18+
) {
919
self.viewModel = viewModel
20+
self._isLoginRequiredPopupVisible = isLoginRequiredPopupVisible
21+
self._isPopupVisible = isPopupVisible
22+
self._coupon = coupon
1023
}
1124

12-
@State private var showDownloadSuccess = false
13-
1425
var body: some View {
1526
HStack(alignment: .top) {
1627
ShimmeringAsyncImage(
@@ -26,6 +37,7 @@ struct CouponInfoCell: View {
2637
Text(viewModel.coupon.marketName)
2738
.pretendardFont(size: 14, weight: .semibold)
2839
.foregroundColor(Color(hex: "333333"))
40+
.padding(.bottom, 3)
2941

3042
Text(viewModel.coupon.couponName)
3143
.pretendardFont(size: 18, weight: .bold)
@@ -42,16 +54,17 @@ struct CouponInfoCell: View {
4254
Text(viewModel.coupon.address)
4355
.pretendardFont(size: 13, weight: .medium)
4456
.foregroundColor(Color(hex: "333333"))
57+
4558
Spacer()
4659

4760
Button(action: {
48-
if !isMemberIssued {
49-
Task {
50-
let result = await viewModel.downloadCoupon(couponId: viewModel.coupon.couponId)
51-
await MainActor.run {
52-
showDownloadSuccess = result
53-
}
54-
}
61+
if !loginViewModel.isLoggedIn {
62+
isLoginRequiredPopupVisible = true
63+
}
64+
65+
else if !isMemberIssued && loginViewModel.isLoggedIn {
66+
coupon = viewModel.coupon
67+
isPopupVisible = true
5568
}
5669
}, label: {
5770
Image(isMemberIssued ? "download_used" : "download")
@@ -64,18 +77,7 @@ struct CouponInfoCell: View {
6477
}
6578
.padding(.leading, 10)
6679
.padding(5)
67-
.frame(maxHeight: 110)
6880
}
6981
.padding(15)
70-
.alert("쿠폰 다운로드 완료", isPresented: $showDownloadSuccess) {
71-
Button("확인", role: .cancel) { }
72-
} message: {
73-
Text("쿠폰이 성공적으로 발급되었습니다.")
74-
}
75-
.alert(viewModel.errorMessage ?? "오류", isPresented: .constant(viewModel.errorMessage != nil)) {
76-
Button("확인", role: .cancel) {
77-
viewModel.errorMessage = nil
78-
}
79-
}
8082
}
8183
}

MarketPlace/View/Components/MarketInfoCell.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
struct MarketInfoCell: View {
44
@ObservedObject var viewModel: MarketInfoCellViewModel
5+
@EnvironmentObject var loginViewModel: LoginViewModel
56
@State var isBookmarked: Bool
67

78
init(isBookmarked: Bool, viewModel: MarketInfoCellViewModel) {
@@ -19,19 +20,22 @@ struct MarketInfoCell: View {
1920
width: 110,
2021
height: 110
2122
)
22-
2323
.frame(width: 110, height: .infinity)
2424
.clipShape(RoundedRectangle(cornerRadius: 4))
2525

2626
VStack(alignment: .leading) {
2727
Text(viewModel.marketData.marketName)
28+
.lineLimit(1)
2829
.pretendardFont(size: 16, weight: .semibold)
2930
.foregroundColor(Color(hex: "333333"))
31+
.padding(.bottom, 3)
3032

3133
Text(viewModel.marketData.marketDescription)
34+
.multilineTextAlignment(.leading)
35+
.lineLimit(2)
3236
.pretendardFont(size: 13, weight: .medium)
3337
.foregroundColor(Color(hex: "7D7D7D"))
34-
.multilineTextAlignment(.leading)
38+
.padding(.bottom, 10)
3539

3640
Spacer()
3741

@@ -43,23 +47,25 @@ struct MarketInfoCell: View {
4347
Text(viewModel.marketData.address)
4448
.pretendardFont(size: 13, weight: .medium)
4549
.foregroundColor(Color(hex: "333333"))
50+
4651
Spacer()
4752

48-
Button(action: {
49-
Task {
50-
await viewModel.postFavoriteMarket(marketId: viewModel.marketData.id)
53+
if loginViewModel.isLoggedIn {
54+
Button(action: {
55+
Task {
56+
await viewModel.postFavoriteMarket(marketId: viewModel.marketData.id)
57+
}
58+
}) {
59+
Image(systemName: viewModel.marketData.isFavorite ? "bookmark.fill" : "bookmark")
60+
.resizable()
61+
.frame(width: 14, height: 20)
62+
.foregroundColor(Color(hex: "#4B4B4B"))
5163
}
52-
}) {
53-
Image(systemName: viewModel.marketData.isFavorite ? "bookmark.fill" : "bookmark")
54-
.resizable()
55-
.frame(width: 14, height: 20)
56-
.foregroundColor(Color(hex: "#4B4B4B"))
5764
}
5865
}
5966
}
60-
.padding(.leading, 10)
67+
.padding([.leading, .trailing], 10)
6168
.padding(5)
62-
.frame(maxHeight: 110)
6369
}
6470
.padding(15)
6571
}

MarketPlace/View/Main/View/CouponGetPopupView.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import SwiftUI
22

33
struct CouponGetPopupView: View {
44
@Binding var isPopupVisible: Bool
5-
@Binding var coupon: CouponValidModel
5+
@Binding var couponId: Int
6+
@Binding var couponType: String
7+
@Binding var isMemberIssued: Bool
68

79
@ObservedObject var viewModel = CouponPopupViewModel()
810

@@ -62,22 +64,21 @@ struct CouponGetPopupView: View {
6264
.padding(.vertical, 32)
6365
.background(Color.white)
6466
.cornerRadius(8)
65-
// .shadow(radius: 10)
6667
}
6768
}
6869

6970
private func onConfirm() {
70-
coupon.isMemberIssued = true
71+
isMemberIssued = true
7172
isPopupVisible = false
7273

73-
switch coupon.couponType {
74+
switch couponType {
7475
case "PAYBACK":
7576
Task {
76-
await viewModel.downloadPaybackCoupons(couponId: coupon.couponId)
77+
await viewModel.downloadPaybackCoupons(couponId: couponId)
7778
}
7879
case "GIFT":
7980
Task {
80-
await viewModel.downloadCoupons(couponId: coupon.couponId)
81+
await viewModel.downloadCoupons(couponId: couponId)
8182
}
8283

8384
default:

MarketPlace/View/Main/View/MarketDetailView.swift

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,29 @@ struct MarketDetailView: View {
3939
.foregroundColor(.black)
4040
.frame(maxWidth: .infinity, alignment: .topLeading)
4141
Spacer()
42-
Button(action: {
43-
isBookmarked.toggle()
44-
45-
Task {
46-
await viewModel.postFavoriteMarket(marketId: viewModel.id)
47-
}
48-
}) {
49-
if let isFavorite = shop.isFavorite {
50-
Image(systemName: isFavorite ? "bookmark.fill" : "bookmark")
51-
.resizable()
52-
.scaledToFit()
53-
.foregroundColor(.black)
54-
.frame(width: 16)
55-
} else {
56-
Image(systemName: "bookmark")
57-
.resizable()
58-
.scaledToFit()
59-
.foregroundColor(.black)
60-
.frame(width: 16)
42+
43+
if loginViewModel.isLoggedIn {
44+
Button(action: {
45+
isBookmarked.toggle()
46+
47+
Task {
48+
await viewModel.postFavoriteMarket(marketId: viewModel.id)
49+
}
50+
51+
}) {
52+
if let isFavorite = shop.isFavorite {
53+
Image(systemName: isFavorite ? "bookmark.fill" : "bookmark")
54+
.resizable()
55+
.scaledToFit()
56+
.foregroundColor(.black)
57+
.frame(width: 16)
58+
} else {
59+
Image(systemName: "bookmark")
60+
.resizable()
61+
.scaledToFit()
62+
.foregroundColor(.black)
63+
.frame(width: 16)
64+
}
6165
}
6266
}
6367
}
@@ -157,7 +161,9 @@ struct MarketDetailView: View {
157161
) {
158162
CouponGetPopupView(
159163
isPopupVisible: $isPopupVisible,
160-
coupon: couponBinding
164+
couponId: couponBinding.couponId,
165+
couponType: couponBinding.couponType,
166+
isMemberIssued: couponBinding.isMemberIssued
161167
).transition(.scale)
162168
}
163169

0 commit comments

Comments
 (0)