Branchwell

Jobley / app · jobley.ai / Apps / Mac / PeopleViews.swift

1import SwiftUI
2import JobleyKit
3import JobleyUI
4
5/// Candidates: per job or "any job", oldest first. People mark them reviewed or declined and make
6/// introductions themselves. There is no score, rank or match anywhere.
7struct CandidateList: View {
8 @ObservedObject var desk: DeskModel
9 @ObservedObject var model: CandidatesModel
10 let jobs: [Job]
11
12 var body: some View {
13 VStack(spacing: 0) {
14 HStack {
15 Picker("Who", selection: $model.scope) {
16 Text("Everyone").tag(CandidatesModel.Scope.everyone)
17 Text("Any job (asked about a kind of job)").tag(CandidatesModel.Scope.anyJob)
18 if !jobs.isEmpty { Divider() }
19 ForEach(jobs) { Text("\($0.title) · \($0.company)").tag(CandidatesModel.Scope.job($0.id)) }
20 }
21 Picker("Status", selection: $model.status) {
22 Text("Any status").tag("")
23 ForEach(["new", "reviewed", "introduced", "declined", "withdrawn"], id: \.self) { Text($0.capitalized).tag($0) }
24 }
25 .frame(width: 150)
26 }
27 .labelsHidden()
28 .padding(10)
29 if model.candidates.isEmpty {
30 StateMessage("No one here yet", detail: "When someone asks to be put forward they appear here, oldest first.", systemImage: "person.2")
31 } else {
32 List(model.candidates, selection: $desk.selectedCandidateID) { person in
33 VStack(alignment: .leading, spacing: 4) {
34 HStack {
35 Text(person.name).font(.headline)
36 Spacer()
37 StatusPill(person.status)
38 }
39 Text(person.headline).font(.subheadline).foregroundStyle(Theme.ink2)
40 Text(person.jobID.flatMap { id in jobs.first { $0.id == id }?.title } ?? (person.jobID == nil ? "Any job" : "A job no longer on the board"))
41 .font(.caption).foregroundStyle(Theme.muted)
42 Text("Asked \(APIDate.short(person.createdAt))").font(.caption2).foregroundStyle(Theme.muted)
43 }
44 .padding(.vertical, 4)
45 .tag(person.id)
46 }
47 }
48 }
49 .navigationTitle("Candidates")
50 .navigationSubtitle("Oldest first")
51 .onChange(of: model.scope) { Task { await model.reload() } }
52 .onChange(of: model.status) { Task { await model.reload() } }
53 .onChange(of: desk.selectedCandidateID) { Task { await model.open(desk.selectedCandidateID) } }
54 .alert("Something went wrong", isPresented: Binding(get: { model.error != nil }, set: { if !$0 { model.error = nil } })) {
55 Button("OK") { model.error = nil }
56 } message: { Text(model.error ?? "") }
57 }
58}
59
60struct CandidateDetailView: View {
61 @ObservedObject var model: CandidatesModel
62 let detail: CandidateDetail
63 let jobs: [Job]
64 @ObservedObject var curator: CuratorModel
65 @State private var introducing = false
66
67 var person: Candidate { detail.candidate }
68
69 var body: some View {
70 ScrollView {
71 VStack(alignment: .leading, spacing: 18) {
72 HStack {
73 StatusPill(person.status)
74 Text("Asked \(APIDate.full(person.createdAt))").font(.caption).foregroundStyle(Theme.muted)
75 }
76 Text(person.name).font(Theme.display(28))
77 Text(person.headline).font(.title3).foregroundStyle(Theme.ink2)
78 HStack(spacing: 10) {
79 Button { introducing = true } label: { Label("Introduce", systemImage: "envelope.badge.person.crop") }
80 .buttonStyle(PrimaryButtonStyle()).disabled(jobs.isEmpty)
81 Button("Mark reviewed") { Task { await model.setStatus(person, "reviewed") } }.buttonStyle(SecondaryButtonStyle())
82 Button("Decline") { Task { await model.setStatus(person, "declined") } }.buttonStyle(SecondaryButtonStyle())
83 }
84 GroupBox {
85 VStack(alignment: .leading, spacing: 6) {
86 Text(person.email).textSelection(.enabled)
87 if let location = person.location { Text(location).foregroundStyle(Theme.ink2) }
88 }.frame(maxWidth: .infinity, alignment: .leading)
89 } label: { Label("Private", systemImage: "lock").font(.caption.weight(.semibold)).foregroundStyle(Theme.muted) }
90 if let looking = person.lookingFor { section("Looking for", looking) }
91 if let about = person.about { section("About their work", about) }
92 if !person.links.isEmpty || person.resumeURL != nil {
93 VStack(alignment: .leading, spacing: 6) {
94 Text("Links").font(Theme.display(18))
95 ForEach(person.links, id: \.self) { link in if let url = URL(string: link) { Link(link, destination: url) } }
96 if let resume = person.resumeURL, let url = URL(string: resume) { Link("Resume", destination: url) }
97 }
98 }
99 if !detail.introductions.isEmpty {
100 VStack(alignment: .leading, spacing: 6) {
101 Text("Introductions").font(Theme.display(18))
102 ForEach(detail.introductions) { intro in
103 Text("\(jobs.first { $0.id == intro.jobID }?.title ?? intro.jobID) · by \(intro.introducedBy) · \(APIDate.short(intro.createdAt))")
104 .font(.callout)
105 }
106 }
107 }
108 }
109 .padding(28)
110 .frame(maxWidth: 760, alignment: .leading)
111 .frame(maxWidth: .infinity, alignment: .leading)
112 }
113 .background(Theme.background)
114 .sheet(isPresented: $introducing) { IntroduceSheet(model: model, person: person, jobs: jobs, curator: curator) }
115 }
116
117 func section(_ title: String, _ text: String) -> some View {
118 VStack(alignment: .leading, spacing: 6) {
119 Text(title).font(Theme.display(18))
120 Text(text).textSelection(.enabled).fixedSize(horizontal: false, vertical: true)
121 }
122 }
123}
124
125/// A person writes the introduction: pick the job, write the note, send the mail draft to both
126/// sides from Mail, then record that it happened.
127struct IntroduceSheet: View {
128 @ObservedObject var model: CandidatesModel
129 let person: Candidate
130 let jobs: [Job]
131 @ObservedObject var curator: CuratorModel
132 @State private var jobID = ""
133 @State private var note = ""
134 @State private var drafted = false
135 @Environment(\.dismiss) private var dismiss
136 @Environment(\.openURL) private var openURL
137
138 var body: some View {
139 VStack(alignment: .leading, spacing: 14) {
140 Text("Introduce \(person.name)").font(Theme.display(22))
141 Picker("Job", selection: $jobID) {
142 Text("Choose a job…").tag("")
143 ForEach(jobs) { Text("\($0.title) · \($0.company)").tag($0.id) }
144 }
145 Text("A few words for both of them").font(.callout).foregroundStyle(Theme.ink2)
146 TextEditor(text: $note).frame(minHeight: 120).scrollContentBackground(.hidden)
147 .padding(6).background(Theme.surface2, in: RoundedRectangle(cornerRadius: 8))
148 Text("First open the mail draft and send it from Mail. Then record the introduction here.")
149 .font(.caption).foregroundStyle(Theme.muted)
150 HStack {
151 Button("Cancel") { dismiss() }
152 Spacer()
153 Button("Open mail draft") {
154 Task {
155 // The poster's contact is on the admin copy of the job.
156 guard let item = try? await curator.api.reviewItem(jobID),
157 let mail = MailDraft.introduction(candidate: person, job: item.job, note: note) else { return }
158 openURL(mail); drafted = true
159 }
160 }
161 .disabled(jobID.isEmpty)
162 Button("Record introduction") {
163 Task { if await model.introduce(person, jobID: jobID, note: note) { dismiss() } }
164 }
165 .buttonStyle(PrimaryButtonStyle())
166 .disabled(jobID.isEmpty || !drafted)
167 }
168 }
169 .padding(22)
170 .frame(width: 520)
171 .onAppear { jobID = person.jobID.flatMap { id in jobs.contains { $0.id == id } ? id : nil } ?? "" }
172 }
173}
174
175/// Moderator applications and moderators (curator only).
176struct ModeratorsView: View {
177 @ObservedObject var model: ModeratorsModel
178 @State private var grantCandidates: Set<String> = []
179
180 var body: some View {
181 List {
182 Section("Applications") {
183 if model.applications.isEmpty { Text("No new applications.").foregroundStyle(.secondary) }
184 ForEach(model.applications) { app in
185 VStack(alignment: .leading, spacing: 6) {
186 HStack {
187 Text(app.name).font(.headline)
188 Text(app.email).foregroundStyle(.secondary).textSelection(.enabled)
189 Spacer()
190 Text(APIDate.short(app.createdAt)).font(.caption).foregroundStyle(.secondary)
191 }
192 if let hours = app.hoursPerWeek { Text("\(hours) hours a week\(app.timezone.map { " · \($0)" } ?? "")").font(.caption) }
193 Text(app.why).font(.callout).fixedSize(horizontal: false, vertical: true)
194 if let experience = app.experience { Text(experience).font(.caption).foregroundStyle(Theme.ink2) }
195 HStack {
196 Toggle("Can see candidates", isOn: Binding(get: { grantCandidates.contains(app.id) },
197 set: { if $0 { grantCandidates.insert(app.id) } else { grantCandidates.remove(app.id) } }))
198 Spacer()
199 Button("Decline") { Task { await model.decline(app) } }
200 Button("Approve") { Task { await model.approve(app, canSeeCandidates: grantCandidates.contains(app.id)) } }
201 .buttonStyle(.borderedProminent)
202 }
203 }
204 .padding(.vertical, 6)
205 }
206 }
207 Section("Moderators") {
208 if model.moderators.isEmpty { Text("No moderators yet.").foregroundStyle(.secondary) }
209 ForEach(model.moderators) { moderator in
210 HStack {
211 VStack(alignment: .leading) {
212 Text(moderator.name).font(.headline)
213 Text(moderator.email).font(.caption).foregroundStyle(.secondary)
214 Text(moderator.lastSeenAt.map { "Last seen \(APIDate.short($0))" } ?? "Not seen yet").font(.caption2).foregroundStyle(.secondary)
215 }
216 Spacer()
217 if moderator.active {
218 Toggle("Candidates", isOn: Binding(get: { moderator.canSeeCandidates }, set: { value in Task { await model.setAccess(moderator, value) } }))
219 Button("Setup link") { Task { await model.makeSetupLink(moderator) } }
220 .help("A new one-time link to add a passkey, for a moderator setting up or one who lost theirs")
221 Button("Revoke", role: .destructive) { Task { await model.revoke(moderator) } }
222 } else {
223 Text("Revoked").foregroundStyle(.secondary)
224 }
225 }
226 }
227 }
228 }
229 .navigationTitle("Moderators")
230 .task { await model.reload() }
231 .sheet(item: $model.newSetupLink) { made in
232 VStack(alignment: .leading, spacing: 14) {
233 Text("A passkey setup link for \(made.name)").font(Theme.display(22))
234 Text("Send it to them yourself. They open Jobley, choose Add a passkey and paste it. It works once, until \(APIDate.full(made.link.expiresAt)), and we show it only now.")
235 .foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)
236 Text(made.link.url).font(Theme.mono(12)).textSelection(.enabled).padding(10)
237 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: 8))
238 HStack {
239 Button("Copy") { Clipboard.copy(made.link.url) }
240 Spacer()
241 Button("Done") { model.newSetupLink = nil }.buttonStyle(PrimaryButtonStyle())
242 }
243 }
244 .padding(22).frame(width: 480)
245 }
246 }
247}