Some clean up on new user creation

This commit is contained in:
Jackson Harper
2024-05-10 19:33:38 +08:00
parent 082025e266
commit 2766216ca8
11 changed files with 24 additions and 37 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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(

View File

@ -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)

View File

@ -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)

View File

@ -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 }
}
}

View File

@ -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 {

View File

@ -38237,6 +38237,8 @@ extension Enums {
enum OptInFeatureErrorCode: String, CaseIterable, Codable {
case badRequest = "BAD_REQUEST"
case ineligible = "INELIGIBLE"
case notFound = "NOT_FOUND"
}
}

View File

@ -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))
}
}

View File

@ -21,6 +21,5 @@ public struct AppleSignInButton: View {
.frame(height: 54)
.frame(maxWidth: 300)
.cornerRadius(8)
.signInWithAppleButtonStyle(.white)
}
}