File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ struct MyCouponCell: View {
55 var onTap : ( ) -> Void
66
77 var body : some View {
8- Image ( viewModel. coupon . used || viewModel . isExpired ? " myCoupon_used " : " myCoupon_canuse " )
8+ Image ( viewModel. couponStatus == CouponStatus . issued ? " myCoupon_canuse " : " myCoupon_used " )
99 . resizable ( )
1010 . scaledToFit ( )
1111 . frame ( width: 335 , height: 102 )
@@ -50,7 +50,7 @@ struct MyCouponCell: View {
5050 onTap ( )
5151 }
5252 } ) {
53- Text ( viewModel. coupon . used || viewModel . isExpired ? " 사용 완료 " : " 사용 가능 " )
53+ Text ( viewModel. couponStatusText )
5454 . font ( . custom( " Pretendard " , size: 13 ) )
5555 . fontWeight ( . bold)
5656 . foregroundStyle ( Color . white)
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ struct MyCouponView: View {
2020 @State private var selectedCategoryIndex = 0
2121
2222 var body : some View {
23- // NavigationView 제거 - 상위 뷰에서 이미 NavigationView를 사용중이므로
2423 ZStack {
2524 VStack ( spacing: 0 ) {
2625 CouponCategoryView ( selectedCategory: $selectedCategoryIndex)
@@ -34,11 +33,7 @@ struct MyCouponView: View {
3433 . padding ( )
3534 } else {
3635 ForEach ( viewModel. memberCoupons, id: \. memberCouponId) { coupon in
37- MyCouponCell ( viewModel: MyCouponCellViewModel ( coupon: coupon) ) {
38- selectedCoupon = coupon
39- showingPopup = true
40- }
41- . frame ( maxWidth: . infinity, alignment: . center)
36+ makeCouponCell ( for: coupon)
4237 }
4338 }
4439 }
@@ -83,5 +78,16 @@ struct MyCouponView: View {
8378 }
8479 }
8580 }
81+
82+ // MARK: - coupon Cell 생성
83+ private func makeCouponCell( for coupon: MembersCouponModel ) -> some View {
84+ let status = CouponStatus ( index: selectedCategoryIndex) ?? . issued
85+ let viewModel = MyCouponCellViewModel ( coupon: coupon, couponStatus: status)
86+
87+ return MyCouponCell ( viewModel: viewModel) {
88+ selectedCoupon = coupon
89+ showingPopup = true
90+ }
91+ }
8692}
8793
Original file line number Diff line number Diff line change @@ -10,23 +10,29 @@ import Foundation
1010final class MyCouponCellViewModel : ObservableObject {
1111 private var memberCouponService : MemberCouponServiceProtocol
1212 @Published var coupon : MembersCouponModel
13-
13+ @ Published var couponStatus : CouponStatus
1414 @Published var isLoading : Bool = false
1515 @Published var errorMessage : String ?
1616
1717 init (
1818 coupon: MembersCouponModel ,
19+ couponStatus: CouponStatus ,
1920 memberCouponService: MemberCouponServiceProtocol = MemberCouponService ( )
2021 ) {
2122 self . coupon = coupon
23+ self . couponStatus = couponStatus
2224 self . memberCouponService = memberCouponService
2325 }
2426
25- var isExpired : Bool {
26- let formatter = DateFormatter ( )
27- formatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ss.SSS "
28- guard let expirationDate = formatter. date ( from: coupon. deadLine) else { return false }
29- return expirationDate < Date ( )
27+ var couponStatusText : String {
28+ switch couponStatus {
29+ case . issued:
30+ return " 사용 가능 "
31+ case . used:
32+ return " 사용 완료 "
33+ case . expired:
34+ return " 기간 만료 "
35+ }
3036 }
3137
3238 var formattedDeadline : String {
@@ -38,7 +44,7 @@ final class MyCouponCellViewModel: ObservableObject {
3844 }
3945
4046 var canUse : Bool {
41- return !coupon . used && !isExpired
47+ return couponStatus == . issued
4248 }
4349
4450 func useMemberCoupon( memberCouponId: Int ) async {
You can’t perform that action at this time.
0 commit comments