signInWithApple

This commit is contained in:
2026-04-10 01:44:02 -05:00
parent ccaf0e179f
commit a8747a4df0
5 changed files with 250 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ final class ProfileViewModel {
var isDeleting = false
// Editable fields
var displayName = ""
var piFirstName = ""
var bldgCode = ""
var lab = ""
@@ -36,6 +37,13 @@ final class ProfileViewModel {
isSaving = true
defer { isSaving = false }
do {
let trimmedName = displayName.trimmingCharacters(in: .whitespaces)
if !trimmedName.isEmpty && trimmedName != AppState.shared.currentUser?.name {
let updatedUser = try await authClient.updateName(trimmedName)
await MainActor.run {
AppState.shared.currentUser = updatedUser
}
}
let body = UserProfileUpsertBody(
piFirstName: piFirstName,
bldgCode: bldgCode,
@@ -88,6 +96,11 @@ struct ProfileView: View {
Form {
if let user = appState.currentUser {
Section("Account") {
if viewModel.isEditing {
TextField("Name", text: $viewModel.displayName)
} else {
LabeledContent("Name", value: user.name ?? "")
}
LabeledContent("Email", value: user.email)
}
}
@@ -149,6 +162,7 @@ struct ProfileView: View {
.disabled(viewModel.isSaving)
} else {
Button("Edit") {
viewModel.displayName = appState.currentUser?.name ?? ""
viewModel.isEditing = true
}
}
@@ -157,6 +171,7 @@ struct ProfileView: View {
ToolbarItem(placement: .topBarLeading) {
Button("Cancel") {
viewModel.isEditing = false
viewModel.displayName = appState.currentUser?.name ?? ""
if let p = viewModel.profile {
viewModel.piFirstName = p.piFirstName
viewModel.bldgCode = p.bldgCode