Skip to content

Commit

Permalink
[Hotfix] #12 - (5), (6)번 반영
Browse files Browse the repository at this point in the history
보호 관계 관리
  • Loading branch information
dlwogus0128 committed Jun 6, 2024
1 parent 0c142bd commit fcb51b8
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ struct DoseScheduleStatusView: View {
.font(.body1Medium)
.foregroundColor(Color.gray90)
.padding()
.fadeIn(delay: 0.1)
}
} else {
ScrollView {
ForEach(filteredLogs, id: \.id) { log in
let color = colors[log.cabinetIndex]
let color = colors[log.cabinetIndex - 1]

HStack {
Circle()
Expand Down Expand Up @@ -88,6 +89,7 @@ struct DoseScheduleStatusView: View {
.padding(15)

}
.fadeIn(delay: 0.1)
}

}
Expand All @@ -104,18 +106,19 @@ struct DoseScheduleStatusView: View {
.font(.body1Bold)
.foregroundColor(Color.gray90)
.padding(.bottom, 3)
.fadeIn(delay: 0.1)

Text("복약 일정을 등록하고 알림을 받아보세요")
.font(.caption1Medium)
.foregroundColor(Color.gray60)
.fadeIn(delay: 0.2)
}

}
.cornerRadius(8)
.frame(maxWidth: .infinity,
minHeight: 150,
maxHeight: 150)
.padding(.bottom, 10)
}
} else {
/// 약통이 존재하지 않을 경우, 약통 등록 유도
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct HomeView: View {
isCabinetExist: relation.cabinetID != 0,
takenStatus: nil,
showAddPillCaseView: $showAddPillCaseView)
.padding([.top], 10)
.padding([.top, .bottom], 10)
.padding([.leading, .trailing], 25)
.fadeIn(delay: 0.3)

Expand All @@ -72,14 +72,15 @@ struct HomeView: View {
.padding(.top, 10)
.padding([.leading, .trailing], 25)
.onTapGesture {
if (homeViewModel.healthData?.isEmpty ?? true) {
if (homeViewModel.state.stepCount != "0보") {
self.showHealthView = true
}
}

Spacer()
}
.containerRelativeFrame(.horizontal)

}
.refreshable {
homeViewModel.$requestGetDoseLog.send(self.selectedClientId!)
Expand All @@ -88,12 +89,17 @@ struct HomeView: View {
self.isRefresh = true
}
}
.scrollTransition { content, phase in
content
.opacity(phase.isIdentity ? 1 : 0.7)
.scaleEffect(phase.isIdentity ? 1.0 : 0.7) }
}
.scrollTargetLayout(isEnabled: true)

}
.scrollTargetBehavior(.viewAligned)
.scrollPosition(id: $selectedClientId)

/// 피보호자일 경우
} else {
ScrollView {
Expand Down Expand Up @@ -125,11 +131,12 @@ struct HomeView: View {
.padding([.leading, .trailing], 25)
.fadeIn(delay: 0.3)


HealthMainView(stepCount: $homeViewModel.state.stepCount)
.fadeIn(delay: 0.4)
.padding([.leading, .trailing], 25)
.onTapGesture {
if !(homeViewModel.healthData?.isEmpty ?? true) {
if (homeViewModel.state.stepCount != "0보") {
self.showHealthView = true
}
}
Expand Down Expand Up @@ -264,7 +271,7 @@ struct HealthMainView: View {
ZStack {
Color.primary60

if (homeViewModel.healthData?.steps != 0 || ((homeViewModel.healthData?.isEmpty) != nil)) {
if (homeViewModel.state.stepCount == "0보") {
VStack {
Text("건강 데이터가 없어요.")
.font(.logo4Medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class HomeViewModel: ObservableObject {
// MARK: - Output State

@Published var homeState: HomeState = HomeState()
@Published var healthInfoState: HealthInfoState = HealthInfoState()
// @Published var healthInfoState: HealthInfoState = HealthInfoState()
@Published var isNetworking: Bool = false
@Published var isDataReady: Bool = false
@Published var relationLists: [RelationList] = []
Expand Down Expand Up @@ -246,7 +246,7 @@ class HomeViewModel: ObservableObject {
sleepTotal: "\(String(result.result?.sleepTime ?? 0))시간",
heartRate: "\(String(result.result?.heartRate ?? 0))BPM",
burnCalories: "\(String(result.result?.calorie ?? 0))kcal")
print(self.healthInfoState)
print("memberId \(memberId) 건강 데이터", self.state)
// healthData가 빈 값일 때만 bindHealth() 함수들 실행
if (self.healthData?.isEmpty ?? true) && (!(UserManager.shared.isManager ?? false)) && !self.requestToHK {
self.requestHealthDataToHK()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI

import Moya
import Factory

struct SelectedRelation: Identifiable {
let id = UUID()
Expand All @@ -24,13 +25,15 @@ struct ClientManageView: View {

// MARK: - Properties

@ObservedObject var clientManageViewModel: ClientManageViewModel = ClientManageViewModel(relationService: RelationService(provider: MoyaProvider<RelationAPI>()))
@ObservedObject var clientManageViewModel: ClientManageViewModel
@ObservedObject var managementMyInformationViewModel: ManagementMyInformationViewModel = ManagementMyInformationViewModel(caseService: CaseService(provider: MoyaProvider<CaseAPI>()))
@State var isDeletePopUp: Bool = false
@State var isRequestRelationPopUp: Bool = false
@State var showInformationView: Bool = false
@State var selectedRelation: SelectedRelation?
@State var selectedDeleteRelation: SelectedRelation?
@State var showToastView: Bool = false
@ObservedObject var toastManager = Container.shared.toastManager.resolve()

// MARK: - body

Expand Down Expand Up @@ -79,17 +82,9 @@ struct ClientManageView: View {
.font(.body2Medium)
.foregroundStyle(Color.gray70)
}
.onTapGesture {
self.selectedRelation = SelectedRelation(relationId: relation.id,
name: relation.memberName,
ssn: relation.memberSsn,
phone: relation.memberPhone,
cabinetId: relation.cabinetID)
self.showInformationView = true
}

Spacer()

if (UserManager.shared.isManager ?? true) {
Image(relation.cabinetID == 0 ? "ic_cabnet_disconnected" : "ic_cabnet_connected")
.resizable()
Expand All @@ -102,6 +97,14 @@ struct ClientManageView: View {
.foregroundStyle(Color.gray90)
}
}
.onTapGesture {
self.selectedRelation = SelectedRelation(relationId: relation.id,
name: relation.memberName,
ssn: relation.memberSsn,
phone: relation.memberPhone,
cabinetId: relation.cabinetID)
self.showInformationView = true
}
.swipeActions {
Button("삭제") {
self.isDeletePopUp = true
Expand All @@ -117,13 +120,13 @@ struct ClientManageView: View {
.frame(height: 70)
.padding([.leading, .trailing], 30)
}
.refreshable {
requestToGetInfo()
}
}
.ignoresSafeArea(edges: .bottom)
.listStyle(.plain)
.fadeIn(delay: 0.1)
.refreshable {
requestToGetInfo()
}

if showToastView {
ToastView(description: "보호 관계를 요청했어요.", show: $showToastView)
Expand All @@ -134,6 +137,10 @@ struct ClientManageView: View {
requestToGetInfo()
})
}
.onChange(of: self.clientManageViewModel.isDeleteSucceed, {
self.toastManager.showToast(description: "보호 관계 삭제를 완료했어요.")
requestToGetInfo()
})
.onAppear(perform: {
requestToGetInfo()
})
Expand All @@ -158,7 +165,7 @@ struct ClientManageView: View {
.background(Material.ultraThin)
})
.sheet(item: $selectedRelation, content: { relation in
ManagementMyInformationView(userInfo: relation)
ManagementMyInformationView(clientManageViewModel: clientManageViewModel, userInfo: relation)
})
.transaction { transaction in // 모달 애니메이션 삭제
transaction.disablesAnimations = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ struct ManagementMyInformationView: View {

// MARK: - Properties

@Environment(\.dismiss) var dismiss

@State private var showToast: Bool = false
@State private var showDeletePillCasePopUpView: Bool = false
@State private var showDeleteRelationPopUpView: Bool = false

@ObservedObject var myPageViewModel: MyPageViewModel = MyPageViewModel()
@ObservedObject var managementMyInformationViewModel: ManagementMyInformationViewModel = ManagementMyInformationViewModel(caseService: CaseService(provider: MoyaProvider<CaseAPI>()))
@ObservedObject var managementMyInformationViewModel: ManagementMyInformationViewModel = ManagementMyInformationViewModel(caseService: CaseService(provider: MoyaProvider<CaseAPI>()))
@ObservedObject var clientManageViewModel: ClientManageViewModel

let userInfo: SelectedRelation

Expand Down Expand Up @@ -60,18 +65,61 @@ struct ManagementMyInformationView: View {

Spacer()

if !(UserManager.shared.isManager ?? true) && (userInfo.cabinetId != 0) {
if (userInfo.cabinetId != 0) {
CustomButton(buttonSize: .regular,
buttonStyle: .filled,
action: {
self.managementMyInformationViewModel.$tapDeletePillCaseButton.send(userInfo.cabinetId)
self.showDeletePillCasePopUpView = true
}, content: {
Text("약통 해제하기")
}, isDisabled: self.managementMyInformationViewModel.isDeleteSucced)
.padding([.leading, .trailing], 33)
.fadeIn(delay: 0.3)
}

if userInfo.phone != UserManager.shared.phoneNumber {
CustomButton(buttonSize: .regular,
buttonStyle: .filled,
action: {
self.showDeleteRelationPopUpView = true
}, content: {
Text("보호 관계 삭제하기")
}, isDisabled: false)
.padding([.leading, .trailing], 33)
.padding(.bottom, 5)
.fadeIn(delay: 0.3)
}
}
}
.fullScreenCover(isPresented: $showDeleteRelationPopUpView, content: {
CustomPopUpView(mainText: "\(userInfo.name) 님을\n삭제하시겠어요?",
subText: popUpSubText(name: userInfo.name),
leftButtonText: "취소할래요",
rightButtonText: "삭제할래요",
leftButtonAction: {},
rightButtonAction: {
requestToDelete(userInfo.relationId)
self.dismiss()
})
.background(ClearBackgroundView())
.background(Material.ultraThin)
})
.fullScreenCover(isPresented: $showDeletePillCasePopUpView,
content: {
CustomPopUpView(mainText: "약통을 해제하시겠어요?",
subText: "약통을 해제하면 \(userInfo.name) 님은 더 이상 서비스에서 복약 관리를 받을 수 없어요.",
leftButtonText: "해제할게요",
rightButtonText: "취소할게요",
leftButtonAction: {},
rightButtonAction: {
self.managementMyInformationViewModel.$tapDeletePillCaseButton.send(userInfo.cabinetId)
})
.background(ClearBackgroundView())
.background(Material.ultraThin)
})
.transaction { transaction in // 모달 애니메이션 삭제
transaction.disablesAnimations = true
}
}

/// 수정 전: 초기값 return func
Expand All @@ -86,6 +134,13 @@ struct ManagementMyInformationView: View {
case .isPillCaseExist:
return ""
}

}

private func requestToDelete(_ id: Int) {
self.clientManageViewModel.$requestDeleteRelation.send(id)
}

private func popUpSubText(name: String) -> String {
return (UserManager.shared.isManager ?? true) ? "삭제하면 \(name) 님은 새로운 보호자가 케어를\n요청할 때까지 서비스를 이용할 수 없어요." : "삭제하면 \(name) 님은 \n\(UserManager.shared.name ?? "null") 님을 케어할 수 없어요. 신중하게 삭제해주세요."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

import LinkNavigator
import Factory
import Moya

// 이후 다른 곳으로 이동할 것
@frozen
Expand Down Expand Up @@ -47,6 +48,7 @@ struct MyPageDetailView: View {
@State var isEditing: Bool = false
@State var settingListElement: SettingListElement
@ObservedObject var homeViewModel = Container.shared.homeViewModel.resolve()
@ObservedObject var clientManageViewModel: ClientManageViewModel = ClientManageViewModel(relationService: RelationService(provider: MoyaProvider<RelationAPI>()))

@State var name: String?
let navigator: LinkNavigatorType
Expand All @@ -69,8 +71,8 @@ struct MyPageDetailView: View {

switch settingListElement {
case .managementMyInformation:
ManagementMyInformationView(userInfo: SelectedRelation(relationId: UserManager.shared.memberId ?? 0,
name: UserManager.shared.name ?? "null",
ManagementMyInformationView(clientManageViewModel: clientManageViewModel,
userInfo: SelectedRelation(relationId: UserManager.shared.memberId ?? 0, name: UserManager.shared.name ?? "null",
ssn: UserManager.shared.ssn ?? "null",
phone: UserManager.shared.phoneNumber ?? "null",
cabinetId: homeViewModel.clientCabnetId))
Expand All @@ -81,7 +83,7 @@ struct MyPageDetailView: View {
case .withdrawal:
WithdrawalView(navigator: navigator)
case .clientManage:
ClientManageView()
ClientManageView(clientManageViewModel: clientManageViewModel)
case .managementDoseSchedule:
ManagementDoseScheduleView()
case .todaysHealthState:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ struct RelationList: Codable {
let id, memberID: Int
let memberName, memberSsn, memberPhone: String
let cabinetID: Int
let cabinetIndexList: [Int]

enum CodingKeys: String, CodingKey {
case id
case memberID = "memberId"
case memberName, memberSsn, memberPhone
case cabinetID = "cabinetId"
case cabinetIndexList
}
}

0 comments on commit fcb51b8

Please sign in to comment.