1- import { useState } from 'react'
1+ import { type ReactNode , useState } from 'react'
22import {
33 Badge ,
44 Chip ,
@@ -9,19 +9,23 @@ import {
99 ChipModalField ,
1010 ChipModalFooter ,
1111 ChipModalHeader ,
12+ cn ,
13+ InfoCard ,
1214} from '@sim/emcn'
15+ import { ChevronDown } from '@sim/emcn/icons'
1316import type { DirectoryIssueField , PeopleSyncIssue } from '@/lib/api/contracts/people-sync'
1417import { usePeopleSyncIssues } from '@/hooks/queries/people-sync'
1518
1619const dateFormat = new Intl . DateTimeFormat ( undefined , { dateStyle : 'medium' } )
20+ const listFormat = new Intl . ListFormat ( undefined , { type : 'conjunction' } )
1721const FIELD_LABELS : Record < DirectoryIssueField , string > = {
1822 title : 'title' ,
1923 department : 'department' ,
2024 location : 'location' ,
2125 manager : 'manager' ,
2226}
23- const LIST_CLASS = 'flex flex-col gap-2 text-small '
24- const CARD_CLASS = 'flex flex-col gap-2 rounded-lg border border-[var(--border)] p-2 text-small '
27+ const LIST_CLASS = 'flex flex-col divide-y divide-[var(--border)] '
28+ const ROW_CLASS = 'flex flex-col gap-0.5 px-3 py-2 '
2529
2630interface SharedEmail {
2731 email : string
@@ -68,25 +72,56 @@ function sectionIssues(issues: readonly PeopleSyncIssue[]): IssueSections {
6872 }
6973}
7074
71- function accountLabel ( issue : PeopleSyncIssue ) {
72- return [ issue . name , issue . login , issue . title ] . filter ( Boolean ) . join ( ' · ' )
75+ /** The source sign-in name and title that tell two accounts with the same name apart. */
76+ function accountDetail ( issue : PeopleSyncIssue ) {
77+ return [ issue . login , issue . title ] . filter ( Boolean ) . join ( ' · ' )
7378}
7479
7580function emailProblem ( issue : PeopleSyncIssue , source : string ) {
76- return issue . email ? `Email is not valid: ${ issue . email } ` : `No email in ${ source } `
81+ return issue . email ? `Email not valid: ${ issue . email } ` : `No email in ${ source } `
82+ }
83+
84+ function capitalize ( text : string ) {
85+ return text . charAt ( 0 ) . toUpperCase ( ) + text . slice ( 1 )
7786}
7887
7988function changeDescription ( issues : readonly PeopleSyncIssue [ ] ) {
80- const fields = issues . flatMap ( ( issue ) => issue . fields . map ( ( field ) => FIELD_LABELS [ field ] ) )
89+ const cleared = issues . filter ( ( issue ) => issue . kind === 'field_cleared' )
90+ const fields = cleared . flatMap ( ( issue ) => issue . fields . map ( ( field ) => FIELD_LABELS [ field ] ) )
91+ const kept = cleared . some ( ( issue ) => issue . keptPrevious )
8192 return [
82- fields . length > 0 && `Not synced, too long or not text: ${ fields . join ( ', ' ) } ` ,
93+ fields . length > 0 &&
94+ `${ capitalize ( listFormat . format ( fields ) ) } ${
95+ kept ? 'kept from the last sync' : 'left empty'
96+ } : too long or not text`,
8397 issues . some ( ( issue ) => issue . kind === 'manager_cleared' ) &&
8498 'Manager removed to break a reporting loop' ,
8599 ]
86100 . filter ( Boolean )
87101 . join ( '. ' )
88102}
89103
104+ interface IssueRowProps {
105+ name : string
106+ detail ?: string
107+ reason ?: ReactNode
108+ badge ?: ReactNode
109+ }
110+
111+ /** One account: its name, what identifies it in the source, and what the sync did with it. */
112+ function IssueRow ( { name, detail, reason, badge } : IssueRowProps ) {
113+ return (
114+ < li className = { ROW_CLASS } >
115+ < div className = 'flex flex-wrap items-center gap-2' >
116+ < span className = 'break-words text-[var(--text-body)] text-small' > { name } </ span >
117+ { badge }
118+ </ div >
119+ { detail && < span className = 'break-all text-[var(--text-muted)] text-caption' > { detail } </ span > }
120+ { reason && < span className = 'text-[var(--text-secondary)] text-caption' > { reason } </ span > }
121+ </ li >
122+ )
123+ }
124+
90125interface DirectorySyncIssuesProps {
91126 organizationId : string
92127 sourceName : string
@@ -129,30 +164,33 @@ export function DirectorySyncIssues({
129164 { sections . review . length > 0 && (
130165 < ChipModalField type = 'custom' title = 'Needs review' >
131166 { ( ) => (
132- < div className = { LIST_CLASS } >
167+ < div className = 'flex flex-col gap-2' >
168+ < p className = 'text-[var(--text-secondary)] text-caption' >
169+ In { sourceName } , give each account its own email, or make the email the
170+ username of the account that should use it.
171+ </ p >
133172 { sections . review . map ( ( { email, accounts } ) => (
134- < section key = { email } className = { CARD_CLASS } aria-label = { email } >
135- < p className = 'break-all text-[var(--text-body)]' > { email } </ p >
136- < ul className = 'flex flex-col gap-1' >
137- { accounts . map ( ( account ) => (
138- < li
139- key = { account . externalId }
140- className = 'flex flex-wrap items-center gap-2'
141- >
142- < span className = 'break-words text-[var(--text-body)]' >
143- { accountLabel ( account ) }
144- </ span >
145- { account . keptPrevious && (
146- < Badge variant = 'gray' > Showing previous details</ Badge >
147- ) }
148- </ li >
149- ) ) }
150- </ ul >
151- < p className = 'text-[var(--text-muted)]' >
152- In { sourceName } , give each account its own email, or make this email the
153- username of the account that should use it.
154- </ p >
155- </ section >
173+ < InfoCard key = { email } >
174+ < section aria-label = { email } >
175+ < p className = 'break-all border-[var(--border)] border-b px-3 py-2 text-[var(--text-body)] text-small' >
176+ { email }
177+ </ p >
178+ < ul className = { LIST_CLASS } >
179+ { accounts . map ( ( account ) => (
180+ < IssueRow
181+ key = { account . externalId }
182+ name = { account . name }
183+ detail = { accountDetail ( account ) }
184+ badge = {
185+ account . keptPrevious && (
186+ < Badge variant = 'gray' > Showing previous details</ Badge >
187+ )
188+ }
189+ />
190+ ) ) }
191+ </ ul >
192+ </ section >
193+ </ InfoCard >
156194 ) ) }
157195 </ div >
158196 ) }
@@ -161,92 +199,103 @@ export function DirectorySyncIssues({
161199 { sections . resolved . length > 0 && (
162200 < ChipModalField type = 'custom' title = 'Resolved automatically' >
163201 { ( ) => (
164- < div className = { LIST_CLASS } >
165- < div >
166- < Chip
167- aria-expanded = { showResolved }
168- onClick = { ( ) => setShowResolved ( ( shown ) => ! shown ) }
169- >
170- { showResolved
171- ? 'Hide'
172- : `Show ${ sections . resolved . length . toLocaleString ( ) } shared ${
173- sections . resolved . length === 1 ? 'email' : 'emails'
174- } `}
175- </ Chip >
176- </ div >
202+ < InfoCard >
203+ < button
204+ type = 'button'
205+ aria-expanded = { showResolved }
206+ onClick = { ( ) => setShowResolved ( ( shown ) => ! shown ) }
207+ className = 'flex w-full items-center justify-between gap-2 px-3 py-2 text-left text-[var(--text-body)] text-small'
208+ >
209+ { `${ sections . resolved . length . toLocaleString ( ) } shared ${
210+ sections . resolved . length === 1 ? 'email' : 'emails'
211+ } `}
212+ < ChevronDown
213+ className = { cn (
214+ 'size-[14px] text-[var(--text-icon)] transition-transform' ,
215+ showResolved && 'rotate-180'
216+ ) }
217+ />
218+ </ button >
177219 { showResolved && (
178- < ul className = { LIST_CLASS } >
220+ < ul className = { cn ( LIST_CLASS , 'border-[var(--border)] border-t' ) } >
179221 { sections . resolved . map ( ( { email, accounts } ) => (
180- < li key = { email } className = 'flex flex-col gap-0.5' >
181- < span className = 'break-all text-[var(--text-body)]' > { email } </ span >
182- < span className = 'text-[var(--text-muted)]' >
183- { accounts [ 0 ] ?. chosenName
184- ? `Using ${ accounts [ 0 ] . chosenName } , whose username matches. `
185- : '' }
186- Left out: { accounts . map ( accountLabel ) . join ( '; ' ) }
187- </ span >
188- </ li >
222+ < IssueRow
223+ key = { email }
224+ name = { email }
225+ detail = {
226+ accounts [ 0 ] ?. chosenName
227+ ? `Using ${ accounts [ 0 ] . chosenName } , whose username matches`
228+ : undefined
229+ }
230+ reason = { `Left out: ${ accounts
231+ . map ( ( account ) => account . login ?? account . name )
232+ . join ( ', ' ) } `}
233+ />
189234 ) ) }
190235 </ ul >
191236 ) }
192- </ div >
237+ </ InfoCard >
193238 ) }
194239 </ ChipModalField >
195240 ) }
196241 { sections . kept . length > 0 && (
197242 < ChipModalField type = 'custom' title = 'Showing previous details' >
198243 { ( ) => (
199- < ul className = { LIST_CLASS } >
200- { sections . kept . map ( ( issue ) => (
201- < li key = { issue . externalId } className = 'flex flex-col gap-0.5' >
202- < span className = 'break-words text-[var(--text-body)]' >
203- { accountLabel ( issue ) }
204- </ span >
205- < span className = 'break-all text-[var(--text-muted)]' >
206- { emailProblem ( issue , sourceName ) } . Since{ ' ' }
207- < time dateTime = { issue . since } >
208- { dateFormat . format ( new Date ( issue . since ) ) }
209- </ time >
210- </ span >
211- </ li >
212- ) ) }
213- </ ul >
244+ < InfoCard >
245+ < ul className = { LIST_CLASS } >
246+ { sections . kept . map ( ( issue ) => (
247+ < IssueRow
248+ key = { issue . externalId }
249+ name = { issue . name }
250+ detail = { accountDetail ( issue ) }
251+ reason = {
252+ < >
253+ { emailProblem ( issue , sourceName ) } . Since{ ' ' }
254+ < time dateTime = { issue . since } >
255+ { dateFormat . format ( new Date ( issue . since ) ) }
256+ </ time >
257+ </ >
258+ }
259+ />
260+ ) ) }
261+ </ ul >
262+ </ InfoCard >
214263 ) }
215264 </ ChipModalField >
216265 ) }
217266 { sections . skipped . length > 0 && (
218267 < ChipModalField type = 'custom' title = 'Skipped' >
219268 { ( ) => (
220- < ul className = { LIST_CLASS } >
221- { sections . skipped . map ( ( issue ) => (
222- < li key = { issue . externalId } className = 'flex flex-col gap-0.5' >
223- < span className = 'break-words text-[var(--text-body)]' >
224- { accountLabel ( issue ) }
225- </ span >
226- < span className = 'break-all text-[var(--text-muted)]' >
227- { emailProblem ( issue , sourceName ) }
228- </ span >
229- </ li >
230- ) ) }
231- </ ul >
269+ < InfoCard >
270+ < ul className = { LIST_CLASS } >
271+ { sections . skipped . map ( ( issue ) => (
272+ < IssueRow
273+ key = { issue . externalId }
274+ name = { issue . name }
275+ detail = { accountDetail ( issue ) }
276+ reason = { emailProblem ( issue , sourceName ) }
277+ / >
278+ ) ) }
279+ </ ul >
280+ </ InfoCard >
232281 ) }
233282 </ ChipModalField >
234283 ) }
235284 { sections . changed . length > 0 && (
236285 < ChipModalField type = 'custom' title = 'Changed' >
237286 { ( ) => (
238- < ul className = { LIST_CLASS } >
239- { sections . changed . map ( ( issues ) => (
240- < li key = { issues [ 0 ] . externalId } className = 'flex flex-col gap-0.5' >
241- < span className = 'break-words text-[var(--text-body)]' >
242- { [ issues [ 0 ] . name , issues [ 0 ] . email ] . filter ( Boolean ) . join ( ' · ' ) }
243- </ span >
244- < span className = 'text-[var(--text-muted)]' >
245- { changeDescription ( issues ) }
246- </ span >
247- </ li >
248- ) ) }
249- </ ul >
287+ < InfoCard >
288+ < ul className = { LIST_CLASS } >
289+ { sections . changed . map ( ( issues ) => (
290+ < IssueRow
291+ key = { issues [ 0 ] . externalId }
292+ name = { issues [ 0 ] . name }
293+ detail = { issues [ 0 ] . email ?? undefined }
294+ reason = { changeDescription ( issues ) }
295+ / >
296+ ) ) }
297+ </ ul >
298+ </ InfoCard >
250299 ) }
251300 </ ChipModalField >
252301 ) }
0 commit comments