Skip to content

Commit dd70818

Browse files
committed
[feat] #211 포킷 설정 - 참여자, 소유자 분기
1 parent 4c2ba6d commit dd70818

2 files changed

Lines changed: 87 additions & 39 deletions

File tree

Projects/Feature/FeatureCategorySetting/Sources/PokitCategorySettingFeature.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ public struct PokitCategorySettingFeature {
2727
var keyboardClient
2828
@Dependency(UserNotificationClient.self)
2929
var userNotificationClient
30+
@Dependency(UserDefaultsClient.self)
31+
var userDefaultsClient
3032
@Dependency(\.openSettings)
3133
var openSetting
3234
/// - State
3335
@ObservableState
3436
public struct State: Equatable {
3537
fileprivate var domain: PokitCategorySetting
36-
38+
3739
var selectedProfile: BaseCategoryImage? {
3840
get { domain.categoryImage }
3941
set { domain.categoryImage = newValue }
@@ -45,20 +47,25 @@ public struct PokitCategorySettingFeature {
4547
var profileImages: [BaseCategoryImage] {
4648
get { domain.imageList }
4749
}
48-
50+
4951
var selectedKeywordType: BaseInterestType {
5052
get { domain.keywordType }
5153
set { domain.keywordType = newValue }
5254
}
53-
55+
5456
var isPublicType: Bool {
5557
get { domain.openType == .공개 ? true : false }
5658
set { domain.openType = newValue ? .공개 : .비공개 }
5759
}
5860
var saveButtonEnabled: Bool {
59-
!categoryName.isEmpty
60-
&& selectedProfile != nil
61-
&& (domain.openType == .공개 ? keywordSelectType != .normal : true)
61+
// 참여자는 항상 활성화 (알림 설정만 변경)
62+
if isParticipant {
63+
return true
64+
}
65+
// 소유자는 기존 로직
66+
return !categoryName.isEmpty
67+
&& selectedProfile != nil
68+
&& (domain.openType == .공개 ? keywordSelectType != .normal : true)
6269
}
6370
var isCoEditing: Bool {
6471
let userCount = domain.userCount ?? 0
@@ -67,6 +74,17 @@ public struct PokitCategorySettingFeature {
6774
var alertEnable: Bool {
6875
isNotificationAuthorization && isAlert
6976
}
77+
78+
/// 소유권 검증
79+
var categoryUserId: Int?
80+
var currentUserId: Int?
81+
var isOwner: Bool {
82+
guard let currentUserId, let categoryUserId else { return true }
83+
return categoryUserId == currentUserId
84+
}
85+
var isParticipant: Bool {
86+
!isOwner && isCoEditing
87+
}
7088

7189
let type: SettingType
7290
var keywordSelectType: KeywordSelectType = .normal
@@ -96,6 +114,7 @@ public struct PokitCategorySettingFeature {
96114
keywordType: category?.keywordType,
97115
userCount: category?.userCount
98116
)
117+
self.categoryUserId = category?.userId
99118
}
100119
}
101120

@@ -275,6 +294,12 @@ private extension PokitCategorySettingFeature {
275294
}
276295

277296
case .뷰가_나타났을때:
297+
/// 현재 로그인한 사용자 ID 가져오기
298+
if let userIdString = userDefaultsClient.stringKey(.userId),
299+
let userId = Int(userIdString) {
300+
state.currentUserId = userId
301+
}
302+
278303
let selectType = state.selectedKeywordType
279304
if selectType != .default {
280305
state.keywordSelectType = .select(keywordName: selectType.title)

Projects/Feature/FeatureCategorySetting/Sources/PokitCategorySettingView.swift

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ public extension PokitCategorySettingView {
3737
PokitDivider()
3838
.padding(.horizontal, -20)
3939
.padding(.top, 28)
40-
41-
if store.isCoEditing { alarmSettingSection }
42-
43-
openTypeSettingSection
44-
keywordSection
40+
41+
// 공동 편집 중이면 알림 받기 표시 (소유자, 참여자 모두)
42+
if store.isCoEditing {
43+
alarmSettingSection
44+
}
45+
46+
// 소유자만 전체 공개 설정과 키워드 표시
47+
if store.isOwner {
48+
openTypeSettingSection
49+
keywordSection
50+
}
51+
4552
Spacer()
4653
}
4754
.padding(.top, 16)
@@ -81,8 +88,17 @@ public extension PokitCategorySettingView {
8188
}
8289
//MARK: - Configure View
8390
private extension PokitCategorySettingView {
91+
@ViewBuilder
8492
var navigationBar: some View {
85-
PokitHeader(title: store.type.title) {
93+
let title: String = {
94+
// 참여자는 "포킷 설정", 소유자는 기존 타이틀
95+
if store.isParticipant {
96+
return "포킷 설정"
97+
}
98+
return store.type.title
99+
}()
100+
101+
PokitHeader(title: title) {
86102
PokitHeaderItems(placement: .leading) {
87103
PokitToolbarButton(.icon(.arrowLeft)) {
88104
send(.dismiss)
@@ -122,30 +138,33 @@ private extension PokitCategorySettingView {
122138
}
123139
.frame(width: 80, height: 80)
124140
.overlay(alignment: .bottomTrailing) {
125-
Circle()
126-
.stroke(
127-
.pokit(.icon(.tertiary)),
128-
lineWidth: 1
129-
)
130-
.frame(width: 24, height: 24)
131-
.background {
132-
ZStack {
133-
Circle()
134-
.foregroundStyle(
135-
.pokit(.icon(.inverseWh))
136-
)
137-
Button(action: { send(.프로필_설정_버튼_눌렀을때) }) {
138-
Image(.icon(.edit))
139-
.resizable()
140-
.frame(width: 18, height: 18)
141-
.foregroundStyle(.pokit(.icon(.tertiary)))
142-
.padding(2)
141+
// 소유자만 프로필 편집 버튼 표시
142+
if store.isOwner {
143+
Circle()
144+
.stroke(
145+
.pokit(.icon(.tertiary)),
146+
lineWidth: 1
147+
)
148+
.frame(width: 24, height: 24)
149+
.background {
150+
ZStack {
151+
Circle()
152+
.foregroundStyle(
153+
.pokit(.icon(.inverseWh))
154+
)
155+
Button(action: { send(.프로필_설정_버튼_눌렀을때) }) {
156+
Image(.icon(.edit))
157+
.resizable()
158+
.frame(width: 18, height: 18)
159+
.foregroundStyle(.pokit(.icon(.tertiary)))
160+
.padding(2)
161+
}
143162
}
163+
144164
}
145-
146-
}
147-
.offset(x: 10)
148-
.padding(.bottom, 3)
165+
.offset(x: 10)
166+
.padding(.bottom, 3)
167+
}
149168
}
150169
}
151170
/// 타이틀 + 텍스트필드를 포함한 포킷명 입력 섹션
@@ -154,20 +173,24 @@ private extension PokitCategorySettingView {
154173
Text("포킷명")
155174
.pokitFont(.b2(.m))
156175
.foregroundStyle(.pokit(.text(.secondary)))
157-
176+
158177
PokitTextInput(
159178
text: $store.categoryName,
160-
type: store.categoryName.isEmpty ? .text : .iconR(
179+
type: store.isOwner && !store.categoryName.isEmpty ? .iconR(
161180
icon: .icon(.x),
162181
action: { send(.포킷명지우기_버튼_눌렀을때) }
163-
),
182+
) : .text,
164183
shape: .rectangle,
165-
state: $store.pokitNameTextInpuState,
166-
placeholder: "포킷명을 입력해주세요.",
184+
state: store.isParticipant
185+
? .constant(.disable)
186+
: $store.pokitNameTextInpuState,
187+
placeholder: store.isOwner ? "포킷명을 입력해주세요." : "",
188+
info: store.isParticipant ? "수정 권한이 없습니다." : nil,
167189
maxLetter: 10,
168190
focusState: $isFocused,
169191
equals: true
170192
)
193+
.disabled(!store.isOwner)
171194
}
172195
}
173196

0 commit comments

Comments
 (0)