Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enrollmentDate, tweak example app UI, fix typos #12

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MyDataHelpsKit/Model/ParticipantInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public struct ParticipantInfo: Decodable {
public let demographics: ParticipantDemographics
/// Key/value pairs representing project-specific custom fields.
public let customFields: [String: String]
/// Date when the participant completed enrollment.
public let enrollmentDate: Date?
}

/// Participant's gender.
Expand Down
9 changes: 2 additions & 7 deletions example/MyDataHelpsKit-Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import SwiftUI
import MyDataHelpsKit

struct ContentView: View {
@EnvironmentObject var sessionModel: SessionModel
Expand All @@ -15,19 +14,15 @@ struct ContentView: View {
NavigationView {
if let session = sessionModel.session {
RootMenuView(participant: .init(session: session))
.navigationTitle(title)
.navigationTitle("Example App")
.navigationBarItems(trailing: Button("Log Out", action: logOut))
} else {
TokenView()
.navigationTitle(title)
.navigationTitle("Example App")
}
}
}

var title: String {
"MyDataHelpsKit v\(MyDataHelpsClient.SDKVersion)"
}

private func logOut() {
sessionModel.logOut()
}
Expand Down
17 changes: 15 additions & 2 deletions example/MyDataHelpsKit-Example/Session/ParticipantInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct ParticipantInfoViewModel {
let name: String
let email: String?
let phone: String?
let enrollmentDate: Date?
}

extension ParticipantInfoViewModel {
Expand All @@ -21,12 +22,20 @@ extension ParticipantInfoViewModel {
self.name = tokens.compactMap { $0 }.joined(separator: " ")
self.email = info.demographics.email
self.phone = info.demographics.mobilePhone
self.enrollmentDate = info.enrollmentDate
}
}

struct ParticipantInfoView: View {
let model: ParticipantInfoViewModel

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

var body: some View {
VStack(alignment: .leading) {
Text(model.name)
Expand All @@ -37,6 +46,9 @@ struct ParticipantInfoView: View {
if let phone = model.phone {
Text(phone)
}
if let enrollmentDate = model.enrollmentDate {
Text("Enrolled \(Self.dateFormatter.string(from: enrollmentDate))")
}
}
.font(.caption)
}
Expand All @@ -46,8 +58,9 @@ struct ParticipantInfoView_Previews: PreviewProvider {
static var previews: some View {
ParticipantInfoView(
model: .init(
name: "Firstname Lastname",
name: "FirstName LastName",
email: nil,
phone: "555-555-1212"))
phone: "555-555-1212",
enrollmentDate: Date().addingTimeInterval(-86400)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension ParticipantSession: ParticipantSessionType {

class ParticipantSessionPreview: ParticipantSessionType {
func getParticipantInfoViewModel(completion: @escaping (Result<ParticipantInfoViewModel, MyDataHelpsError>) -> Void) {
completion(.success(.init(name: "name", email: "email", phone: "phone")))
completion(.success(.init(name: "name", email: "email", phone: "phone", enrollmentDate: Date())))
}

func queryDeviceData(_ query: DeviceDataQuery, completion: @escaping (Result<DeviceDataResultPage, MyDataHelpsError>) -> Void) {
Expand Down
15 changes: 11 additions & 4 deletions example/MyDataHelpsKit-Example/Session/TokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
//

import SwiftUI
import MyDataHelpsKit

struct TokenView: View {
@EnvironmentObject var sessionModel: SessionModel

var body: some View {
VStack {
Text("To get started with this example app, you need a participant access token. Paste the participant access token below to initialize the app with a ParticipantSession and access views that demonstracte the functionality provided by MyDataHelpsKit.\n\nSee MyDataHelpsKit documentaion for more information.")
VStack(alignment: .leading) {
Text("MyDataHelpsKit v\(MyDataHelpsClient.SDKVersion)")
.font(.headline)
.padding(.bottom)
Text("To get started with this example app, you need a participant access token. Paste the participant access token below to initialize the app with a ParticipantSession and access views that demonstrate the functionality provided by MyDataHelpsKit.\n\nSee MyDataHelpsKit documentation for more information.")
.font(.subheadline)
Spacer()
Text("Participant access token:")
Expand All @@ -33,7 +37,10 @@ struct TokenView: View {

struct TokenView_Previews: PreviewProvider {
static var previews: some View {
TokenView()
.environmentObject(SessionModel())
NavigationView {
TokenView()
.navigationTitle("Example App")
.environmentObject(SessionModel())
}
}
}