Some clean up on new user creation
This commit is contained in:
@ -12,7 +12,6 @@
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioController: AudioController
|
||||
|
||||
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
let delete: (_: NSManagedObjectID) -> Void
|
||||
|
||||
@ -30,11 +30,10 @@ import Views
|
||||
|
||||
init() {}
|
||||
|
||||
func submitProfile(name: String, bio: String, authenticator: Authenticator) {
|
||||
func submitProfile(name: String, authenticator: Authenticator) {
|
||||
let profileOrError = NewUserProfile.make(
|
||||
username: potentialUsername,
|
||||
name: name,
|
||||
bio: bio.isEmpty ? nil : bio
|
||||
name: name
|
||||
)
|
||||
|
||||
switch profileOrError {
|
||||
@ -112,7 +111,6 @@ struct CreateProfileView: View {
|
||||
@StateObject private var viewModel = CreateProfileViewModel()
|
||||
|
||||
@State private var name = ""
|
||||
@State private var bio = ""
|
||||
|
||||
init(userProfile: NewUserProfile) {
|
||||
self.initialUserProfile = userProfile
|
||||
@ -171,29 +169,11 @@ struct CreateProfileView: View {
|
||||
}
|
||||
.animation(.default, value: 0.35)
|
||||
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text(LocalText.registrationBio)
|
||||
.font(.appFootnote)
|
||||
.foregroundColor(.appGrayText)
|
||||
TextEditor(text: $bio)
|
||||
.lineSpacing(6)
|
||||
.accentColor(.appGraySolid)
|
||||
.foregroundColor(.appGrayText)
|
||||
.font(.appBody)
|
||||
.padding(12)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 16)
|
||||
.strokeBorder(Color.appGrayBorder, lineWidth: 1)
|
||||
.background(RoundedRectangle(cornerRadius: 16).fill(Color.systemBackground))
|
||||
)
|
||||
.frame(height: 160)
|
||||
}
|
||||
|
||||
Button(
|
||||
action: { viewModel.submitProfile(name: name, bio: bio, authenticator: authenticator) },
|
||||
action: { viewModel.submitProfile(name: name, authenticator: authenticator) },
|
||||
label: { Text(viewModel.submitButtonText) }
|
||||
)
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appDeepBackground, width: 300))
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, textColor: Color.themeDarkGray, width: 300))
|
||||
|
||||
if let errorMessage = viewModel.validationErrorMessage {
|
||||
Text(errorMessage)
|
||||
|
||||
@ -45,7 +45,7 @@ struct EmailAuthView: View {
|
||||
|
||||
var innerBody: some View {
|
||||
ZStack {
|
||||
Color.appBackground.edgesIgnoringSafeArea(.all)
|
||||
Color.themeSolidBackground.edgesIgnoringSafeArea(.all)
|
||||
primaryContent
|
||||
.frame(maxWidth: 300)
|
||||
#if os(iOS)
|
||||
|
||||
@ -93,7 +93,7 @@ struct EmailLoginFormView: View {
|
||||
},
|
||||
label: { Text(LocalText.genericSubmit) }
|
||||
)
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, width: 300))
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, textColor: Color.themeDarkGray, width: 300))
|
||||
|
||||
if let loginError = viewModel.loginError {
|
||||
LoginErrorMessageView(loginError: loginError)
|
||||
@ -186,7 +186,7 @@ struct EmailPendingVerificationView: View {
|
||||
}
|
||||
}
|
||||
)
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appDeepBackground, width: 300))
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, textColor: Color.themeDarkGray, width: 300))
|
||||
|
||||
HStack {
|
||||
Button(
|
||||
|
||||
@ -191,7 +191,7 @@ struct EmailSignupFormView: View {
|
||||
}
|
||||
}
|
||||
)
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, width: 300))
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, textColor: Color.themeDarkGray, width: 300))
|
||||
|
||||
if let loginError = viewModel.loginError {
|
||||
LoginErrorMessageView(loginError: loginError)
|
||||
|
||||
@ -50,13 +50,13 @@ struct NewAppleSignupView: View {
|
||||
},
|
||||
label: { Text(LocalText.genericContinue) }
|
||||
)
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appDeepBackground, width: 300))
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, textColor: Color.themeDarkGray, width: 300))
|
||||
|
||||
Button(
|
||||
action: showProfileEditView,
|
||||
label: { Text(LocalText.registrationChangeUsername) }
|
||||
)
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appDeepBackground, width: 300))
|
||||
.buttonStyle(SolidCapsuleButtonStyle(color: .appCtaYellow, textColor: Color.themeDarkGray, width: 300))
|
||||
|
||||
if let loginError = viewModel.loginError {
|
||||
LoginErrorMessageView(loginError: loginError)
|
||||
|
||||
@ -159,6 +159,8 @@ struct WelcomeView: View {
|
||||
|
||||
var logoView: some View {
|
||||
Image.omnivoreTitleLogo
|
||||
.renderingMode(.template)
|
||||
.foregroundColor(Color.appGrayTextContrast)
|
||||
.gesture(
|
||||
TapGesture(count: 2)
|
||||
.onEnded {
|
||||
@ -231,7 +233,7 @@ struct WelcomeView: View {
|
||||
|
||||
public var body: some View {
|
||||
ZStack(alignment: viewModel.registrationState == nil ? .leading : .center) {
|
||||
Color.appBackground
|
||||
Color.themeSolidBackground
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.modifier(SizeModifier())
|
||||
.onPreferenceChange(SizePreferenceKey.self) {
|
||||
@ -286,7 +288,6 @@ struct WelcomeView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.preferredColorScheme(.light)
|
||||
.task { selectedEnvironment = dataService.appEnvironment }
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,13 +20,12 @@ public struct NewUserProfile: Codable {
|
||||
public extension NewUserProfile {
|
||||
static func make(
|
||||
username: String,
|
||||
name: String,
|
||||
bio: String?
|
||||
name: String
|
||||
) -> Either<NewUserProfile, String> {
|
||||
let userProfile = NewUserProfile(
|
||||
username: username,
|
||||
name: name,
|
||||
bio: bio
|
||||
bio: nil
|
||||
)
|
||||
|
||||
if let errorMessage = userProfile.validationErrorMessage {
|
||||
|
||||
@ -38237,6 +38237,8 @@ extension Enums {
|
||||
enum OptInFeatureErrorCode: String, CaseIterable, Codable {
|
||||
case badRequest = "BAD_REQUEST"
|
||||
|
||||
case ineligible = "INELIGIBLE"
|
||||
|
||||
case notFound = "NOT_FOUND"
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,10 @@ public struct Feature {
|
||||
public let granted: Bool
|
||||
}
|
||||
|
||||
public enum IneligibleError: Error {
|
||||
case message(messageText: String)
|
||||
}
|
||||
|
||||
public extension DataService {
|
||||
func optInFeature(name: String) async throws -> Feature? {
|
||||
enum MutationResult {
|
||||
@ -51,6 +55,9 @@ public extension DataService {
|
||||
case let .success(feature: feature):
|
||||
continuation.resume(returning: feature)
|
||||
case let .error(errorCode: errorCode):
|
||||
if errorCode == .ineligible {
|
||||
continuation.resume(throwing: IneligibleError.message(messageText: "You are not eligible for this feature."))
|
||||
}
|
||||
continuation.resume(throwing: BasicError.message(messageText: errorCode.rawValue))
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,5 @@ public struct AppleSignInButton: View {
|
||||
.frame(height: 54)
|
||||
.frame(maxWidth: 300)
|
||||
.cornerRadius(8)
|
||||
.signInWithAppleButtonStyle(.white)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user