diff --git a/CHMeetupApp/Sources/Common/Helpers/NotificationHelper/NotificationHelper.swift b/CHMeetupApp/Sources/Common/Helpers/NotificationHelper/NotificationHelper.swift index 2369c5de..3651530a 100644 --- a/CHMeetupApp/Sources/Common/Helpers/NotificationHelper/NotificationHelper.swift +++ b/CHMeetupApp/Sources/Common/Helpers/NotificationHelper/NotificationHelper.swift @@ -12,7 +12,7 @@ class NotificationHelper { static func viewController(title: String? = nil, description: String? = nil, emoji: String? = nil, - completion: @escaping ActionCompletionBlock) -> NotificationViewController { + completion: @escaping ActionCompletionBlock = {}) -> NotificationViewController { let notification = Storyboards.Main.instantiateNotificationViewController() notification.titleText = title notification.descriptionText = description @@ -22,4 +22,5 @@ class NotificationHelper { return notification } + } diff --git a/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift b/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift index 436fdc4f..dd161b38 100644 --- a/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift +++ b/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift @@ -18,6 +18,7 @@ struct EventPlainObjectTranslation: PlainObjectTranslation { event.endDate = plainObject.endDate event.descriptionText = plainObject.description event.statusValue = plainObject.registrationStatus + event.isRegistrationOpen = plainObject.isRegistrationOpen for speakerURLs in plainObject.speakersPhotos { let containerEntity = StringContainerEntity() diff --git a/CHMeetupApp/Sources/Model/Entities/EventEntity.swift b/CHMeetupApp/Sources/Model/Entities/EventEntity.swift index be7d9639..bed376b0 100644 --- a/CHMeetupApp/Sources/Model/Entities/EventEntity.swift +++ b/CHMeetupApp/Sources/Model/Entities/EventEntity.swift @@ -20,15 +20,6 @@ final class EventEntity: TemplatableObject, TemplateEntity { case loading case registrationClosed - var allowCanceling: Bool { - switch self { - case .waiting, .approved: - return true - case .canRegister, .rejected, .unknown, .loading, .registrationClosed: - return false - } - } - var allowRegister: Bool { switch self { case .canRegister: @@ -58,6 +49,15 @@ final class EventEntity: TemplatableObject, TemplateEntity { } } + var allowCanceling: Bool { + switch status { + case .waiting, .approved: + return isRegistrationOpen + case .canRegister, .rejected, .unknown, .loading, .registrationClosed: + return false + } + } + dynamic var id: Int = 0 dynamic var title: String = "" @@ -80,6 +80,7 @@ final class EventEntity: TemplatableObject, TemplateEntity { } } + dynamic var isRegistrationOpen: Bool = false dynamic var place: PlaceEntity? var importingState: ImportingStateEntity { @@ -153,6 +154,7 @@ extension EventEntity { entity.statusValue = EventEntity.EventRegistrationStatus.unknown.rawValue entity.speeches.append(SpeechEntity.templateEntity) entity.isTemplate = true + entity.isRegistrationOpen = true return entity } } diff --git a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift index 60449680..5489b778 100644 --- a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift +++ b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift @@ -39,6 +39,7 @@ extension EventPlainObject: PlainObjectType { let placeJson = json["place"] as? JSONDictionary, let speakersJson = json["speakers_photos"] as? [String], let registrationStatus = json["status"] as? String, + let isRegistrationOpen = json["is_registration_open"] as? Bool, let place = PlacePlainObject(json: placeJson) else { return nil } @@ -50,6 +51,7 @@ extension EventPlainObject: PlainObjectType { self.startDate = Date(timeIntervalSince1970: startDate) self.endDate = Date(timeIntervalSince1970: endDate) self.registrationStatus = registrationStatus + self.isRegistrationOpen = isRegistrationOpen var photos: [URL] = [] speakersJson.forEach { photoUrl in diff --git a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift index fecf6f3c..a07be5e6 100644 --- a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift +++ b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift @@ -18,4 +18,5 @@ struct EventPlainObject { let endDate: Date let speakersPhotos: [URL] let registrationStatus: String + let isRegistrationOpen: Bool } diff --git a/CHMeetupApp/Sources/ViewControllers/Events/EventPreview/EventPreviewViewController.swift b/CHMeetupApp/Sources/ViewControllers/Events/EventPreview/EventPreviewViewController.swift index f6a1742a..9314ba67 100644 --- a/CHMeetupApp/Sources/ViewControllers/Events/EventPreview/EventPreviewViewController.swift +++ b/CHMeetupApp/Sources/ViewControllers/Events/EventPreview/EventPreviewViewController.swift @@ -75,7 +75,7 @@ class EventPreviewViewController: UIViewController { if event.status.allowRegister { state = .isRegistrationEnabled - } else if event.status.allowCanceling, event.isUpcomingEvent { + } else if event.allowCanceling { state = .canCanceling } @@ -105,11 +105,20 @@ class EventPreviewViewController: UIViewController { if success { self?.displayCollection.event?.status = .canRegister self?.showSuccessNotification() + } else { + self?.showFaildNotification() } self?.dismissProgressHUD() } } + func showFaildNotification() { + let notification = NotificationHelper.viewController(title: "Ошибка!".localized, + description: "Не удалось отменить заявку. Регистрация закрыта.".localized, + emoji: "😔") + self.present(viewController: notification) + } + func showSuccessNotification() { let notification = NotificationHelper.viewController(title: "Заявка отменена!".localized, // swiftlint:disable:next line_length