diff --git a/Spon-Us/MyPage/Club/WriteClubProfileView.swift b/Spon-Us/MyPage/Club/WriteClubProfileView.swift index 594f5d2..1d7c87e 100644 --- a/Spon-Us/MyPage/Club/WriteClubProfileView.swift +++ b/Spon-Us/MyPage/Club/WriteClubProfileView.swift @@ -26,9 +26,8 @@ struct WriteClubProfileView: View { @ObservedObject var mypageVM: MypageViewModel -// @State var existProfile = false - + @State var buttonDisabled: [WriteClubProfileTab : Bool] = [.image : true, .name : true, .introduce : true, .member : true, .link : true, .field : true] var body: some View { @@ -44,25 +43,24 @@ struct WriteClubProfileView: View { TabView(selection: $selectedPage) { - ImageTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM) + ImageTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM, buttonDisabled: $buttonDisabled) .tag(WriteClubProfileTab.image) - NameTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM) + NameTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM, buttonDisabled: $buttonDisabled) .tag(WriteClubProfileTab.name) - IntroduceTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM) + IntroduceTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM, buttonDisabled: $buttonDisabled) .tag(WriteClubProfileTab.introduce) - MemberTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM) + MemberTabView(selectedPage: $selectedPage, mypageViewModel: mypageVM, buttonDisabled: $buttonDisabled) .tag(WriteClubProfileTab.member) - LinkTabView(selectedPage: $selectedPage, WriteClubProfileVM: mypageVM) + LinkTabView(selectedPage: $selectedPage, WriteClubProfileVM: mypageVM, buttonDisabled: $buttonDisabled) .tag(WriteClubProfileTab.link) - FieldTabView(mypageViewModel: mypageVM) + FieldTabView(mypageViewModel: mypageVM, buttonDisabled: $buttonDisabled) .tag(WriteClubProfileTab.field) - } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)) @@ -92,11 +90,13 @@ struct ImageTabView: View { @Binding var selectedPage: WriteClubProfileTab -// @State private var selectedImage: UIImage? = nil + @State private var selectedImage: UIImage? = nil @State private var isImagePickerPresented = false @ObservedObject var mypageViewModel: MypageViewModel + @Binding var buttonDisabled: [WriteClubProfileTab : Bool] + var body: some View { VStack(spacing: 0) { ScrollView { @@ -137,7 +137,7 @@ struct ImageTabView: View { .padding(.top, 16) .zIndex(1.0) - if let selectedImage = mypageViewModel.clubImage { + if let selectedImage = selectedImage { Image(uiImage: selectedImage) .resizable() .aspectRatio(contentMode: .fill) @@ -153,7 +153,7 @@ struct ImageTabView: View { } }) .sheet(isPresented: $isImagePickerPresented) { - SingleImagePickerView(selectedImage: $mypageViewModel.clubImage) + SingleImagePickerView(selectedImage: $selectedImage) } } .padding(.horizontal, 20) @@ -171,19 +171,27 @@ struct ImageTabView: View { Button(action: { selectedPage = .name }, label: { - SponusButtonLabel(text: "다음", disabledCondition: mypageViewModel.clubImageTabDisabledCondition ?? true) + SponusButtonLabel(text: "다음", disabledCondition: buttonDisabled[.image]!) }) - .disabled(mypageViewModel.clubImageTabDisabledCondition ?? true) + .disabled(buttonDisabled[.image]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) .onAppear { print("이미지탭 생성") - mypageViewModel.checkClubImageTabDisabledCondition() } - .onChange(of: mypageViewModel.clubImage) { - mypageViewModel.checkClubImageTabDisabledCondition() + .onChange(of: selectedImage) { + if selectedImage == nil { + buttonDisabled[.image] = true + print(buttonDisabled[.image]!) + mypageViewModel.clubImage = selectedImage + } + else { + buttonDisabled[.image] = false + print(buttonDisabled[.image]!) + mypageViewModel.clubImage = selectedImage + } } } } @@ -193,12 +201,14 @@ struct ImageTabView: View { struct NameTabView: View { -// @State var text = "" -// var limitTextCount = 13 + @State var text = "" + var limitTextCount = 13 @Binding var selectedPage: WriteClubProfileTab @ObservedObject var mypageViewModel: MypageViewModel + @Binding var buttonDisabled: [WriteClubProfileTab : Bool] + var body: some View { VStack(spacing: 0) { ScrollView { @@ -213,11 +223,11 @@ struct NameTabView: View { .foregroundStyle(Color.textPrimary) .padding(.bottom, 20) - TextField("ex. 스포너스 기획 동아리", text: $mypageViewModel.clubName) - .textFieldStyle(SponusTextfieldStyle(text: $mypageViewModel.clubName, limitTextCount: mypageViewModel.clubNameLimitTextCount)) + TextField("ex. 스포너스 기획 동아리", text: $text) + .textFieldStyle(SponusTextfieldStyle(text: $text, limitTextCount: limitTextCount)) .padding(.bottom, 8) - Text("(\(mypageViewModel.clubName.count)/\(mypageViewModel.clubNameLimitTextCount))") + Text("(\(text.count)/\(limitTextCount))") .font(.B2EnMd) .foregroundStyle(Color.textTertiary) .padding(.leading, 12) @@ -229,31 +239,39 @@ struct NameTabView: View { Button(action: { selectedPage = .introduce }, label: { - SponusButtonLabel(text: "다음", disabledCondition: mypageViewModel.clubNameTabDisabledCondition ?? true) + SponusButtonLabel(text: "다음", disabledCondition: buttonDisabled[.name]!) }) - .disabled(mypageViewModel.clubNameTabDisabledCondition ?? true) + .disabled(buttonDisabled[.name]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) .onAppear { print("네임탭 생성") - mypageViewModel.checkClubNameTabDisabledCondition() } - .onChange(of: mypageViewModel.clubName) { - mypageViewModel.checkClubNameTabDisabledCondition() + .onChange(of: text) { + if text.count == 0 || text.count > limitTextCount { + buttonDisabled[.name] = true + print(buttonDisabled[.name]!) + mypageViewModel.clubProfile?.name = text + } + else { + buttonDisabled[.name] = false + print(buttonDisabled[.name]!) + mypageViewModel.clubProfile?.name = text + } } - } - } struct IntroduceTabView: View { -// @State var text = "" -// var limitTextCount = 300 + @State var text = "" + var limitTextCount = 300 @Binding var selectedPage: WriteClubProfileTab @ObservedObject var mypageViewModel: MypageViewModel + + @Binding var buttonDisabled: [WriteClubProfileTab : Bool] var body: some View { @@ -270,30 +288,27 @@ struct IntroduceTabView: View { .foregroundStyle(Color.textPrimary) .padding(.bottom, 20) - TextEditor(text: $mypageViewModel.clubDescription) - .modifier(SponusTextEditorModifier(text: $mypageViewModel.clubDescription, limitTextCount: mypageViewModel.clubDescriptionLimitTextCount, height: 260, placeHolder: "ex. 안녕하세요. 저희는 스포대학교의 마케팅 기획을 하는 동아리 ‘스포대학교' 기획동아리 입니다.")) + TextEditor(text: $text) + .modifier(SponusTextEditorModifier(text: $text, limitTextCount: limitTextCount, height: 260, placeHolder: "ex. 안녕하세요. 저희는 스포대학교의 마케팅 기획을 하는 동아리 ‘스포대학교' 기획동아리 입니다.")) .padding(.bottom, 8) HStack(spacing: 0) { - Text("(\(mypageViewModel.clubDescription.count)/\(mypageViewModel.clubDescriptionLimitTextCount))") + Text("(\(text.count)/\(limitTextCount))") .font(.B2EnMd) .foregroundStyle(Color.textTertiary) Spacer() Button(action: { - mypageViewModel.clubDescription = "" + text = "" }, label: { Text("전체 삭제") .font(.B2EnMd) .foregroundStyle(Color.textTertiary) - }) - } .padding(.horizontal, 12) - } .padding(.horizontal, 20) } @@ -301,31 +316,38 @@ struct IntroduceTabView: View { Button(action: { selectedPage = .member }, label: { - SponusButtonLabel(text: "다음", disabledCondition: mypageViewModel.clubDescriptionTabDisabledCondition ?? true) + SponusButtonLabel(text: "다음", disabledCondition: buttonDisabled[.introduce]!) }) - .disabled(mypageViewModel.clubDescriptionTabDisabledCondition ?? true) + .disabled(buttonDisabled[.introduce]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) .onAppear { print("정보입력탭 생성") - mypageViewModel.checkClubDescriptionTabDisabledCondition() } - .onChange(of: mypageViewModel.clubDescription) { - mypageViewModel.checkClubDescriptionTabDisabledCondition() + .onChange(of: text) { + if text.count == 0 || text.count > limitTextCount { + buttonDisabled[.introduce] = true + mypageViewModel.clubProfile?.description = text + } + else { + buttonDisabled[.introduce] = false + mypageViewModel.clubProfile?.description = text + } } - } } struct MemberTabView: View { -// @State private var number = "" + @State private var text = "" var limitTextCount = 999 @Binding var selectedPage: WriteClubProfileTab @ObservedObject var mypageViewModel: MypageViewModel + + @Binding var buttonDisabled: [WriteClubProfileTab : Bool] var body: some View { @@ -342,15 +364,15 @@ struct MemberTabView: View { .foregroundStyle(Color.textPrimary) .padding(.bottom, 20) - TextField("ex. 999", text: $mypageViewModel.clubMemberCount) + TextField("ex. 999", text: $text) .keyboardType(.numberPad) - .onReceive(Just(mypageViewModel.clubMemberCount)) { newValue in + .onReceive(Just(text)) { newValue in let filtered = newValue.filter { "0123456789".contains($0) } if filtered != newValue { - self.mypageViewModel.clubMemberCount = filtered + text = filtered } } - .textFieldStyle(SponusTextfieldStyle(text: $mypageViewModel.clubMemberCount, limitTextCount: limitTextCount)) + .textFieldStyle(SponusTextfieldStyle(text: $text, limitTextCount: limitTextCount)) .padding(.bottom, 8) } @@ -360,28 +382,26 @@ struct MemberTabView: View { Button(action: { selectedPage = .link }, label: { - SponusButtonLabel(text: "다음", disabledCondition: mypageViewModel.clubMemberTabDisabledCondition ?? true) + SponusButtonLabel(text: "다음", disabledCondition: buttonDisabled[.member]!) }) - .disabled(mypageViewModel.clubMemberTabDisabledCondition ?? true) + .disabled(buttonDisabled[.member]!) .padding(.horizontal, 20) - } .background(Color.bgSecondary) .onAppear { print("회원수 입력탭 생성") - mypageViewModel.checkClubMemberTabDisabledCondition() } - .onChange(of: mypageViewModel.clubMemberCount) { - mypageViewModel.checkClubMemberTabDisabledCondition() + .onChange(of: text) { + if let numberValue = Int(text), numberValue > 0 { + buttonDisabled[.member] = false + mypageViewModel.clubProfile?.memberCount = Int(text) ?? 0 + } + else { + buttonDisabled[.member] = true + mypageViewModel.clubProfile?.memberCount = Int(text) ?? 0 + } } } - -// private func isButtonDisabled() -> Bool { -// guard let numberValue = Int(WriteClubProfileVM.clubMemberCount), numberValue > 0 else { -// return true -// } -// return false -// } } struct LinkTabView: View { @@ -392,6 +412,8 @@ struct LinkTabView: View { @Binding var selectedPage: WriteClubProfileTab @ObservedObject var WriteClubProfileVM: MypageViewModel + + @Binding var buttonDisabled: [WriteClubProfileTab : Bool] var limitTextCount = 999 @@ -454,21 +476,33 @@ struct LinkTabView: View { } struct FieldTabView: View { -// @State private var number = "" + var limitTextCount = 999 let maxSelections = 2 + @ObservedObject var mypageViewModel: MypageViewModel - @State private var categories: [ClubCategorySelection] = ClubCategory.allCases.dropFirst().map { - ClubCategorySelection(category: $0, isSelected: false) - } +// @State private var categories: [ClubCategorySelection] = ClubCategory.allCases.dropFirst().map { +// ClubCategorySelection(category: $0, isSelected: false) +// } + + var categories2 = ClubCategory.allCases.dropFirst().map { $0.rawValue } + @State var selectedCategories: [String] = [] + + @Binding var buttonDisabled: [WriteClubProfileTab : Bool] var body: some View { VStack(spacing: 0) { ScrollView { VStack(alignment: .leading, spacing: 0) { + Button(action: { + print(mypageViewModel.clubProfile) + }, label: { + Text("클럽프로필 출력") + }) + Rectangle() .frame(height: 0) .padding(.top, 36) @@ -483,15 +517,20 @@ struct FieldTabView: View { .foregroundStyle(Color.textDisabled) .padding(.bottom, 24) - ForEach($categories) { $category in - SelectinOptionCell(text: category.category.rawValue, isSelected: category.isSelected) + ForEach(categories2, id: \.self) { category in + SelectinOptionCell(text: category, isSelected: selectedCategories.contains(category)) .padding(.bottom, 8) .onTapGesture { - toggleSelection(for: category) - let selectedCategories = categories.filter { $0.isSelected }.map { $0.category.rawValue } - mypageViewModel.clubTypes = getMappedStrings(from: selectedCategories) - print(categories) - print(mypageViewModel.clubTypes) + if selectedCategories.contains(category) { + // 카테고리가 선택된 상태라면 배열에서 제거 + selectedCategories.removeAll { $0 == category } + } else if selectedCategories.count < maxSelections { + // 카테고리가 선택되지 않았고, 최대 선택 수를 넘지 않았을 때만 추가 + selectedCategories.append(category) + } + // 선택된 항목이 최대치에 도달한 경우, 아무 동작도 하지 않음 + // 매핑 +// print(getMappedStrings(from: selectedCategories)) } } } @@ -499,51 +538,28 @@ struct FieldTabView: View { } Button(action: { - let selectedCategories = categories.filter { $0.isSelected }.map { $0.category.rawValue } - print(getMappedStrings(from: selectedCategories)) - print(selectedCategories) - -// mypageViewModel.patchClubProfile(clubProfile: ClubProfile) - }, label: { - SponusButtonLabel(text: "완료", disabledCondition: mypageViewModel.patchClubProfileDisabledCondition) + SponusButtonLabel(text: "완료", disabledCondition: buttonDisabled[.image]! || buttonDisabled[.name]! || buttonDisabled[.introduce]! || buttonDisabled[.member]! || buttonDisabled[.field]!) }) - .disabled(mypageViewModel.patchClubProfileDisabledCondition) + .disabled(buttonDisabled[.image]! || buttonDisabled[.name]! || buttonDisabled[.introduce]! || buttonDisabled[.member]! || buttonDisabled[.field]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) .onAppear { print("동아리 분야 입력탭 생성") - mypageViewModel.checkClubTypesTabDisabledCondition() - mypageViewModel.checkPatchClubProfileDisabledCondition() - } - .onChange(of: mypageViewModel.clubTypes) { - mypageViewModel.checkClubTypesTabDisabledCondition() - mypageViewModel.checkPatchClubProfileDisabledCondition() } - } - - private func toggleSelection(for category: ClubCategorySelection) { - if category.isSelected { - // If the category is already selected, allow deselecting it - if let index = categories.firstIndex(where: { $0.id == category.id }) { - categories[index].isSelected.toggle() + .onChange(of: selectedCategories) { + if selectedCategories.count > 0 && selectedCategories.count <= 2 { + buttonDisabled[.field] = false + mypageViewModel.clubProfile?.clubTypes = getMappedStrings(from: selectedCategories) } - } else { - // If the category is not selected, allow selecting it only if the limit has not been reached - let selectedCount = categories.filter { $0.isSelected }.count - if selectedCount < maxSelections { - if let index = categories.firstIndex(where: { $0.id == category.id }) { - categories[index].isSelected.toggle() - } + else { + buttonDisabled[.field] = true + mypageViewModel.clubProfile?.clubTypes = getMappedStrings(from: selectedCategories) } } } - private func isButtonDisabled() -> Bool { - return categories.filter { $0.isSelected }.isEmpty - } - private func getMappedStrings(from categories: [String]) -> [String] { let mapping: [String: String] = [ ClubCategory.planningAndIdeas.rawValue: "PLANNING_IDEA", diff --git a/Spon-Us/MyPage/Company/WriteCompanyProfileView.swift b/Spon-Us/MyPage/Company/WriteCompanyProfileView.swift index 1d07de6..cc9c421 100644 --- a/Spon-Us/MyPage/Company/WriteCompanyProfileView.swift +++ b/Spon-Us/MyPage/Company/WriteCompanyProfileView.swift @@ -41,16 +41,16 @@ struct WriteCompanyProfileView: View { CompanyImageTabView(selectedPage: $selectedPage, imageTabDisabled: $imageTabDiabled, buttonDisabled: $buttonDisabled) .tag(WriteCompanyProfileTab.image) - CompanyNameTabView(selectedPage: $selectedPage) + CompanyNameTabView(selectedPage: $selectedPage, buttonDisabled: $buttonDisabled) .tag(WriteCompanyProfileTab.name) - CompanyCollaborationFieldTabView(selectedPage: $selectedPage) + CompanyCollaborationFieldTabView(selectedPage: $selectedPage, buttonDisabled: $buttonDisabled) .tag(WriteCompanyProfileTab.collaborationField) - CompanyFieldTabView(selectedPage: $selectedPage) + CompanyFieldTabView(selectedPage: $selectedPage, buttonDisabled: $buttonDisabled) .tag(WriteCompanyProfileTab.companyField) - CompanyLinkTabView(selectedPage: $selectedPage) + CompanyLinkTabView(selectedPage: $selectedPage, buttonDisabled: $buttonDisabled) .tag(WriteCompanyProfileTab.link) } @@ -154,14 +154,10 @@ struct CompanyImageTabView: View { .background(Color.bgSecondary) .onChange(of: selectedImage) { if selectedImage == nil { -// imageTabDisabled = true -// print(imageTabDisabled) buttonDisabled[.image] = true print(buttonDisabled[.image]!) } else { -// imageTabDisabled = false -// print(imageTabDisabled) buttonDisabled[.image] = false print(buttonDisabled[.image]!) } @@ -175,6 +171,7 @@ struct CompanyNameTabView: View { var limitTextCount = 13 @Binding var selectedPage: WriteCompanyProfileTab + @Binding var buttonDisabled: [WriteCompanyProfileTab : Bool] var body: some View { VStack(spacing: 0) { @@ -206,21 +203,26 @@ struct CompanyNameTabView: View { Button(action: { selectedPage = .collaborationField }, label: { - SponusButtonLabel(text: "다음", disabledCondition: text.count == 0 || text.count > limitTextCount) + SponusButtonLabel(text: "다음", disabledCondition: buttonDisabled[.name]!) }) - .disabled(text.count == 0 || text.count > limitTextCount) + .disabled(buttonDisabled[.name]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) - + .onChange(of: text) { + if text.count == 0 || text.count > limitTextCount { + buttonDisabled[.name] = true + print(buttonDisabled[.name]!) + } + else { + buttonDisabled[.name] = false + print(buttonDisabled[.name]!) + } + } } } -//enum CoworkCategory: String { -// case linkedProject = "연계프로젝트" -// case partnership = "제휴" -// case sponsorship = "협찬" -//} + struct CompanyCollaborationFieldTabView: View { @@ -234,17 +236,24 @@ struct CompanyCollaborationFieldTabView: View { @State var sponsorshipSelected = false @State var sponsorshipSelected2 = false - @State var text = "" - @State private var categories: [CompanyCategorySelection] = CompanyCategory.allCases.dropFirst().map { - CompanyCategorySelection(category: $0, isSelected: false) - } + @State var selectedCategories: [String] = [] + @State var sponsorshipContent = "" + + @Binding var buttonDisabled: [WriteCompanyProfileTab : Bool] var body: some View { VStack(spacing: 0) { ScrollView { VStack(alignment: .leading, spacing: 0) { + Button(action: { + print(selectedCategories) + print(sponsorshipContent) + }, label: { + Text("선택된 유형 추가") + }) + Rectangle() .frame(height: 0) .padding(.top, 36) @@ -254,29 +263,32 @@ struct CompanyCollaborationFieldTabView: View { .foregroundStyle(Color.textPrimary) .padding(.bottom, 20) - SelectinOptionCell(text: CoworkCategory.linkedProject.rawValue, isSelected: linkedProjectSelected) + SelectinOptionCell(text: CoworkCategory.linkedProject.rawValue, isSelected: selectedCategories.contains(CoworkCategory.linkedProject.rawValue)) .onTapGesture { - linkedProjectSelected.toggle() + if selectedCategories.contains(CoworkCategory.linkedProject.rawValue) { + selectedCategories.removeAll { $0 == CoworkCategory.linkedProject.rawValue } + } else { + selectedCategories.append(CoworkCategory.linkedProject.rawValue) + } } .padding(.bottom, 8) - SelectinOptionCell(text: CoworkCategory.partnership.rawValue, isSelected: partnershipSelected) - .onTapGesture { - partnershipSelected.toggle() - } - .padding(.bottom, 8) - - SelectinOptionCell(text: CoworkCategory.sponsorship.rawValue, isSelected: sponsorshipSelected) + SelectinOptionCell(text: CoworkCategory.partnership.rawValue, isSelected: selectedCategories.contains(CoworkCategory.partnership.rawValue)) .onTapGesture { - sponsorshipSelected.toggle() + if selectedCategories.contains(CoworkCategory.partnership.rawValue) { + selectedCategories.removeAll { $0 == CoworkCategory.partnership.rawValue } + } else { + selectedCategories.append(CoworkCategory.partnership.rawValue) + } } .padding(.bottom, 8) + VStack(spacing: 0) { HStack(spacing: 0) { Image("Tick Square") .renderingMode(.template) - .foregroundStyle(sponsorshipSelected2 ? Color.textBrand : Color.textDisabled) + .foregroundStyle(selectedCategories.contains(CoworkCategory.sponsorship.rawValue) ? Color.textBrand : Color.textDisabled) .padding(.trailing, 21) Text("협찬") @@ -286,29 +298,31 @@ struct CompanyCollaborationFieldTabView: View { Spacer() } .padding(.bottom, 12) + .onTapGesture { + if selectedCategories.contains(CoworkCategory.sponsorship.rawValue) { + selectedCategories.removeAll { $0 == CoworkCategory.sponsorship.rawValue } + sponsorshipContent = "" + } else { + selectedCategories.append(CoworkCategory.sponsorship.rawValue) + } + } - TextField("협찬 가능한 대표적인 물품", text: $text) + if selectedCategories.contains(CoworkCategory.sponsorship.rawValue) { + TextField("협찬 가능한 대표적인 물품", text: $sponsorshipContent) + .padding(.bottom, 14) + } + } - .padding(.vertical, 14) + .padding(.top, 14) .padding(.leading, 20) .background(Color.bgWhite) .cornerRadius(16) .overlay( RoundedRectangle(cornerRadius: 16) .inset(by: 0.5) - .stroke(sponsorshipSelected2 ? Color.textBrand : Color.line200, lineWidth: 1) - + .stroke(selectedCategories.contains(CoworkCategory.sponsorship.rawValue) ? Color.textBrand : Color.line200, lineWidth: 1) ) - - -// ForEach($categories) { $category in -// SelectinOptionCell(text: category.category.rawValue, isSelected: category.isSelected) -// .padding(.bottom, 8) -// .onTapGesture { -// toggleSelection(for: category) -// } -// } } .padding(.horizontal, 20) } @@ -316,35 +330,51 @@ struct CompanyCollaborationFieldTabView: View { Button(action: { }, label: { - SponusButtonLabel(text: "완료", disabledCondition: isButtonDisabled()) + SponusButtonLabel(text: "완료", disabledCondition: selectedCategories.isEmpty || (selectedCategories.contains(CoworkCategory.sponsorship.rawValue) && sponsorshipContent.isEmpty)) }) - .disabled(isButtonDisabled()) + .disabled(selectedCategories.isEmpty || (selectedCategories.contains(CoworkCategory.sponsorship.rawValue) && sponsorshipContent.isEmpty)) .padding(.horizontal, 20) } .background(Color.bgSecondary) + .onChange(of: selectedCategories) { + if selectedCategories.isEmpty { + buttonDisabled[.collaborationField] = true + } + else { + buttonDisabled[.collaborationField] = false + print(buttonDisabled[.companyField]!) + } + } } - private func isButtonDisabled() -> Bool { - return categories.filter { $0.isSelected }.isEmpty - } +// private func isButtonDisabled() -> Bool { +// return categories.filter { $0.isSelected }.isEmpty +// } } struct CompanyFieldTabView: View { - @State private var number = "" @Binding var selectedPage: WriteCompanyProfileTab var limitTextCount = 999 let maxSelections = 3 - @State private var categories: [CompanyCategorySelection] = CompanyCategory.allCases.dropFirst().map { - CompanyCategorySelection(category: $0, isSelected: false) - } + @Binding var buttonDisabled: [WriteCompanyProfileTab : Bool] + + var categories: [String] = CompanyCategory.allCases.dropFirst().map { $0.rawValue } + @State var selectedCategories: [String] = [] var body: some View { VStack(spacing: 0) { + + Button(action: { + print(categories) + }, label: { + Text("카테고리 출력") + }) + ScrollView { VStack(alignment: .leading, spacing: 0) { @@ -362,12 +392,23 @@ struct CompanyFieldTabView: View { .foregroundStyle(Color.textDisabled) .padding(.bottom, 24) - ForEach($categories) { $category in - SelectinOptionCell(text: category.category.rawValue, isSelected: category.isSelected) - .padding(.bottom, 8) - .onTapGesture { - toggleSelection(for: category) + + ForEach(categories, id: \.self) { category in + SelectinOptionCell( + text: category, + isSelected: selectedCategories.contains(category) + ) + .padding(.bottom, 8) + .onTapGesture { + if selectedCategories.contains(category) { + // 카테고리가 선택된 상태라면 배열에서 제거 + selectedCategories.removeAll { $0 == category } + } else if selectedCategories.count < maxSelections { + // 카테고리가 선택되지 않았고, 최대 선택 수를 넘지 않았을 때만 추가 + selectedCategories.append(category) } + // 선택된 항목이 최대치에 도달한 경우, 아무 동작도 하지 않음 + } } } .padding(.horizontal, 20) @@ -376,34 +417,23 @@ struct CompanyFieldTabView: View { Button(action: { }, label: { - SponusButtonLabel(text: "완료", disabledCondition: isButtonDisabled()) + SponusButtonLabel(text: "완료", disabledCondition: buttonDisabled[.companyField]!) }) - .disabled(isButtonDisabled()) + .disabled(buttonDisabled[.companyField]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) - } - - private func toggleSelection(for category: CompanyCategorySelection) { - if category.isSelected { - // If the category is already selected, allow deselecting it - if let index = categories.firstIndex(where: { $0.id == category.id }) { - categories[index].isSelected.toggle() + .onChange(of: selectedCategories) { + if selectedCategories.isEmpty { + buttonDisabled[.companyField] = true + print(buttonDisabled[.companyField]!) } - } else { - // If the category is not selected, allow selecting it only if the limit has not been reached - let selectedCount = categories.filter { $0.isSelected }.count - if selectedCount < maxSelections { - if let index = categories.firstIndex(where: { $0.id == category.id }) { - categories[index].isSelected.toggle() - } + else { + buttonDisabled[.companyField] = false + print(buttonDisabled[.companyField]!) } } } - - private func isButtonDisabled() -> Bool { - return categories.filter { $0.isSelected }.isEmpty - } } struct CompanyLinkTabView: View { @@ -411,6 +441,8 @@ struct CompanyLinkTabView: View { @State private var WebsiteUrl = "" @Binding var selectedPage: WriteCompanyProfileTab + + @Binding var buttonDisabled: [WriteCompanyProfileTab : Bool] var limitTextCount = 999 @@ -443,10 +475,14 @@ struct CompanyLinkTabView: View { .padding(.horizontal, 20) } Button(action: { - + print(buttonDisabled[.image]) + print(buttonDisabled[.name]) + print(buttonDisabled[.collaborationField]) + print(buttonDisabled[.companyField]) }, label: { - SponusButtonLabel(text: "다음", disabledCondition: false) + SponusButtonLabel(text: "다음", disabledCondition: buttonDisabled[.image]! || buttonDisabled[.name]! || buttonDisabled[.collaborationField]! || buttonDisabled[.companyField]!) }) + .disabled(buttonDisabled[.image]! || buttonDisabled[.name]! || buttonDisabled[.collaborationField]! || buttonDisabled[.companyField]!) .padding(.horizontal, 20) } .background(Color.bgSecondary) diff --git a/Spon-Us/MyPage/Network/MyPageModel.swift b/Spon-Us/MyPage/Network/MyPageModel.swift index 035630d..4f6f072 100644 --- a/Spon-Us/MyPage/Network/MyPageModel.swift +++ b/Spon-Us/MyPage/Network/MyPageModel.swift @@ -117,3 +117,13 @@ struct ClubProfile: Codable { var profileStatus: String } + +struct PostImageResponse: Codable { + let statusCode: String + let message: String + let content: ImageUrl +} + +struct ImageUrl: Codable { + let imageUrl: String +} diff --git a/Spon-Us/MyPage/Network/MypageViewModel.swift b/Spon-Us/MyPage/Network/MypageViewModel.swift index 0110c67..4909313 100644 --- a/Spon-Us/MyPage/Network/MypageViewModel.swift +++ b/Spon-Us/MyPage/Network/MypageViewModel.swift @@ -19,37 +19,31 @@ class MypageViewModel: ObservableObject { @Published var clubImageUrl: String = "" @Published var clubImage: UIImage? - @Published var clubImageTabDisabledCondition: Bool = true - - - @Published var clubName: String = "" - var clubNameLimitTextCount = 13 - @Published var clubNameTabDisabledCondition: Bool = true - - - @Published var clubDescription: String = "" - var clubDescriptionLimitTextCount = 300 - @Published var clubDescriptionTabDisabledCondition: Bool = true - - - @Published var clubMemberCount: String = "" -// var clubMemberCountLimitTextCount: String = "" - @Published var clubMemberTabDisabledCondition: Bool = true - - - @Published var clubTypes: [String] = [] - @Published var clubTypesTabDisabledCondition: Bool = true - - @Published var patchClubProfileDisabledCondition: Bool = true - - - @Published var clubProfileStatus: String = "" +// +// +// @Published var clubName: String = "" +// +// +// @Published var clubDescription: String = "" +// +// +// @Published var clubMemberCount: String = "" +// +// +// @Published var clubTypes: [String] = [] +// +// +// @Published var clubProfileStatus: String = "" @Published var clubProfile: ClubProfile? private let provider = MoyaProvider() + init() { + clubProfile = ClubProfile(name: "", description: "", imageURL: "", memberCount: 0, clubTypes: [], profileStatus: "") + } + func getMyOrganization() { provider.request(.getMyOrganization) { result in @@ -108,15 +102,29 @@ class MypageViewModel: ObservableObject { } func postProfileImage(UIImage: UIImage) { - provider.request(.postProfileImage(image: UIImage)) { result in + + // 타임스탬프 기반 파일 이름 생성 + let timestamp = Int(Date().timeIntervalSince1970) + let uniqueFileName = "image_\(timestamp).jpg" + + provider.request(.postProfileImage(image: UIImage, fileName: uniqueFileName)) { result in DispatchQueue.main.async { switch result { case .success(let response): print(response) if let responseString = String(data: response.data, encoding: .utf8) { print("Response Data: \(responseString)") + print("postProfileImage네트워크 요청 성공🚨") + } + + if let postImageResponse = try? response.map(PostImageResponse.self) { + self.clubProfile?.imageURL = postImageResponse.content.imageUrl + print(self.clubProfile) + print("postProfileImage매핑 성공🚨") + } + else { + print("postProfileImage매핑 실패🚨") } - print("postProfileImage네트워크 요청 성공🚨") case .failure(let error): if let response = error.response { @@ -131,68 +139,68 @@ class MypageViewModel: ObservableObject { } // api 아닌 함수 - func checkClubImageTabDisabledCondition() { - if clubImage == nil { - print(true) - clubImageTabDisabledCondition = true - } - else { - print(false) - clubImageTabDisabledCondition = false - } - } - - func checkClubNameTabDisabledCondition() { - if clubName.count == 0 || clubName.count > clubNameLimitTextCount { - print(true) - clubNameTabDisabledCondition = true - } - else { - print(false) - clubNameTabDisabledCondition = false - } - } - - func checkClubDescriptionTabDisabledCondition() { - if clubDescription.count == 0 || clubDescription.count > clubDescriptionLimitTextCount { - print(true) - clubDescriptionTabDisabledCondition = true - } - else { - print(false) - clubDescriptionTabDisabledCondition = false - } - } - - func checkClubMemberTabDisabledCondition() { - if let numberValue = Int(clubMemberCount), numberValue > 0 { - print(false) - clubMemberTabDisabledCondition = false - } - else { - print(true) - clubMemberTabDisabledCondition = true - } - } - - func checkClubTypesTabDisabledCondition() { - if clubTypes.count > 0 && clubTypes.count <= 2 { - print(false) - clubTypesTabDisabledCondition = false - } - else { - print(true) - clubTypesTabDisabledCondition = true - } - } - - func checkPatchClubProfileDisabledCondition() { - if clubImageTabDisabledCondition == false && clubNameTabDisabledCondition == false && clubDescriptionTabDisabledCondition == false && clubMemberTabDisabledCondition == false && clubTypesTabDisabledCondition == false { - patchClubProfileDisabledCondition = false - } - else { - patchClubProfileDisabledCondition = true - } - } +// func checkClubImageTabDisabledCondition() { +// if clubImage == nil { +// print(true) +// clubImageTabDisabledCondition = true +// } +// else { +// print(false) +// clubImageTabDisabledCondition = false +// } +// } +// +// func checkClubNameTabDisabledCondition() { +// if clubName.count == 0 || clubName.count > clubNameLimitTextCount { +// print(true) +// clubNameTabDisabledCondition = true +// } +// else { +// print(false) +// clubNameTabDisabledCondition = false +// } +// } +// +// func checkClubDescriptionTabDisabledCondition() { +// if clubDescription.count == 0 || clubDescription.count > clubDescriptionLimitTextCount { +// print(true) +// clubDescriptionTabDisabledCondition = true +// } +// else { +// print(false) +// clubDescriptionTabDisabledCondition = false +// } +// } +// +// func checkClubMemberTabDisabledCondition() { +// if let numberValue = Int(clubMemberCount), numberValue > 0 { +// print(false) +// clubMemberTabDisabledCondition = false +// } +// else { +// print(true) +// clubMemberTabDisabledCondition = true +// } +// } +// +// func checkClubTypesTabDisabledCondition() { +// if clubTypes.count > 0 && clubTypes.count <= 2 { +// print(false) +// clubTypesTabDisabledCondition = false +// } +// else { +// print(true) +// clubTypesTabDisabledCondition = true +// } +// } +// +// func checkPatchClubProfileDisabledCondition() { +// if clubImageTabDisabledCondition == false && clubNameTabDisabledCondition == false && clubDescriptionTabDisabledCondition == false && clubMemberTabDisabledCondition == false && clubTypesTabDisabledCondition == false { +// patchClubProfileDisabledCondition = false +// } +// else { +// patchClubProfileDisabledCondition = true +// } +// } } diff --git a/Spon-Us/Network/SponusAPI.swift b/Spon-Us/Network/SponusAPI.swift index 11e75d2..a06b23b 100644 --- a/Spon-Us/Network/SponusAPI.swift +++ b/Spon-Us/Network/SponusAPI.swift @@ -27,7 +27,7 @@ enum SponusAPI { case getReissue(refreshToken: String) case getMyOrganization case patchMyClubProfile(clubProfile: ClubProfile) - case postProfileImage(image: UIImage) + case postProfileImage(image: UIImage, fileName: String) } extension SponusAPI: TargetType { @@ -201,12 +201,13 @@ extension SponusAPI: TargetType { case .patchMyClubProfile(let clubProfile): return .requestParameters(parameters: ["name": clubProfile.name, "description": clubProfile.description, "imageUrl": clubProfile.imageURL, "memberCount": clubProfile.memberCount, "clubTypes": clubProfile.clubTypes, "profileStatus": clubProfile.profileStatus], encoding: JSONEncoding.default) - case .postProfileImage(let image): + case .postProfileImage(let image, let fileName): let imageData = image.jpegData(compressionQuality: 0.1)! - let formData = MultipartFormData(provider: .data(imageData), name: "profileImage", fileName: "profileImage.JPG", mimeType: "image/jpeg") + let formData = MultipartFormData(provider: .data(imageData), name: "profileImage", fileName: "image9.jpg", mimeType: "image/jpeg") return .uploadMultipart([formData]) } } + var validationType: ValidationType { diff --git a/Spon-Us/OnBoarding/View/LoginView.swift b/Spon-Us/OnBoarding/View/LoginView.swift index 5098d63..3198db8 100644 --- a/Spon-Us/OnBoarding/View/LoginView.swift +++ b/Spon-Us/OnBoarding/View/LoginView.swift @@ -102,7 +102,10 @@ struct LoginView: View { Button(action: { loginVM.login(email: email, password: password) { resultContent in switch resultContent { - case "success" : loginVM.loginSuccess = true + case "success" : + loginVM.loginSuccess = true + UserDefaults.standard.set(true, forKey: "isAutoLogin") +// TokenManager.shared.isAutoLogin = true case "Account not found": wrongInput = "email" case "Bad credentials": wrongInput = "password" default: diff --git a/Spon-Us/Spon_UsApp.swift b/Spon-Us/Spon_UsApp.swift index 7df7ebb..fd15f9b 100644 --- a/Spon-Us/Spon_UsApp.swift +++ b/Spon-Us/Spon_UsApp.swift @@ -18,14 +18,15 @@ struct Spon_UsApp: App { if (vm.loginSuccess || UserDefaults.standard.bool(forKey: "isAutoLogin")) && !TokenManager.shared.isRefreshTokenExpired() { ContentView().onAppear(perform: { print("\(vm.loginSuccess), \(TokenManager.shared.isAutoLogin ?? false), \(!TokenManager.shared.isRefreshTokenExpired())") - }) + }).environmentObject(vm) } else { OnBoardingView().onAppear(perform: { print("\(vm.loginSuccess), \(TokenManager.shared.isAutoLogin ?? false), \(!TokenManager.shared.isRefreshTokenExpired())") - }) + }).environmentObject(vm) } // WriteCompanyProfileView() - }.environmentObject(vm) + }/*.environmentObject(vm)*/ .environmentObject(MypageNavigationPathFinder.shared) } } +