Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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: 1 addition & 1 deletion docs/PROJECT_DOCUMENTATION.md

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions docs/recent-features/v2.9277.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# v2.9277 — Builders: more ways into a company's page (2026-12-03)

Punch list #465, step 2, four of the ways in the card names. It stands on v2.9266, the company's page. Client only. Nothing owed on prod.

## What it does

- **The card of who pulled it** (`WhoPulledItSheet`) has a press under the name, **Everything they are working on**. It opens the company's page (`builderProfileHref`) and the card closes on the way. The card opens from a name on a skim card, in the ledger and on the sheet of a kept permit, so each of those is two presses from the page. A row with no `builder_key` draws no press.
- **The builder's sheet over Market** (`BuilderSheet`, the new `pageLink`) has the same press. Market opens the sheet from **Open builder** on the call list, from a city's count in the table and from a name under *Who holds the work*. The sheet draws no such press when it is open over the page itself.
- **The Overview's Identify box** has a second quiet press beside *What we want*: *See who is building*, which opens Builders (`OVERVIEW_DOORS.builders`). `OverviewStep.also` is a list now.
- **A customer's record, both ways.** On the customer's **Permits** tab, a name the city lists a permit under is a link to its page (`BidGcTiedNames`, the new `pageLinks`, which `BidGcPermits` sets when it is on its own page). Over a bid the names stay plain words, since a link would leave the window. On the company's page, *Us and them* names each customer a person tied the company to, and each is a link to that customer's Permits tab (`/customers/<id>?tab=permits`).

## Where it differs from the card

The card says a press on a name opens the page, in place of the sheet it opens today. Here the sheet still opens and the page is one press further.

- On the skim the card of who pulled it holds the two answers and the lookups for the one permit. A press that left the skim for the page would drop them mid-answer.
- On Market the sheet's kept facts read the call list's lookups again (v2.8732). The page is another view of the tab, so Market would not be there to read.

This is a call for the owner. The pick here is the sheet first.

## Left of step 2

- **The search.** A name typed in the app's search opens its page. It needs a read of the builders' names inside the search, which is its own piece.
- The calling deck's press belongs to step 3, with the call's screen.

## Tests

`funnelOverview.test.ts` (the Identify box's two presses), `ProspectsResearchTab.render.test.tsx` (one new case: the card's press, its address, and the card closing), `PermitMarket.render.test.tsx` (the sheet's press over Market), `PermitBuilders.render.test.tsx` (no press on the sheet over the page, and the page's link to a tied customer), `BidGcTiedNames.render.test.tsx` (new, two cases).

## To verify on the live site

Read only. On the skim, press the name beside **Who**, then **Everything they are working on**: the company's page opens. Press the browser's Back: the skim is there. On Market, press **Open builder**, then the same press. On Prospects → Overview, press *See who is building*: Builders opens. On a customer with a tied name, open the **Permits** tab and press the name: its page opens, and *Us and them* there links back.

Not seen in a browser.
2 changes: 1 addition & 1 deletion src/components/bids/BidGcPermits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function BidGcPermits({
)}
{view.elsewhere && <div style={muted}>{view.elsewhere}</div>}
{view.unreadable && <div style={muted}>{view.unreadable}</div>}
<BidGcTiedNames customerIds={customerIds} customerName={customerName} />
<BidGcTiedNames customerIds={customerIds} customerName={customerName} pageLinks={onItsOwnPage} />
</div>
)
}
62 changes: 62 additions & 0 deletions src/components/bids/BidGcTiedNames.render.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @vitest-environment jsdom
/**
* Render-smoke tests for the names tied to a GC (punch list #307, PR 7), and for the way into a
* company's page from a customer's record (punch list #465, step 2): on the customer's own page a
* name the city lists a permit under is a link to its page on Builders. Over a bid it is plain
* words, since a link would leave the window. Every name here is made up.
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { screen, waitFor, within } from '@testing-library/react'
import type { SitePermit } from '../../lib/research/permitPublic'

const { siteIo, io } = vi.hoisted(() => ({
siteIo: { loadNameAnswers: vi.fn(), onNameAnswered: vi.fn(), recordNameAnswer: vi.fn() },
io: { loadPermitsOfBuilder: vi.fn(), loadResearchers: vi.fn() },
}))

vi.mock('../../lib/supabase', async () => {
const { makeSupabaseStub } = await import('../../test/renderSmokeMocks')
return { supabase: makeSupabaseStub() }
})
vi.mock('../../lib/research/bidSiteIo', () => siteIo)
vi.mock('../../lib/research/permitResearchIo', () => io)
vi.mock('../../hooks/usePermitRecordsStart', () => ({ usePermitRecordsStart: () => null }))
vi.mock('./FindNamesSheet', () => ({ FindNamesSheet: () => <div data-testid="find-names" /> }))

import { installDomShims, renderWithProviders } from '../../test/renderSmokeMocks'
import { BidGcTiedNames } from './BidGcTiedNames'

installDomShims()

const permit = (id: string): SitePermit => ({ id, permit_number: `COM-${id}`, permit_type: 'Commercial Building Permit', kind: 'building', stage: 'issued', work_type: 'New commercial', submitted_on: '2026-10-01', issued_on: '2026-10-20', contact: 'Hartwell Interiors', address: '5 FAR RD', declared_value: 100000 })

beforeEach(() => {
for (const fn of [...Object.values(siteIo), ...Object.values(io)]) fn.mockReset()
siteIo.onNameAnswered.mockReturnValue(() => {})
io.loadResearchers.mockResolvedValue([{ id: 'u2', name: 'Eve' }])
// Someone tied Hartwell Interiors to the customer, on every permit.
siteIo.loadNameAnswers.mockResolvedValue({ rows: [{ id: 'a1', builder_key: 'hartwellinteriors', customer_id: 'c1', answer: 'works_for', scope: 'all', permit_id: null, name: 'Hartwell Interiors', answered_by: 'u2', answered_at: '2026-11-20T15:00:00Z' }], me: 'u1' })
// The city lists a permit under the tied name and none under the customer's own.
io.loadPermitsOfBuilder.mockImplementation(async (city: string, key: string) => (city === 'Austin' && key === 'hartwellinteriors' ? [permit('1')] : []))
})

const rows = async () => within(await screen.findByTestId('bid-gc-tied-names'))

describe('BidGcTiedNames', () => {
it('on the customer’s own page, a name with a permit is a link to the company’s page on Builders', async () => {
renderWithProviders(<BidGcTiedNames customerIds={['c1']} customerName="Ridgeway Builders" pageLinks />)
const list = await rows()
await waitFor(() => expect(list.getByRole('link', { name: 'Hartwell Interiors' })).toBeTruthy())
expect(list.getByRole('link', { name: 'Hartwell Interiors' }).getAttribute('href')).toBe('/prospects?tab=permits&view=builders&builder=hartwellinteriors')
// The customer's own name has no permit on record: no page to open, so plain words.
expect(list.queryByRole('link', { name: 'Ridgeway Builders' })).toBeNull()
expect(list.getByText('Ridgeway Builders')).toBeTruthy()
})

it('over a bid, the names stay plain words', async () => {
renderWithProviders(<BidGcTiedNames customerIds={['c1']} customerName="Ridgeway Builders" />)
const list = await rows()
await waitFor(() => expect(list.getByText('Hartwell Interiors')).toBeTruthy())
expect(list.queryByRole('link')).toBeNull()
})
})
13 changes: 12 additions & 1 deletion src/components/bids/BidGcTiedNames.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useState, type CSSProperties } from 'react'
import { Link } from 'react-router-dom'
import { formatErrorMessage } from '../../utils/errorHandling'
import { todayYmdInAppTz } from '../../utils/dateUtils'
import { usePermitRecordsStart } from '../../hooks/usePermitRecordsStart'
Expand All @@ -8,6 +9,7 @@ import { sitePermitLines as feedLines, type SitePermit } from '../../lib/researc
import { loadPermitsOfBuilder, loadResearchers } from '../../lib/research/permitResearchIo'
import { loadNameAnswers, onNameAnswered, recordNameAnswer } from '../../lib/research/bidSiteIo'
import { foldNameAnswers, listedOnWords, tiedNames, type TiedName } from '../../lib/research/nameAnswers'
import { builderProfileHref } from '../../lib/research/permitsLink'
import { FindNamesSheet } from './FindNamesSheet'

/**
Expand All @@ -26,11 +28,14 @@ export function BidGcTiedNames({
customerIds,
customerName,
findPress = true,
pageLinks = false,
}: {
customerIds: readonly string[]
customerName: string
/** The press that opens Find their names on permits. Off inside that sheet itself. */
findPress?: boolean
/** On the customer's own page a name with a permit is a link to the company's page on Builders. Off over a bid, where a link would leave the window. */
pageLinks?: boolean
}) {
const [finding, setFinding] = useState(false)
const [loaded, setLoaded] = useState<Loaded>({ state: 'loading' })
Expand Down Expand Up @@ -115,7 +120,13 @@ export function BidGcTiedNames({
return (
<div key={r.key} style={{ padding: '8px 0', borderBottom: '1px solid var(--border)', display: 'grid', gap: 3 }}>
<div style={{ display: 'flex', gap: 8, alignItems: 'baseline', flexWrap: 'wrap' }}>
<strong style={{ fontSize: '0.875rem' }}>{r.name}</strong>
{pageLinks && r.permits.length > 0 ? (
<Link to={builderProfileHref(r.key)} title="Opens the company’s page on Builders." style={{ fontSize: '0.875rem', fontWeight: 700, color: 'var(--text-link)' }}>
{r.name}
</Link>
) : (
<strong style={{ fontSize: '0.875rem' }}>{r.name}</strong>
)}
<span style={{ display: 'inline-block', borderRadius: 999, padding: '1px 8px', fontSize: '0.72rem', fontWeight: 600, background: r.tie === 'own' ? 'var(--bg-200)' : 'var(--bg-blue-tint)', color: r.tie === 'own' ? 'var(--text-700)' : 'var(--text-blue-700)' }}>{r.how}</span>
</div>
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', alignItems: 'baseline', fontSize: '0.8125rem', color: 'var(--text-700)' }}>
Expand Down
23 changes: 21 additions & 2 deletions src/components/prospects/PermitBuilderProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useMemo, useState, type CSSProperties } from 'react'
import { Fragment, useCallback, useEffect, useMemo, useState, type CSSProperties } from 'react'
import { Link } from 'react-router-dom'
import { useBuilderAskFor } from '../../hooks/useBuilderAskFor'
import { byWordWords } from '../../lib/research/builderAnswers'
import type { BuilderAnswersGround } from '../../lib/research/builderAnswersIo'
Expand Down Expand Up @@ -209,7 +210,25 @@ export function PermitBuilderProfile({
<ValueSentence text={ourBidsLine(row, todayYmd)} />
</div>
{byWord && <div style={muted}>{byWord}</div>}
{tied.length > 0 && !byWord && <div style={muted}>Tied to {tied.map((c) => c.name).join(', ')} by a person’s word.</div>}
{/* Each tied customer is a press to its record's Permits tab, which links back here (punch list #465, step 2). */}
{tied.length > 0 && (
<div style={muted} data-profile-tied="">
{byWord ? 'Their record with us: ' : 'Tied to '}
{tied.map((c, i) => (
<Fragment key={c.key}>
{i > 0 ? ', ' : ''}
{c.ids[0] ? (
<Link to={`/customers/${c.ids[0]}?tab=permits`} style={{ color: 'var(--text-link)' }}>
{c.name}
</Link>
) : (
c.name
)}
</Fragment>
))}
{byWord ? '.' : ' by a person’s word.'}
</div>
)}
<div>
<ValueSentence text={markLine(row)} />
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/components/prospects/PermitBuilders.render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ describe('Builders, Our bids', () => {
// No builder's permits in this city name a plumber, so the sheet says nothing of one.
expect(within(sheet).getByText('Our bids: 4 priced, 2 won, the last on Oct 14.')).toBeTruthy()
expect(within(sheet).getByText('1 of them is with Ridgeway Builders, tied to this name by a person’s word.')).toBeTruthy()
// The page behind the sheet links to the tied customer's record, its Permits tab (punch list #465, step 2).
const tied = document.querySelector('[data-profile-tied]') as HTMLElement
expect(tied.textContent).toBe('Their record with us: Ridgeway Builders.')
expect(within(tied).getByRole('link', { name: 'Ridgeway Builders' }).getAttribute('href')).toMatch(/^\/customers\/c[12]\?tab=permits$/)
})

it('says it on a phone card too', async () => {
Expand Down Expand Up @@ -553,6 +557,8 @@ describe('A company’s profile (punch list #465, step 2)', () => {
it('opens the builder’s sheet for the mark, and reads the jobs again once it is kept', async () => {
everyCity()
const sheet = await openSheet('Sable Creek Construction')
// The sheet is over the company's own page here, so it offers no press to it.
expect(within(sheet).queryByRole('link', { name: 'Everything they are working on' })).toBeNull()
fireEvent.click(within(sheet).getByRole('button', { name: 'Good' }))
fireEvent.change(within(sheet).getByLabelText('Why, in a line'), { target: { value: 'Pays on time.' } })
fireEvent.click(within(sheet).getByRole('button', { name: 'Mark as Good' }))
Expand Down
13 changes: 10 additions & 3 deletions src/components/prospects/PermitBuilders.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment, useCallback, useEffect, useMemo, useState, type CSSProperties } from 'react'
import { useSearchParams } from 'react-router-dom'
import { Link, useSearchParams } from 'react-router-dom'
import { EmptyState } from '../EmptyState'
import { emptyWords, emptyWordsWithPress } from '../../lib/emptyWords'
import { DEAD_PRESS_FILL, DEAD_PRESS_TEXT } from '../../lib/deadPress'
Expand Down Expand Up @@ -32,7 +32,7 @@ import { byWordWords, openLookAlikes, throughWords, withAnsweredBids } from '../
import type { BuilderAnswersGround } from '../../lib/research/builderAnswersIo'
import { BuilderNameTies } from './BuilderNameTies'
import { PermitLookAlikes } from './PermitLookAlikes'
import { permitsLinkWithBuilder, permitsLinkWithLooks, readPermitsLink } from '../../lib/research/permitsLink'
import { builderProfileHref, permitsLinkWithBuilder, permitsLinkWithLooks, readPermitsLink } from '../../lib/research/permitsLink'
import { loadBuildersOf, loadPermitsOfBuilder, markBuilder, pullPermitsBack, saveBuilder } from '../../lib/research/permitResearchIo'
import { BUILDER_OURS, BUILDER_OURS_WORDS, DEFAULT_BUILDER_SORT, ariaSortOf, barWidth, builderShares, buildersOfOurs, drawnWords, longestShare, oursCounts, pressSort, recordsStartWords, shareWords, sortBuilders, sortMark, type BuilderOurs, type BuilderShare, type BuilderSort, type BuilderSortBy } from '../../lib/research/builderShare'
import { Money } from '../Money'
Expand Down Expand Up @@ -474,7 +474,7 @@ export function PermitBuilders({ city, cities, authUserId, todayYmd, isMobile, o
* **Put back** kept the same way. Until that read lands the sheet shows the Google press alone, as it did, so
* it never says nobody looked before it knows.
*/
export function BuilderSheet({ row, city, permitCities, authUserId, todayYmd, reach, namesPlumbers, ground, onAnswered, onLookupChecked, onClose, onSaved }: { row: BuilderRow; city: string; /** The cities the name's permits are read in, when the list read more than one. The one city when left out. */ permitCities?: readonly string[]; authUserId: string; todayYmd: string; reach: RecordsReach; /** False where no builder's permits in the city name a plumber: the sheet says nothing of one. */ namesPlumbers: boolean; /** The answers on names. Null before they are read, and before the table is on the database: the section is not drawn. */ ground: BuilderAnswersGround | null; onAnswered: () => void; /** A press on a looked-up fact was kept: a list behind the sheet reads its lookups again. */ onLookupChecked?: () => void; onClose: () => void; onSaved: () => void }) {
export function BuilderSheet({ row, city, permitCities, authUserId, todayYmd, reach, namesPlumbers, ground, onAnswered, onLookupChecked, pageLink, onClose, onSaved }: { row: BuilderRow; city: string; /** The cities the name's permits are read in, when the list read more than one. The one city when left out. */ permitCities?: readonly string[]; authUserId: string; todayYmd: string; reach: RecordsReach; /** False where no builder's permits in the city name a plumber: the sheet says nothing of one. */ namesPlumbers: boolean; /** The answers on names. Null before they are read, and before the table is on the database: the section is not drawn. */ ground: BuilderAnswersGround | null; onAnswered: () => void; /** A press on a looked-up fact was kept: a list behind the sheet reads its lookups again. */ onLookupChecked?: () => void; /** True where the sheet opens over another view, as on Market: it offers the company's page. Left out on the page itself. */ pageLink?: boolean; onClose: () => void; onSaved: () => void }) {
const { showToast } = useToastContext()
const name = builderName(row)
const [mark, setMark] = useState<BuilderMarkValue | 'none'>(row.mark ?? 'none')
Expand Down Expand Up @@ -550,6 +550,13 @@ export function BuilderSheet({ row, city, permitCities, authUserId, todayYmd, re
<div style={muted}>
{builderCountWords(row, reachWords(reach, todayYmd))} · last filed {shortDay(row.last_permit_on)}
</div>
{pageLink && (
<div style={{ fontSize: '0.875rem', marginTop: 4 }}>
<Link to={builderProfileHref(row.key)} onClick={onClose} style={{ color: 'var(--text-link)' }}>
Everything they are working on
</Link>
</div>
)}
</div>
<span style={{ flex: '1 1 auto' }} />
<button type="button" aria-label="Close" onClick={onClose} disabled={saving} style={{ background: 'transparent', border: 0, color: 'var(--text-muted)', width: 36, height: 36, borderRadius: 8, fontSize: 20, lineHeight: 1, cursor: 'pointer' }}>
Expand Down
5 changes: 5 additions & 0 deletions src/components/prospects/PermitMarket.render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ describe('Market, the companies we bid', () => {
expect(research.loadPermitsOfBuilder).toHaveBeenCalledWith('Austin', 'harborfitouts', TODAY)
// Austin's permits name a plumber, so the sheet says which.
expect(within(sheet).getByText(/Plumber they use: Copperline Mechanical on 2\./)).toBeTruthy()
// Over Market the sheet offers the company's page, and closes on the way (punch list #465, step 2).
const page = within(sheet).getByRole('link', { name: 'Everything they are working on' })
expect(page.getAttribute('href')).toBe('/prospects?tab=permits&view=builders&builder=harborfitouts')
fireEvent.click(page)
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
})

it('a fact checked on the builder’s sheet reads the call list’s lookups again (v2.8732)', async () => {
Expand Down
Loading
Loading