Skip to content

Commit

Permalink
Merge pull request #324 from cocoaheadsru/task/cxORRnGH/cancel-button
Browse files Browse the repository at this point in the history
Task/cx or rn gh/cancel button
  • Loading branch information
smejl authored Dec 3, 2017
2 parents f41fd2d + f3e6df4 commit d24f35a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,4 +22,5 @@ class NotificationHelper {

return notification
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 11 additions & 9 deletions CHMeetupApp/Sources/Model/Entities/EventEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = ""
Expand All @@ -80,6 +80,7 @@ final class EventEntity: TemplatableObject, TemplateEntity {
}
}

dynamic var isRegistrationOpen: Bool = false
dynamic var place: PlaceEntity?

var importingState: ImportingStateEntity {
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ struct EventPlainObject {
let endDate: Date
let speakersPhotos: [URL]
let registrationStatus: String
let isRegistrationOpen: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d24f35a

Please sign in to comment.