|
|
|
|
@ -30,6 +30,10 @@ struct CreateClubView: View { |
|
|
|
|
ProgressView() |
|
|
|
|
} else { |
|
|
|
|
ButtonValidateView { |
|
|
|
|
if club.acronym.isEmpty { |
|
|
|
|
club.acronym = club.name.canonicalVersion.replaceCharactersFromSet(characterSet: .whitespacesAndNewlines).acronym() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validationInProgress = true |
|
|
|
|
} |
|
|
|
|
.disabled(club.isValid == false) |
|
|
|
|
@ -45,27 +49,25 @@ struct CreateClubView: View { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let club = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode) |
|
|
|
|
club.creator = Store.main.userId |
|
|
|
|
let newClub = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode) |
|
|
|
|
|
|
|
|
|
//update existing club if rights ok / freshly created club with data input from user |
|
|
|
|
if club.hasBeenCreated(by: Store.main.userId) { |
|
|
|
|
club.update(fromClub: club) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: club) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
if newClub.hasBeenCreated(by: Store.main.userId) { |
|
|
|
|
newClub.update(fromClub: club) |
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: newClub) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//save into user |
|
|
|
|
if dataStore.user.clubs.contains(where: { $0 == club.id }) == false { |
|
|
|
|
dataStore.user.clubs.append(club.id) |
|
|
|
|
if dataStore.user.clubs.contains(where: { $0 == newClub.id }) == false { |
|
|
|
|
dataStore.user.clubs.append(newClub.id) |
|
|
|
|
self.dataStore.saveUser() |
|
|
|
|
} |
|
|
|
|
dismiss() |
|
|
|
|
selection?(club) |
|
|
|
|
selection?(newClub) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|