@@ -2,15 +2,26 @@ import SwiftUI
22
33struct 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}
0 commit comments