Skip to content

Commit

Permalink
feat: 🎸 invitation code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun committed Nov 22, 2023
1 parent 662bbc7 commit f009783
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 12 deletions.
86 changes: 74 additions & 12 deletions Packages/GodPackage/Sources/OnboardFeature/InvitationCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,57 @@ public struct InvitationCodeLogic {
public init() {}

public struct State: Equatable {
@BindingState var invitationCode = ""
var isDisabled = true
public init() {}
}

public enum Action: Equatable {
public enum Action: BindableAction {
case onTask
case onAppear
case nextButtonTapped
case skipButtonTapped
case binding(BindingAction<State>)
case delegate(Delegate)

public enum Delegate: Equatable {
case nextScreen(String?)
}
}

@Dependency(\.analytics) var analytics

public var body: some Reducer<State, Action> {
Reduce<State, Action> { _, action in
BindingReducer()
Reduce<State, Action> { state, action in
switch action {
case .onTask:
return .none

case .onAppear:
analytics.logScreen(screenName: "InvitationCode", of: self)
return .none

case .nextButtonTapped:
let code = state.invitationCode
return .send(.delegate(.nextScreen(code)))

case .skipButtonTapped:
return .send(.delegate(.nextScreen(nil)))

case .binding(\.$invitationCode):
state.isDisabled = state.invitationCode.count != 6
return .none

default:
return .none
}
}
}
}

public struct InvitationCodeView: View {
@FocusState var focus: Bool
let store: StoreOf<InvitationCodeLogic>

public init(store: StoreOf<InvitationCodeLogic>) {
Expand All @@ -40,22 +66,58 @@ public struct InvitationCodeView: View {

public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
List {
Text("InvitationCode", bundle: .module)
VStack(spacing: 12) {
Spacer()
Text("Do you have invitation code?", bundle: .module)
.font(.system(.title3, design: .rounded, weight: .bold))

Text("If you do not have it, you can skip it.", bundle: .module)
.font(.system(.body, design: .rounded))

TextField(text: viewStore.$invitationCode) {
Text("ABCDEF", bundle: .module)
}
.foregroundStyle(.white)
.multilineTextAlignment(.center)
.font(.system(.title, design: .rounded))
.focused($focus)

Spacer()

NextButton(isDisabled: viewStore.isDisabled) {
store.send(.nextButtonTapped)
}

Button {
store.send(.skipButtonTapped)
} label: {
Text("Skip", bundle: .module)
.frame(height: 44)
.frame(maxWidth: .infinity)
.font(.system(.body, design: .rounded))
}
}
.navigationTitle("InvitationCode")
.navigationBarTitleDisplayMode(.inline)
.padding(.horizontal, 24)
.padding(.bottom, 16)
.foregroundStyle(Color.white)
.background(Color.godService)
.task { await store.send(.onTask).finish() }
.onAppear { store.send(.onAppear) }
.onAppear {
focus = true
store.send(.onAppear)
}
}
}
}

#Preview {
InvitationCodeView(
store: .init(
initialState: InvitationCodeLogic.State(),
reducer: { InvitationCodeLogic() }
NavigationStack {
InvitationCodeView(
store: .init(
initialState: InvitationCodeLogic.State(),
reducer: { InvitationCodeLogic() }
)
)
)
}
.environment(\.locale, Locale(identifier: "ja-JP"))
}
23 changes: 23 additions & 0 deletions Packages/GodPackage/Sources/OnboardFeature/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
}
}
}
},
"ABCDEF" : {

},
"Add a photo so your friends can find you" : {
"localizations" : {
Expand Down Expand Up @@ -147,6 +150,16 @@
}
}
},
"Do you have invitation code?" : {
"localizations" : {
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "招待コードを持っていますか?"
}
}
}
},
"Enable Contacts" : {

},
Expand Down Expand Up @@ -329,6 +342,16 @@
}
}
},
"If you do not have it, you can skip it." : {
"localizations" : {
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "持っていない場合はスキップ出来ます。"
}
}
}
},
"Imported from Contacts" : {
"localizations" : {
"ja" : {
Expand Down

0 comments on commit f009783

Please sign in to comment.