Skip to content

Commit

Permalink
이메일 미인증시 CTA 개선 (2) (#208)
Browse files Browse the repository at this point in the history
* refactor error alert logic

* show email verify alert on lecture detail page
  • Loading branch information
shp7724 authored Jan 18, 2023
1 parent 3bd0096 commit aca6600
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
17 changes: 17 additions & 0 deletions SNUTT-2022/SNUTT/ViewModels/LectureDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ extension LectureDetailScene {
class ViewModel: BaseViewModel, ObservableObject {
@Published var isErrorAlertPresented = false
@Published var isLectureOverlapped: Bool = false
@Published var isEmailVerifyAlertPresented = false
var errorTitle: String = ""
var errorMessage: String = ""

override init(container: DIContainer) {
super.init(container: container)
appState.system.$selectedTab.assign(to: &$_selectedTab)
}

var lectureService: LectureServiceProtocol {
Expand All @@ -27,6 +29,21 @@ extension LectureDetailScene {
var currentTimetable: Timetable? {
appState.timetable.current
}

@Published private var _selectedTab: TabType = .review
var selectedTab: TabType {
get { _selectedTab }
set { services.globalUIService.setSelectedTab(newValue) }
}

func presentEmailVerifyAlert() {
let emailVerifyError = STError(.EMAIL_NOT_VERIFIED)
errorTitle = emailVerifyError.title
errorMessage = emailVerifyError.content
DispatchQueue.main.async {
self.isEmailVerifyAlertPresented = true
}
}

func addCustomLecture(lecture: Lecture, isForced: Bool = false) async -> Bool {
do {
Expand Down
11 changes: 6 additions & 5 deletions SNUTT-2022/SNUTT/ViewModels/SearchSceneViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class SearchSceneViewModel: BaseViewModel, ObservableObject {
@Published var selectedTagList: [SearchTag] = []
@Published var isLoading: Bool = false
@Published var isLectureOverlapped: Bool = false

@Published var emailVerifyError: STError? = nil
@Published var presentEmailVerifyAlert = false
@Published var isEmailVerifyAlertPresented = false

var errorTitle: String = ""
var errorMessage: String = ""
Expand Down Expand Up @@ -140,8 +138,11 @@ class SearchSceneViewModel: BaseViewModel, ObservableObject {
do {
return try await services.lectureService.fetchReviewId(courseNumber: lecture.courseNumber, instructor: lecture.instructor)
} catch let error as STError where error.code == .EMAIL_NOT_VERIFIED {
emailVerifyError = error
presentEmailVerifyAlert = true
await MainActor.run {
errorTitle = error.title
errorMessage = error.content
isEmailVerifyAlertPresented = true
}
} catch {
services.globalUIService.presentErrorAlert(error: error)
}
Expand Down
14 changes: 13 additions & 1 deletion SNUTT-2022/SNUTT/Views/Scenes/LectureDetailScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,20 @@ struct LectureDetailScene: View {
}

DetailButton(text: "강의평") {
showReviewWebView = true
if reviewId == nil {
viewModel.presentEmailVerifyAlert()
} else {
showReviewWebView = true
}
}
.alert(viewModel.errorTitle, isPresented: $viewModel.isEmailVerifyAlertPresented, actions: {
Button("확인") {
viewModel.selectedTab = .review
}
Button("취소", role: .cancel) {}
}, message: {
Text(viewModel.errorMessage)
})
.onAppear {
Task {
reviewId = await viewModel.fetchReviewId(of: lecture)
Expand Down
9 changes: 3 additions & 6 deletions SNUTT-2022/SNUTT/Views/Scenes/SearchLectureScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,13 @@ struct SearchLectureScene: View {
.task {
await viewModel.fetchTags()
}
.alert(viewModel.emailVerifyError?.title ?? "", isPresented: $viewModel.presentEmailVerifyAlert, actions: {
.alert(viewModel.errorTitle, isPresented: $viewModel.isEmailVerifyAlertPresented, actions: {
Button("확인") {
viewModel.emailVerifyError = nil
viewModel.selectedTab = .review
}
Button("취소", role: .cancel) {
viewModel.emailVerifyError = nil
}
Button("취소", role: .cancel) {}
}, message: {
Text(viewModel.emailVerifyError?.content ?? "")
Text(viewModel.errorMessage)
})
.navigationBarHidden(true)
.animation(.customSpring, value: viewModel.searchResult?.count)
Expand Down

0 comments on commit aca6600

Please sign in to comment.