Skip to content

Commit

Permalink
[WEAV-141] Profile Panel 구조 변경, 직업 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jisu15-kim committed Nov 24, 2024
1 parent 13d9d28 commit 077e079
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 270 deletions.
2 changes: 1 addition & 1 deletion Projects/App/Sources/Navigation/NavigationStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension PathType {
case .jobOccupation(let input):
EditProfileJobView(input)
case .company(let input):
EmptyView()
EditProfileCompanyView(userInfo: input)
case .region(let input):
EmptyView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ extension ProfileService: ProfileServiceProtocol {
.init(
name: userInfo.name,
jobOccupation: jobOccupation,
companyId: userInfo.profile.companyId,
allowSameCompany: userInfo.dreamPartner.allowSameCompany,
locationIds: userInfo.profile.locations.map { $0.id }
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,92 @@
import Foundation
import CommonKit
import CoreKit
import Model
import NetworkKit
import SearchCompany

//MARK: - Intent
class EditProfileCompanyIntent {
private weak var model: EditProfileCompanyModelActionable?
private let input: DataModel
private let profileService: ProfileServiceProtocol

internal let searchCompanyIntent: SearchCompanyIntent.Intentable

// MARK: Life cycle
init(
model: EditProfileCompanyModelActionable,
input: DataModel
input: DataModel,
searchCompanyIntent: SearchCompanyIntent.Intentable,
profileService: ProfileServiceProtocol = ProfileService.shared
) {
self.input = input
self.model = model
self.searchCompanyIntent = searchCompanyIntent
self.profileService = profileService
model.setUserInfo(userInfo: input.userInfo)
}
}

//MARK: - Intentable
extension EditProfileCompanyIntent {
protocol Intentable {
// content
func onTapNextButton()
var searchCompanyIntent: SearchCompanyIntent.Intentable { get }
func onTapNextButton(state: SearchCompanyModel.Stateful)
func showSameCompanyPopup()

// default
func onAppear()
func task() async
}

struct DataModel {}
struct DataModel {
let userInfo: UserInfo
}
}

//MARK: - Intentable
extension EditProfileCompanyIntent: EditProfileCompanyIntent.Intentable {
// default
func onAppear() {}
func onAppear() {
searchCompanyIntent.setSameCompanyPopupHandler { [weak self] state in
self?.onTapNextButton(state: state)
}
}

func task() async {}

// content
func onTapNextButton() {}
func onTapNextButton(
state: SearchCompanyModel.Stateful
) {
Task {
do {
guard let company = state.selectedCompany else { return }
model?.setLoading(status: true)
var newUserInfo = input.userInfo
newUserInfo.profile.companyId = company.id
newUserInfo.dreamPartner.allowSameCompany = state.sameCompanyMatchingAvailable
try await requestPutProfile(newUserInfo: newUserInfo)
model?.setLoading(status: false)
await popView()
} catch {
model?.setLoading(status: false)
}
}
}

func showSameCompanyPopup() {
searchCompanyIntent.showSameCompanyPopup()
}

func requestPutProfile(newUserInfo: UserInfo) async throws {
try await profileService.requestPutUserInfo(userInfo: newUserInfo)
}

@MainActor
func popView() {
AppCoordinator.shared.pop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
import Foundation
import CommonKit
import CoreKit
import SearchCompany
import Model

final class EditProfileCompanyModel: ObservableObject {

//MARK: Stateful
protocol Stateful {
// content
var userInfo: UserInfo? { get }
var searchCompanyState: SearchCompanyModel.Stateful { get }

var isValidated: Bool { get }

// default
Expand All @@ -27,23 +32,31 @@ final class EditProfileCompanyModel: ObservableObject {

//MARK: State Properties
// content
@Published var isValidated: Bool = false
@Published var userInfo: UserInfo?
@Published var searchCompanyState: SearchCompanyModel.Stateful

var isValidated: Bool {
return searchCompanyState.isValidated
}

// default
@Published var isLoading: Bool = false

// error
@Published var showErrorView: ErrorModel?
@Published var showErrorAlert: ErrorModel?

init(searchCompanyState: SearchCompanyModel.Stateful) {
self.searchCompanyState = searchCompanyState
}
}

extension EditProfileCompanyModel: EditProfileCompanyModel.Stateful {}

//MARK: - Actionable
protocol EditProfileCompanyModelActionable: AnyObject {
// content
func setValidation(value: Bool)

func setUserInfo(userInfo: UserInfo)
// default
func setLoading(status: Bool)

Expand All @@ -55,10 +68,9 @@ protocol EditProfileCompanyModelActionable: AnyObject {

extension EditProfileCompanyModel: EditProfileCompanyModelActionable {
// content
func setValidation(value: Bool) {
isValidated = value
func setUserInfo(userInfo: UserInfo) {
self.userInfo = userInfo
}

// default
func setLoading(status: Bool) {
isLoading = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SwiftUI
import CoreKit
import DesignCore
import CommonKit
import SearchCompany
import Model

public struct EditProfileCompanyView: View {

Expand All @@ -18,11 +20,25 @@ public struct EditProfileCompanyView: View {
private var intent: EditProfileCompanyIntent.Intentable { container.intent }
private var state: EditProfileCompanyModel.Stateful { container.model }

public init() {
let model = EditProfileCompanyModel()
@FocusState var showDropDown: Bool
var bottomSpacingHeight: CGFloat {
return showDropDown ? Device.height * 0.7 : 0
}

public init(userInfo: UserInfo) {
let searchCompanyState = SearchCompanyModel()
let searchCompanyIntent = SearchCompanyIntent(
model: searchCompanyState,
input: .init()
)

let model = EditProfileCompanyModel(
searchCompanyState: searchCompanyState
)
let intent = EditProfileCompanyIntent(
model: model,
input: .init()
input: .init(userInfo: userInfo),
searchCompanyIntent: searchCompanyIntent
)
let container = MVIContainer(
intent: intent as EditProfileCompanyIntent.Intentable,
Expand All @@ -33,16 +49,82 @@ public struct EditProfileCompanyView: View {
}

public var body: some View {
VStack {
Text("Hello MVI")
ZStack {
ScrollView {
ScrollViewReader { proxy in
VStack(spacing: 20) {
if let userInfo = state.userInfo {
HStack {
Text("🏢 내 회사")
.typography(.regular_12)
Text(userInfo.profile.companyName ?? "")
.pretendard(
weight: ._600,
size: 12
)
}
.foregroundStyle(DesignCore.Colors.grey400)
.padding(.horizontal, 20)
.padding(.vertical, 10)
.background(
Capsule()
.fill(DesignCore.Colors.yellow50)
.stroke(
Color(hex: 0xEDE9C1),
lineWidth: 1
)
)
.padding(.vertical, 20)
}

SearchCompanyView(
state: state.searchCompanyState as! SearchCompanyModel,
intent: intent.searchCompanyIntent as! SearchCompanyIntent,
showDropDown: _showDropDown
)
.id(0)

Spacer()
.frame(height: bottomSpacingHeight)
.id(1)
.onChange(of: showDropDown) {
if showDropDown {
withAnimation {
proxy.scrollTo(1)
}
}
}
.foregroundStyle(.red)
}
.padding(.horizontal, 20)
.onTapGesture {
withAnimation {
showDropDown = false
}
}
}
}
CTABottomButton(
title: "다음",
isActive: state.searchCompanyState.isValidated
) {
/// 회사를 정확하게 파악할 수 있다면 -> 같은 회사 매칭 팝업 보여주기
if !state.searchCompanyState.isNoCompanyHere {
intent.showSameCompanyPopup()
} else {
/// 회사 정확하게 파악 불가하다면 다음 뷰로
intent.onTapNextButton(state: state.searchCompanyState)
}
}
}
.navigationTitle("회사 수정")
.task {
await intent.task()
}
.onAppear {
intent.onAppear()
}
.ignoresSafeArea(.all)
.ignoresSafeArea(.keyboard, edges: .bottom)
.textureBackground()
.setPopNavigation {
AppCoordinator.shared.pop()
Expand All @@ -53,7 +135,7 @@ public struct EditProfileCompanyView: View {

#Preview {
NavigationView {
EditProfileCompanyView()
EditProfileCompanyView(userInfo: .mock)
}
}

Expand Down
4 changes: 3 additions & 1 deletion Projects/Features/Home/Sources/Profile/ProfileIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ extension ProfileIntent: ProfileIntent.Intentable {
}

func fetchUserInfo(_ userInfo: UserInfo) {
model?.setUserInfo(userInfo)
DispatchQueue.main.async {
self.model?.setUserInfo(userInfo)
}
}

func task() async {}
Expand Down
2 changes: 1 addition & 1 deletion Projects/Features/Home/Sources/Profile/ProfileModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ProfileModel: ObservableObject {
var isPresentedDeleteConfirmSheet: Bool { get set }
var selectedWidgetType: ProfileWidget? { get }

var userInfoModel: UserInfo? { get }
var userInfoModel: UserInfo? { get set }
var isValidated: Bool { get }

// default
Expand Down
Loading

0 comments on commit 077e079

Please sign in to comment.