|
| 1 | +import { cn } from '@sim/emcn' |
| 2 | +import { ArrowRight } from '@sim/emcn/icons' |
| 3 | +import type { CareerPosting } from '@/lib/ashby/jobs' |
| 4 | +import { ALL_FILTER_VALUE } from '@/app/(landing)/careers/search-params' |
| 5 | + |
| 6 | +export interface DepartmentGroup { |
| 7 | + department: string |
| 8 | + postings: CareerPosting[] |
| 9 | +} |
| 10 | + |
| 11 | +/** |
| 12 | + * Narrows postings to a selected Team and Location, treating {@link ALL_FILTER_VALUE} |
| 13 | + * as "any". Shared by the server-rendered fallback and the client board so a |
| 14 | + * deep-linked filter resolves to the exact same set on both sides. |
| 15 | + */ |
| 16 | +export function filterPostings( |
| 17 | + postings: CareerPosting[], |
| 18 | + team: string, |
| 19 | + location: string |
| 20 | +): CareerPosting[] { |
| 21 | + return postings.filter( |
| 22 | + (posting) => |
| 23 | + (team === ALL_FILTER_VALUE || posting.department === team) && |
| 24 | + (location === ALL_FILTER_VALUE || posting.location === location) |
| 25 | + ) |
| 26 | +} |
| 27 | + |
| 28 | +/** Whether either the Team or Location filter is narrowing the board. */ |
| 29 | +export function hasActiveFilters(team: string, location: string): boolean { |
| 30 | + return team !== ALL_FILTER_VALUE || location !== ALL_FILTER_VALUE |
| 31 | +} |
| 32 | + |
| 33 | +/** Empty-state copy: distinguishes a truly empty board from a filtered-to-zero view. */ |
| 34 | +const NO_OPEN_ROLES_MESSAGE = 'No open roles right now — check back soon.' |
| 35 | +const NO_MATCHING_ROLES_MESSAGE = |
| 36 | + 'No roles match these filters right now. Try clearing them, or check back soon.' |
| 37 | + |
| 38 | +/** |
| 39 | + * Buckets postings by department, preserving their incoming order (the fetcher |
| 40 | + * pre-sorts by department then title). Shared by the interactive board and its |
| 41 | + * static Suspense fallback so the two can never render a different grouping. |
| 42 | + */ |
| 43 | +export function groupByDepartment(postings: CareerPosting[]): DepartmentGroup[] { |
| 44 | + const byDepartment = new Map<string, CareerPosting[]>() |
| 45 | + for (const posting of postings) { |
| 46 | + const bucket = byDepartment.get(posting.department) |
| 47 | + if (bucket) bucket.push(posting) |
| 48 | + else byDepartment.set(posting.department, [posting]) |
| 49 | + } |
| 50 | + return Array.from(byDepartment, ([department, items]) => ({ department, postings: items })) |
| 51 | +} |
| 52 | + |
| 53 | +interface JobGroupsProps { |
| 54 | + groups: DepartmentGroup[] |
| 55 | + /** |
| 56 | + * Whether a Team/Location filter is active. Selects the empty-state copy so an |
| 57 | + * unfiltered empty board ("no open roles") never reads as a filtered miss ("no |
| 58 | + * matches") — and the server fallback and client board always agree. |
| 59 | + */ |
| 60 | + filtersActive?: boolean |
| 61 | +} |
| 62 | + |
| 63 | +/** |
| 64 | + * The presentational open-roles list: one labeled section per department, each a |
| 65 | + * list of {@link JobRow}s. Server-safe (no client hooks) so it renders both as |
| 66 | + * the static Suspense fallback and inside the client {@link JobBoard}. |
| 67 | + */ |
| 68 | +export function JobGroups({ groups, filtersActive = false }: JobGroupsProps) { |
| 69 | + if (groups.length === 0) { |
| 70 | + return ( |
| 71 | + <p className='py-10 text-[var(--text-muted)] text-base'> |
| 72 | + {filtersActive ? NO_MATCHING_ROLES_MESSAGE : NO_OPEN_ROLES_MESSAGE} |
| 73 | + </p> |
| 74 | + ) |
| 75 | + } |
| 76 | + |
| 77 | + return ( |
| 78 | + <div className='flex flex-col gap-12'> |
| 79 | + {groups.map((group) => ( |
| 80 | + <section |
| 81 | + key={group.department} |
| 82 | + aria-label={`${group.department} roles`} |
| 83 | + className='flex flex-col' |
| 84 | + > |
| 85 | + <h3 className='pb-2 font-medium text-[var(--text-muted)] text-sm'>{group.department}</h3> |
| 86 | + <ul className='flex flex-col'> |
| 87 | + {group.postings.map((posting) => ( |
| 88 | + <li key={posting.id}> |
| 89 | + <JobRow posting={posting} /> |
| 90 | + </li> |
| 91 | + ))} |
| 92 | + </ul> |
| 93 | + </section> |
| 94 | + ))} |
| 95 | + </div> |
| 96 | + ) |
| 97 | +} |
| 98 | + |
| 99 | +interface JobRowProps { |
| 100 | + posting: CareerPosting |
| 101 | +} |
| 102 | + |
| 103 | +/** |
| 104 | + * A single role row: title over a metadata line, with an "Apply" affordance that |
| 105 | + * links out to the posting on Ashby. The whole row is the link target; hovering |
| 106 | + * tints the row and advances the arrow. The metadata values are de-duplicated |
| 107 | + * because a remote posting normalizes both `location` and `workplaceType` to |
| 108 | + * "Remote", which would otherwise render "Remote · Remote" and collide as keys. |
| 109 | + */ |
| 110 | +function JobRow({ posting }: JobRowProps) { |
| 111 | + const meta = Array.from( |
| 112 | + new Set( |
| 113 | + [ |
| 114 | + posting.location, |
| 115 | + posting.employmentType, |
| 116 | + posting.workplaceType, |
| 117 | + posting.compensationSummary, |
| 118 | + ].filter((value): value is string => Boolean(value)) |
| 119 | + ) |
| 120 | + ) |
| 121 | + |
| 122 | + return ( |
| 123 | + <a |
| 124 | + href={posting.jobUrl} |
| 125 | + target='_blank' |
| 126 | + rel='noopener noreferrer' |
| 127 | + className={cn( |
| 128 | + 'group flex items-center justify-between gap-6 border-[var(--border)] border-t py-5', |
| 129 | + 'transition-colors hover:bg-[var(--surface-hover)]' |
| 130 | + )} |
| 131 | + > |
| 132 | + <div className='flex min-w-0 flex-col gap-1.5'> |
| 133 | + <h4 className='truncate font-medium text-[var(--text-primary)] text-base'> |
| 134 | + {posting.title} |
| 135 | + </h4> |
| 136 | + <div className='flex flex-wrap items-center gap-x-2 gap-y-1 text-[var(--text-muted)] text-sm'> |
| 137 | + {meta.map((item, index) => ( |
| 138 | + <span key={item} className='flex items-center gap-2'> |
| 139 | + {index > 0 && ( |
| 140 | + <span aria-hidden className='text-[var(--text-muted)]'> |
| 141 | + · |
| 142 | + </span> |
| 143 | + )} |
| 144 | + {item} |
| 145 | + </span> |
| 146 | + ))} |
| 147 | + </div> |
| 148 | + </div> |
| 149 | + |
| 150 | + <span className='flex shrink-0 items-center gap-1.5 font-medium text-[var(--text-body)] text-sm'> |
| 151 | + Apply |
| 152 | + <ArrowRight className='size-[14px] text-[var(--text-icon)] transition-transform group-hover:translate-x-0.5' /> |
| 153 | + </span> |
| 154 | + </a> |
| 155 | + ) |
| 156 | +} |
0 commit comments