Skip to content

Commit 4e33b6f

Browse files
authored
Merge pull request #117 from DSM-PICK/feature/(#115)-toast_refectoring
🔗 :: (#115) 토스트 처리 (성공, 실패)
2 parents 5dd2fff + 463b1f5 commit 4e33b6f

8 files changed

Lines changed: 214 additions & 189 deletions

File tree

Projects/Feature/AcceptFeature/Sources/AcceptReducer.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ComposableArchitecture
22
import AcceptDomainInterface
3+
import PiCK_iOS_DesignSystem
34

45
public struct AcceptReducer: Reducer {
56
private let getAllApplicationsUseCase: any GetAllApplicationsUseCaseProtocol
@@ -53,9 +54,9 @@ public struct AcceptReducer: Reducer {
5354
public var currentClassNum: Int = 5
5455
public var currentFloor: Int = 1
5556
public var currentType: ApplicationType = .outgoing
56-
public var toastMessage: String? = nil
57-
public var showToast: Bool = false
58-
public var shouldDismiss: Bool = false
57+
public var showAlert = false
58+
public var alertSuccessType: SuccessType = .success
59+
public var alertMessage: String = ""
5960

6061
public init() {}
6162
}
@@ -70,7 +71,7 @@ public struct AcceptReducer: Reducer {
7071
case approveSelectedApplications
7172
case rejectSelectedApplications
7273
case updateStatusResponse(Result<String, Error>)
73-
case hideToast
74+
case dismissAlert
7475
}
7576

7677
public var body: some Reducer<State, Action> {
@@ -226,7 +227,7 @@ public struct AcceptReducer: Reducer {
226227
switch result {
227228
case .success:
228229
await send(.updateStatusResponse(.success("\(count)명의 \(typeText) 거절이 완료되었습니다!")))
229-
case .failure(let error):
230+
case let .failure(error):
230231
await send(.updateStatusResponse(.failure(error)))
231232
}
232233
}
@@ -238,20 +239,19 @@ public struct AcceptReducer: Reducer {
238239
removedIds.contains(item.id)
239240
}
240241
state.selectedItemIds = []
241-
state.toastMessage = message
242-
state.showToast = true
243-
state.shouldDismiss = true
242+
state.alertMessage = message
243+
state.showAlert = true
244244
return .none
245245

246246
case .updateStatusResponse(.failure):
247247
state.isLoading = false
248-
state.toastMessage = "처리에 실패했습니다"
249-
state.showToast = true
248+
state.alertMessage = "처리를 실패했습니다"
249+
state.showAlert = true
250+
state.alertSuccessType = .fail
250251
return .none
251252

252-
case .hideToast:
253-
state.showToast = false
254-
state.toastMessage = nil
253+
case .dismissAlert:
254+
state.showAlert = false
255255
return .none
256256
}
257257
}

Projects/Feature/AcceptFeature/Sources/Scene/AcceptView.swift

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -254,38 +254,14 @@ public struct AcceptView: View {
254254
}
255255
}
256256

257-
if viewStore.showToast, let message = viewStore.toastMessage {
258-
VStack {
259-
Spacer()
260-
261-
HStack(spacing: 12) {
262-
Image(systemName: "checkmark.circle.fill")
263-
.foregroundColor(.Primary.primary500)
264-
.font(.system(size: 20))
265-
266-
Text(message)
267-
.pickText(type: .body1, textColor: .Normal.black)
268-
}
269-
.padding(.horizontal, 16)
270-
.frame(height: 48)
271-
.background(Color.Gray.gray50)
272-
.cornerRadius(24)
273-
.shadow(color: Color.black.opacity(0.1), radius: 10, x: 0, y: 4)
274-
.padding(.bottom, 40)
275-
.transition(.move(edge: .bottom).combined(with: .opacity))
276-
.onAppear {
277-
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
278-
viewStore.send(.hideToast)
279-
}
280-
}
257+
if viewStore.showAlert {
258+
PiCKDisappearAlert(
259+
successType: viewStore.alertSuccessType,
260+
message: viewStore.alertMessage
261+
)
262+
.onDisappear {
263+
viewStore.send(.dismissAlert)
281264
}
282-
.zIndex(1000)
283-
.animation(.spring(response: 0.5, dampingFraction: 0.7), value: viewStore.showToast)
284-
}
285-
}
286-
.onChange(of: viewStore.shouldDismiss) { shouldDismiss in
287-
if shouldDismiss {
288-
dismiss()
289265
}
290266
}
291267
}

Projects/Feature/BugReport/Sources/BugReportReducer.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ComposableArchitecture
2+
import PiCK_iOS_DesignSystem
23
import Foundation
34
import PhotosUI
45
import SwiftUI
@@ -21,7 +22,10 @@ public struct BugReportReducer: Reducer {
2122
public var bugDescription: String = ""
2223
public var selectedImages: [Data] = []
2324
public var isSubmitting: Bool = false
24-
public var showSuccessAlert: Bool = false
25+
public var showAlert: Bool = false
26+
public var alertSuccessType: SuccessType = .success
27+
public var alertMessage: String = ""
28+
public var shouldDismiss: Bool = false
2529
public var isSubmitButtonEnabled: Bool = false
2630

2731
public init() {}
@@ -35,7 +39,7 @@ public struct BugReportReducer: Reducer {
3539
case submitButtonTapped
3640
case uploadImagesResponse(TaskResult<[String]>)
3741
case submitBugReportResponse(TaskResult<Void>)
38-
case dismissSuccessAlert
42+
case dismissAlert
3943
case updateSubmitButtonState
4044
}
4145

@@ -101,24 +105,33 @@ public struct BugReportReducer: Reducer {
101105
))
102106
}
103107

104-
case let .uploadImagesResponse(.failure(error)):
108+
case .uploadImagesResponse(.failure):
105109
state.isSubmitting = false
110+
state.alertSuccessType = .fail
111+
state.alertMessage = "이미지 업로드를 실패했어요"
112+
state.showAlert = true
106113
return .none
107114

108115
case .submitBugReportResponse(.success):
109116
state.isSubmitting = false
110-
state.showSuccessAlert = true
117+
state.alertSuccessType = .success
118+
state.alertMessage = "버그 제보가 완료되었습니다"
119+
state.showAlert = true
120+
state.shouldDismiss = true
111121
state.bugLocation = ""
112122
state.bugDescription = ""
113123
state.selectedImages = []
114124
return .none
115125

116-
case let .submitBugReportResponse(.failure(error)):
126+
case .submitBugReportResponse(.failure):
117127
state.isSubmitting = false
128+
state.alertSuccessType = .fail
129+
state.alertMessage = "버그 제보를 실패했어요"
130+
state.showAlert = true
118131
return .none
119132

120-
case .dismissSuccessAlert:
121-
state.showSuccessAlert = false
133+
case .dismissAlert:
134+
state.showAlert = false
122135
return .none
123136

124137
case .updateSubmitButtonState:

Projects/Feature/BugReport/Sources/Scene/BugReportView.swift

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,38 @@ public struct BugReportView: View {
1515

1616
public var body: some View {
1717
WithViewStore(store, observe: { $0 }) { viewStore in
18-
VStack(spacing: 0) {
19-
customNavigationBar
18+
ZStack {
19+
VStack(spacing: 0) {
20+
customNavigationBar
2021

21-
ScrollView {
22-
formContent(viewStore: viewStore)
23-
}
22+
ScrollView {
23+
formContent(viewStore: viewStore)
24+
}
2425

25-
submitButton(viewStore: viewStore)
26-
}
27-
.background(Color.Background.background)
28-
.navigationBarHidden(true)
29-
.toolbar(.hidden, for: .tabBar)
30-
.alert("제보 완료", isPresented: viewStore.binding(
31-
get: \.showSuccessAlert,
32-
send: .dismissSuccessAlert
33-
)) {
34-
Button("확인") {
35-
dismiss()
26+
submitButton(viewStore: viewStore)
27+
}
28+
.background(Color.Background.background)
29+
.navigationBarHidden(true)
30+
.toolbar(.hidden, for: .tabBar)
31+
32+
if viewStore.showAlert {
33+
VStack {
34+
Spacer()
35+
PiCKDisappearAlert(
36+
successType: viewStore.alertSuccessType,
37+
message: viewStore.alertMessage
38+
)
39+
.onDisappear {
40+
viewStore.send(.dismissAlert)
41+
if viewStore.shouldDismiss {
42+
dismiss()
43+
}
44+
}
45+
.padding(.bottom, 40)
46+
}
47+
.transition(.move(edge: .bottom).combined(with: .opacity))
48+
.zIndex(999)
3649
}
37-
} message: {
38-
Text("버그 제보가 성공적으로 완료되었습니다.")
3950
}
4051
}
4152
}

Projects/Feature/HomeFeature/Sources/HomeReducer.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ComposableArchitecture
2+
import PiCK_iOS_DesignSystem
23
import HomeDomainInterface
34
import AcceptDomainInterface
45
import OutListDomainInterface
@@ -51,6 +52,9 @@ public struct HomeReducer: Reducer {
5152
public var floor: String = "0층"
5253
public var isHomeroomTeacher: Bool = false
5354
public var isSelfStudyTeacher: Bool = false
55+
public var showAlert: Bool = false
56+
public var alertSuccessType: SuccessType = .success
57+
public var alertMessage: String = ""
5458

5559
// 내부용 리스트
5660
var earlyReturnList: [EarlyReturnEntity] = []
@@ -90,6 +94,8 @@ public struct HomeReducer: Reducer {
9094
case classroomMoveResponse(TaskResult<[ClassroomMoveListEntity]>)
9195
case outListResponse(TaskResult<[OutListEntity]>)
9296
case earlyReturnListResponse(TaskResult<[EarlyReturnEntity]>)
97+
98+
case dismissAlert
9399
}
94100

95101
public var body: some Reducer<State, Action> {
@@ -236,6 +242,10 @@ public struct HomeReducer: Reducer {
236242
}
237243

238244
case .updateStatusResponse(.success):
245+
state.alertSuccessType = .success
246+
state.alertMessage = "외출 처리를 성공했어요"
247+
state.showAlert = true
248+
239249
let components = state.classroom.split(separator: "-").compactMap { Int($0) }
240250
if components.count == 2 {
241251
return .merge(
@@ -245,9 +255,16 @@ public struct HomeReducer: Reducer {
245255
}
246256
return .none
247257
case .updateStatusResponse(.failure):
258+
state.alertSuccessType = .fail
259+
state.alertMessage = "외출 처리를 실패했어요"
260+
state.showAlert = true
248261
return .none
249262

250263
case .updateEarlyReturnStatusResponse(.success):
264+
state.alertSuccessType = .success
265+
state.alertMessage = "조기귀가 처리를 성공했어요"
266+
state.showAlert = true
267+
251268
let components = state.classroom.split(separator: "-").compactMap { Int($0) }
252269
if components.count == 2 {
253270
return .merge(
@@ -257,6 +274,9 @@ public struct HomeReducer: Reducer {
257274
}
258275
return .none
259276
case .updateEarlyReturnStatusResponse(.failure):
277+
state.alertSuccessType = .fail
278+
state.alertMessage = "조기귀가 처리를 실패했어요"
279+
state.showAlert = true
260280
return .none
261281

262282
case let .classroomMoveResponse(.success(students)):
@@ -284,6 +304,10 @@ public struct HomeReducer: Reducer {
284304
return .none
285305
case .earlyReturnListResponse(.failure):
286306
return .none
307+
308+
case .dismissAlert:
309+
state.showAlert = false
310+
return .none
287311
}
288312
}
289313
}

0 commit comments

Comments
 (0)