From b1bde50dbd545c4b1baa55b30d1ad9456d3607d2 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 30 May 2024 22:59:14 +0900 Subject: [PATCH] =?UTF-8?q?[Feat/#43]=20Alert=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Challenge/ViewModels/PointViewModel.swift | 6 ++++- .../Challenge/Views/PointView.swift | 13 ++++++---- .../ViewModels/OnboardingViewModel.swift | 12 ++++++--- .../Views/OnboardingContentView.swift | 25 +++++++++++++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewModels/PointViewModel.swift b/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewModels/PointViewModel.swift index eaf65d8b..a1fd68da 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewModels/PointViewModel.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewModels/PointViewModel.swift @@ -18,6 +18,7 @@ final class PointViewModel: ObservableObject { guard let data = result.data else { return } } } + // 앱 잠금해제시에 사용될 포인트를 조회하는 api입니다. func patchEarnPoint(day: Int) { let date = pointList[day].challengeDate @@ -27,6 +28,7 @@ final class PointViewModel: ObservableObject { guard let data = result.data else { return } } } + // 하루하루 챌린지를 성공하고, 포인트를 받는 버튼을 눌렀을 때, 포인트를 받는 API func getPointList() { Providers.pointProvider.request(target: .getPointList, @@ -37,6 +39,7 @@ final class PointViewModel: ObservableObject { self.pointList = data.challengePointStatuses } } + // 챌린지 보상 수령 여부를 리스트로 조회하는 api입니다. func patchPointUse(day: Int) { let date = pointList[day].challengeDate @@ -46,6 +49,7 @@ final class PointViewModel: ObservableObject { guard let data = result.data else { return } } } + // 포인트를 사용해 이용시간 잠금을 해제할 때 사용하는 api func getCurrentPoint(date: String) { let request = PointRequestDTO(challengeDate: date) @@ -54,5 +58,5 @@ final class PointViewModel: ObservableObject { guard let data = result.data else { return } } } - + // 현재 유저 포인트 불러오기 } diff --git a/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/PointView.swift b/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/PointView.swift index 6d8b222e..c2841575 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/PointView.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/PointView.swift @@ -39,18 +39,18 @@ extension PointView { private var listView: some View { ForEach(1...viewModel.challengeDay, id: \.self) { day in - HStack{ - VStack(alignment: .leading){ + HStack { + VStack(alignment: .leading) { Text("\(day)" + StringLiteral.Challenge.pointTitle) .font(.text4_semibold_16) - .foregroundStyle(.whiteText) + .foregroundColor(.whiteText) .padding(.bottom, 2) Text("\(viewModel.challengeDay)" + StringLiteral.Challenge.pointSubTitle) .font(.detail4_medium_12) - .foregroundStyle(.gray2) + .foregroundColor(.gray2) } Spacer() - EarnPointButton(day: Int) + EarnPointButton(day: day, viewModel: viewModel) } .frame(height: 80) } @@ -62,6 +62,9 @@ extension PointView { } struct EarnPointButton: View { + let day: Int + @ObservedObject var viewModel: PointViewModel + var body: some View { Button(action: { viewModel.patchPointUse(day: day) diff --git a/HMH_iOS/HMH_iOS/Presentation/Onboarding/ViewModels/OnboardingViewModel.swift b/HMH_iOS/HMH_iOS/Presentation/Onboarding/ViewModels/OnboardingViewModel.swift index 715a26a3..b2dc3127 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Onboarding/ViewModels/OnboardingViewModel.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Onboarding/ViewModels/OnboardingViewModel.swift @@ -22,6 +22,9 @@ class OnboardingViewModel: ObservableObject { @Published var isCompleted: Bool + @Published + var isCompletePresented: Bool = false + @Published var selectedGoalTime: String @@ -78,9 +81,7 @@ class OnboardingViewModel: ObservableObject { case 3: self.goalTime = convertToTotalMilliseconds(hour: selectedGoalTime, minute: "0") if isChallengeMode { - print("isChallengeMode") - postCreateChallengeData() - addOnboardingState() + isCompletePresented = true } else { addOnboardingState() } @@ -102,6 +103,11 @@ class OnboardingViewModel: ObservableObject { } } + func alertAction() { + postCreateChallengeData() + addOnboardingState() + } + func addOnboardingState() { onboardingState += 1 } diff --git a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingContentView.swift b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingContentView.swift index 84136daf..6dd1a803 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingContentView.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingContentView.swift @@ -47,6 +47,31 @@ struct OnboardingContentView: View { self.presentationMode.wrappedValue.dismiss() } } + .customAlert( + isPresented: $onboardingViewModel.isCompletePresented, + customAlert: { + CustomAlertView( + alertType: .challengeCreationComplete, + confirmBtn: CustomAlertButtonView( + buttonType: .Confirm, + alertType: .challengeCreationComplete, + isPresented: $onboardingViewModel.isCompletePresented, + action: { + onboardingViewModel.alertAction() + } + ), + cancelBtn: CustomAlertButtonView( + buttonType: .Cancel, + alertType: .challengeCreationComplete, + isPresented: $onboardingViewModel.isCompletePresented, + action: { + onboardingViewModel.alertAction() + } + ) + ) + } + ) + } }