|
|
|
|
@ -311,21 +311,24 @@ struct UmpireView: View { |
|
|
|
|
NavigationStack { |
|
|
|
|
SelectablePlayerListView(allowSelection: 1, searchField: user.firstName + " " + user.lastName, playerSelectionAction: { players in |
|
|
|
|
if let player = players.first { |
|
|
|
|
user.licenceId = player.license?.computedLicense |
|
|
|
|
if user.clubsObjects().contains(where: { $0.code == player.clubCode }) == false { |
|
|
|
|
let userClub = Club.findOrCreate(name: player.clubName!, code: player.clubCode) |
|
|
|
|
if userClub.hasBeenCreated(by: StoreCenter.main.userId) { |
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: userClub) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
dataStore.clubs.addOrUpdate(instance: userClub) |
|
|
|
|
} |
|
|
|
|
user.setUserClub(userClub) |
|
|
|
|
} |
|
|
|
|
self._updateUserLicense(license: player.license?.computedLicense) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
.task { |
|
|
|
|
do { |
|
|
|
|
try await dataStore.clubs.loadDataFromServerIfAllowed() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.navigationDestination(for: UmpireScreen.self) { screen in |
|
|
|
|
switch screen { |
|
|
|
|
@ -336,6 +339,25 @@ struct UmpireView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _updateUserLicense(license: String?) { |
|
|
|
|
print("_updateUserLicense(license: ", license) |
|
|
|
|
guard let license else { return } |
|
|
|
|
|
|
|
|
|
let copyUser = CustomUser(username: "", email: "", firstName: "", lastName: "", phone: nil, country: nil, loserBracketMode: .automatic) |
|
|
|
|
copyUser.copy(from: dataStore.user) |
|
|
|
|
copyUser.licenceId = license |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try await self.dataStore.userStorage.tryPutBeforeUpdating(copyUser) |
|
|
|
|
print("_updateUserLicense OK") |
|
|
|
|
} catch { |
|
|
|
|
print(error) |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _confirmUmpireMail() { |
|
|
|
|
umpireCustomMailIsInvalid = false |
|
|
|
|
if umpireCustomMail.isEmpty { |
|
|
|
|
|