Skip to content

Commit

Permalink
Merge pull request #21860 from wordpress-mobile/task/21432-my-domains…
Browse files Browse the repository at this point in the history
…-list

[Domain Management] All Domains List
  • Loading branch information
salimbraksa authored Nov 1, 2023
2 parents 901e6bf + 36dc4ba commit 60a98e5
Show file tree
Hide file tree
Showing 12 changed files with 585 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ extension DomainsService {

typealias AllDomainsEndpointResult = DomainsServiceRemote.AllDomainsEndpointResult
typealias AllDomainsEndpointParams = DomainsServiceRemote.AllDomainsEndpointParams
typealias AllDomainsListItem = DomainsServiceRemote.AllDomainsListItem
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Foundation

struct AllDomainsListItemViewModel {

let name: String
let description: String?
let status: Status?
let expiryDate: String?
}

// MARK: - Convenience Inits

extension AllDomainsListItemViewModel {

private static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .none
return formatter
}()

init(domain: Domain) {
self.init(
name: domain.domain,
description: Self.description(from: domain),
status: domain.status,
expiryDate: Self.expiryDate(from: domain)
)
}

private static func description(from domain: Domain) -> String? {
guard !domain.isDomainOnlySite else {
return nil
}
return !domain.blogName.isEmpty ? domain.blogName : domain.siteSlug
}

private static func expiryDate(from domain: Domain) -> String? {
guard let date = domain.expiryDate, domain.hasRegistration else {
return nil
}
let expired = date < Date()
let notice = expired ? Strings.expired : Strings.renews
let formatted = Self.dateFormatter.string(from: date)
return "\(notice) \(formatted)"
}
}

// MARK: - Types

extension AllDomainsListItemViewModel {

private enum Strings {

static let expired = NSLocalizedString(
"domain.management.card.expired.label",
value: "Expired",
comment: "The expired label of the domain card in My Domains screen."
)
static let renews = NSLocalizedString(
"domain.management.card.renews.label",
value: "Renews",
comment: "The renews label of the domain card in My Domains screen."
)
}

typealias Domain = DomainsService.AllDomainsListItem
typealias Status = Domain.Status
typealias StatusType = DomainsService.AllDomainsListItem.StatusType
}
Loading

0 comments on commit 60a98e5

Please sign in to comment.