diff --git a/docs/CLOCK_SURFACES_ARCHITECTURE.md b/docs/CLOCK_SURFACES_ARCHITECTURE.md index 1e8fa18115..77db99c1f0 100644 --- a/docs/CLOCK_SURFACES_ARCHITECTURE.md +++ b/docs/CLOCK_SURFACES_ARCHITECTURE.md @@ -198,7 +198,7 @@ Because they are components, regions are gated by **state/props**, not an `activ ### B6 — Button row + My Time preview - **Location:** 1670–1852 (`loading` early return 1670–1676, `canClockIn` / `hasOpenSession` / `showMyTimeDayPreview` 1678–1681, `myTimePreviewButton` 1683–1717, `topRowContent` 1755–1841, wrapper 1843–1852). -- **Behavior:** open session → red `formatElapsed(totalSecondsToday) Clock Out` (hidden when `salaryUiActive`; "Checking…" while the tally gate loads) + **Break** (`BreakPress`, offered by `breakOffered` wherever Clock Out is; one press sends the clock out with no window and the row becomes `OnBreakRow` with **Back to work**, **Clock In…** and *Done for the day* until a session opens or the day turns; the rule is `lib/clock/clockBreak.ts`, the two presses `hooks/useClockBreak.ts`, the break in hand one `localStorage` entry by person; since v2.9203 the bar also tells **the break's door** what is true and hands it its three presses (`lib/clock/clockBreakDoor.ts`, `contexts/ClockBreakDoorContext.tsx`, inside the clock's bridge), so the Job Mode card, where this bar is mounted out of sight, draws Break and its *On a break* band itself (`jobModeBreakOffered` in `lib/jobMode/pressBar.ts`, `components/jobMode/JobModeOnBreak.tsx`); since v2.9217 *Done for the day* ends the break and then asks for the day's bids, **Your bids today**, when the day holds a bid and for no role when it holds none (`lib/clock/doneForTheDay.ts`, `components/clock/DoneForTheDayBidDay.tsx`, kept through `save_my_bid_day`)) + blue Update Focus; no session and salaried → only the My Time preview clock icon (it needs `onOpenMyTimeDayEditor`, which Dashboard withholds when `dashboardSelfIsSalary`, so there the row renders nothing); otherwise orange Clock In (`CLOCK_IN_ACCENT_UNDER_WORDS` under `CLOCK_IN_ACCENT_TEXT` — since v2.6186 the deep safety orange `#c75000` under white words in both themes, `lib/orangeUnderWords.ts`; v2.5981 had near-black words on `#ff6600` — as on Complete Clock In, the Job Mode card's and the press bar's orange press, `DAY_PRESS_TEXT`, and the strip's three orange headers) + B7's quick-time door + preview icon when `todaySessions` exist. Clock Out and Update Focus disable on any of `actionLoading || updateFocusLoading || clockOutSaving || clockOutTallyGateLoading`; Clock In on `!canClockIn || actionLoading`. `embedded` drops the wrapper's bottom margin. +- **Behavior:** open session → red `formatElapsed(totalSecondsToday) Clock Out` (hidden when `salaryUiActive`; "Checking…" while the tally gate loads) + **Break** (`BreakPress`, offered by `breakOffered` wherever Clock Out is; one press sends the clock out with no window and the row becomes `OnBreakRow` with **Back to work**, **Clock In…** and *Done for the day* until a session opens or the day turns; the rule is `lib/clock/clockBreak.ts`, the two presses `hooks/useClockBreak.ts`, the break in hand one `localStorage` entry by person; since v2.9203 the bar also tells **the break's door** what is true and hands it its three presses (`lib/clock/clockBreakDoor.ts`, `contexts/ClockBreakDoorContext.tsx`, inside the clock's bridge), so the Job Mode card, where this bar is mounted out of sight, draws Break and its *On a break* band itself (`jobModeBreakOffered` in `lib/jobMode/pressBar.ts`, `components/jobMode/JobModeOnBreak.tsx`); since v2.9217 *Done for the day* ends the break and then asks for the day's bids, **Your bids today**, when the day holds a bid and for no role when it holds none (`lib/clock/doneForTheDay.ts`, `components/clock/DoneForTheDayBidDay.tsx` over the window `components/clock/BidDayKeepWindow.tsx`, which the Job Mode header's **Bids · 3 ›** opens too, kept through `save_my_bid_day`)) + blue Update Focus; no session and salaried → only the My Time preview clock icon (it needs `onOpenMyTimeDayEditor`, which Dashboard withholds when `dashboardSelfIsSalary`, so there the row renders nothing); otherwise orange Clock In (`CLOCK_IN_ACCENT_UNDER_WORDS` under `CLOCK_IN_ACCENT_TEXT` — since v2.6186 the deep safety orange `#c75000` under white words in both themes, `lib/orangeUnderWords.ts`; v2.5981 had near-black words on `#ff6600` — as on Complete Clock In, the Job Mode card's and the press bar's orange press, `DAY_PRESS_TEXT`, and the strip's three orange headers) + B7's quick-time door + preview icon when `todaySessions` exist. Clock Out and Update Focus disable on any of `actionLoading || updateFocusLoading || clockOutSaving || clockOutTallyGateLoading`; Clock In on `!canClockIn || actionLoading`. `embedded` drops the wrapper's bottom margin. - **Tests:** none (no render smoke for the component). - **Extraction status:** stays with the parent; it is the component. diff --git a/docs/GLOSSARY.md b/docs/GLOSSARY.md index e2b74167d6..dab926f7ac 100644 --- a/docs/GLOSSARY.md +++ b/docs/GLOSSARY.md @@ -4533,6 +4533,10 @@ Since v2.9165 the Dashboard's My Time section has **Your bids today** for the pe It is closed until pressed and reads the day when it opens, it shows for the roles that work on bids (`worksOnBids`), and only on the person's own section. A salaried estimator, who has no clock out, keeps the day's list there. Since v2.9194 the My Time day editor draws a day's kept list above its timeline (`my-time-day-editor/MyTimeDayBids.tsx`): the same sentence and labels, with no **Open the bid** (`noBidDoor`), and no read on a person's own day unless their role works on bids. +Since v2.9282 the Job Mode card's header counts the bids of the day so far while the clock is on the office job or on no job: **Bids · 3 ›** where the job's name was and *On JP000 · Office* under it (`lib/jobMode/jobModeBids.ts`, `hooks/useJobModeBids.ts`, `jobMode/JobModeBidsPress.tsx`, the person's answers of 2026-12-03). +That count is the clock out's own, the bids the person changed with a kept list winning, read from the person's own day for the roles that work on bids, and a day with no bid yet keeps the job's header. +A press on it opens **Your bids today** in a window, read when it opens, with **Keep my list · N bids** (`clock/BidDayKeepWindow.tsx`, the window *Done for the day* opens too). +An empty list names a typed note only on the clock out's sheet, and everywhere else it names the next press that is there (`bidDayEmptyWords`). **Database**: `user_bid_activity`, `bid_day_entries`, `bump_user_bid_activity`, `get_my_bid_day`, `save_my_bid_day` · kernels `lib/bids/bidInFront.ts`, `lib/clock/bidDay.ts`, `lib/clock/bidDayLabels.ts` · hooks `useBidActivityBeat`, `useClockOutBidDay`, `useSessionsBidDay` · guides `/help/clock-out-with-the-bids-of-the-day`, `/help/approve-my-teams-hours` @@ -4545,6 +4549,7 @@ A quick add and a rejected session are left out of the day, and a session still On People → Hours the line sits beside the later session, measured in the active, pending and approved lists together, and a list sorted by length draws none. Where the line does not sit between its two sessions, it leads with the person's name. In the My Time day editor the strip between two groups of sessions reads the same words. +My time's week list draws no gap line, since it is one row a job for the week and holds no two sessions side by side (the person, 2026-12-03). **Code**: kernel `lib/clock/sessionGaps.ts` · `components/clock-sessions/ClockSessionsTable.tsx` (`gapsAmong`) · `components/my-time-day-editor/MyTimeDayTimelineBody.tsx` diff --git a/docs/recent-features/v2.9282.md b/docs/recent-features/v2.9282.md new file mode 100644 index 0000000000..ee16558423 --- /dev/null +++ b/docs/recent-features/v2.9282.md @@ -0,0 +1,57 @@ +# v2.9282 — Job Mode: the card counts the bids of your day, and a press opens the list (2026-12-03) + +Punch list #469, the Job Mode step. Client only. No migration, no function change, nothing owed on prod. It reads `get_my_bid_day` and writes through `save_my_bid_day`, both on prod since punch list #445. + +## What was asked + +The owner, 2026-12-02: a day spent on bids is to look like the bids worked on, not like the office job the clock was on. People → Hours reads a day's *kept* list for that. The card named the Job Mode card as the next place and drew nothing for it. + +## The calls, and the person's answers (2026-12-03) + +The *kept* rule would almost never change the Job Mode header: a list is kept at clock out, and after a clock out the card shows no session. So three calls were put, each with a pick. + +- **What the header shows on the office job:** the bids of the day so far, from the person's own list, kept or not. The pick. +- **Which bids count:** the bids the person changed, with a kept list winning. The pick. +- **A press on it:** it opens the list in a window with **Keep my list**. The pick put was no press, and the person chose the press. + +## What it does + +- While the clock is on the office job, or on no job, and the person's role works on bids, the header reads **Bids · 3 ›** where the job's name was. The line under it reads *On JP000 · Office*, or *Clocked in with no job*. +- With no bid yet, on a job in the field, on a bid, or for a role that does not work on bids, the header is as it was. +- A press opens **Your bids today** over the card: the clock out's own list and strip, **Keep my list · N bids** and **Close**. It reads the day when it opens. It says *Reading your day…* while it reads, and says so when the day cannot be read. +- After the window closes the card reads its count again. + +## How + +- New kernel `src/lib/jobMode/jobModeBids.ts`: `jobModeBidsNeedsOffice`, `jobModeBidsAsked`, `bidsSoFar` (the clock out's own `keptCount`), `jobModeBidsHeader` (over `bidDayJobWords`) and the window's words. +- New hook `src/hooks/useJobModeBids.ts`: the office job's id once, then the person's own day. A read that fails leaves the job's header. +- New `src/components/jobMode/JobModeBidsPress.tsx`: the press, and the window over `useClockOutBidDay`. +- New `src/components/clock/BidDayKeepWindow.tsx`: the window *Done for the day* drew, lifted out so both doors use it, each with its own words. `DoneForTheDayBidDay.tsx` draws it now. +- `DashboardJobModeCard.tsx`: the hook, the header's first branch, and the window held by the card so a reload that redraws the header leaves it open. + +## Chosen in the build, to be read by the owner + +- **The count is as fresh as the card's last read.** It is read when the card draws, after a clock press and after the window closes. It does not tick while the card sits open. +- **The line *Not on today's schedule* stays** under the count where it stood under the office job. +- **A job whose papers are still owed keeps its masked header.** +- **The window takes the cursor when it opens and gives it back when it closes.** That holds for *Done for the day*'s window too, whose cursor the walker found outside it. Its two presses are 44 px tall now, up from 40. + +## A words mend that rode with it + +My time's **Your bids today** drew the clock out's empty words on a day with no bid: *Add the bids you worked on, or say what you did below.* Nothing is below on My time. The words are `bidDayEmptyWords` in `src/lib/clock/bidDay.ts` now. The clock out's sheet passes `noteBelow` and reads as it did. My time and the two windows name the next press that is there: tick an opened bid, add from the board, or *A bid you change on the Bids page today shows here.* + +## Tests + +- `jobModeBids.test.ts` (12 cases): when the day is read, what is counted, a kept list winning, the header's words. +- `DashboardJobModeCard.bids.render.test.tsx` (6 cases): the header on the office job and on no job, the window with its keep and its reread, the window's reading and not-read words, the job's own header on a day with no bid and on a failed read, and no read on a field job or for a role that does not work on bids. +- `bidDay.test.ts`: `bidDayEmptyWords`. +- `DoneForTheDayBidDay.render.test.tsx` passes unchanged over the shared window. +- Not seen in a browser: this thread signs in to nothing, and View as keeps no bid trace. + +## Words + +The guides `clock-out-with-the-bids-of-the-day` and `job-mode-clocking`. The glossary's *Bids of the day* and *Gap line*. The clock map. The cards `to-dos/bids-on-my-time/README.md` (the six answers and the looks) and `to-dos/clock-break/README.md` (the gap line on the week's list is closed, not drawn: the person's answer to call W3). + +## The look owed + +On the card under *The looks owed*. It needs a real sign-in as a ZZ Test person who works on bids, since View as keeps no bid trace: clock in on the office job with Job Mode on, change one thing on a ZZ Test bid, and the header reads *Bids · 1 ›*. The press opens the list, **Keep my list · 1 bid** keeps it, and **Close** gives the cursor back. diff --git a/src/components/ClockInOutButton.tsx b/src/components/ClockInOutButton.tsx index e00c9685f5..209033e69e 100644 --- a/src/components/ClockInOutButton.tsx +++ b/src/components/ClockInOutButton.tsx @@ -2620,6 +2620,7 @@ export default function ClockInOutButton({ list={bidDay.list} board={bidDay.board} disabled={clockOutSaving} + noteBelow onToggle={bidDay.toggle} onAddFromBoard={(bidId) => { const pick = workingBoardBidPicks.find((b) => b.id === bidId) diff --git a/src/components/clock/BidDayKeepWindow.tsx b/src/components/clock/BidDayKeepWindow.tsx new file mode 100644 index 0000000000..f69a4ae60c --- /dev/null +++ b/src/components/clock/BidDayKeepWindow.tsx @@ -0,0 +1,160 @@ +/** + * The day's list of bids in a window, with one press that keeps it. Two doors open it: *Done for the day* after a + * break (punch list #473, `DoneForTheDayBidDay`) and the Job Mode header's count (punch list #469, + * `JobModeBidsPress`). Each hands in its own words and its own read of the day. The list is the clock out's own + * (`ClockOutBidDay`), and the save is `save_my_bid_day`. + * + * The window takes the cursor when it opens and gives it back to where it was when it closes. + */ +import { useEffect, useRef, useState, type CSSProperties } from 'react' +import { createPortal } from 'react-dom' +import ClockOutBidDay from './ClockOutBidDay' +import type { BidDayPick, ClockOutBidDay as BidDay } from '../../hooks/useClockOutBidDay' +import { useToastContext } from '../../contexts/ToastContext' +import { useModalStackEntry } from '../../hooks/useModalStackEntry' +import { saveMyBidDay } from '../../lib/clock/bidDayIo' +import { DEAD_PRESS_FILL, DEAD_PRESS_TEXT } from '../../lib/deadPress' +import { formatErrorMessage } from '../../utils/errorHandling' + +const GREEN = '#15803d' +const btn: CSSProperties = { + minHeight: 44, + padding: '0 0.85rem', + borderRadius: 8, + borderWidth: 1, + borderStyle: 'solid', + borderColor: 'var(--border-strong)', + background: 'var(--surface)', + color: 'var(--text-strong)', + fontFamily: 'inherit', + fontSize: '0.875rem', + fontWeight: 600, + cursor: 'pointer', +} +const muted: CSSProperties = { margin: 0, fontSize: '0.8125rem', color: 'var(--text-muted)' } + +export type BidDayKeepWindowWords = { + title: string + lead: string + officeWords: string + closeLabel: string + keepingLabel: string + keepLabel: (kept: number) => string + keptToast: (kept: number) => string + notKeptLead: string + /** A last quiet line, or '' for none. */ + later: string +} + +type Props = { + words: BidDayKeepWindowWords + bidDay: BidDay + boardPicks: readonly BidDayPick[] + /** Words drawn in place of the list while there is no list to draw: the day being read, or not read. */ + inPlaceOfList?: string | null + /** The window's own test id; its two presses take `-keep` and `-close` after it. */ + testId: string + /** The list was kept, with how many bids. The window closes after it. */ + onKept?: (kept: number) => void + onClose: () => void +} + +export function BidDayKeepWindow({ words, bidDay, boardPicks, inPlaceOfList = null, testId, onKept, onClose }: Props) { + const { showToast } = useToastContext() + const [saving, setSaving] = useState(false) + const hasList = !inPlaceOfList + const canKeep = hasList && bidDay.list.worked.length > 0 && !saving + + // The cursor goes into the window, and back to the press that opened it. + const windowRef = useRef(null) + useEffect(() => { + const before = document.activeElement instanceof HTMLElement ? document.activeElement : null + windowRef.current?.focus() + return () => { + if (before && before.isConnected) before.focus() + } + }, []) + + // Escape closes the window; a window opened over it keeps the press for itself. + const isTopmost = useModalStackEntry() + useEffect(() => { + const onKey = (e: KeyboardEvent) => { + if (e.key !== 'Escape' || e.defaultPrevented || !isTopmost()) return + e.preventDefault() + e.stopPropagation() + if (!saving) onClose() + } + window.addEventListener('keydown', onKey, true) + return () => window.removeEventListener('keydown', onKey, true) + }, [onClose, isTopmost, saving]) + + const keep = async () => { + if (!canKeep) return + setSaving(true) + try { + const kept = await saveMyBidDay(bidDay.workDate, bidDay.entries()) + showToast(words.keptToast(kept), 'success') + onKept?.(kept) + onClose() + } catch (e) { + // The window stays: the person can press again, or close it and keep the list later. + showToast(`${words.notKeptLead}: ${formatErrorMessage(e, 'the save did not go through')}`, 'error') + setSaving(false) + } + } + + return createPortal( +
{ + if (e.target === e.currentTarget && !saving) onClose() + }} + > +
+

{words.title}

+

{words.lead}

+ {hasList ? ( + { + const pick = boardPicks.find((b) => b.id === bidId) + if (pick) bidDay.add(pick) + }} + /> + ) : ( +

+ {inPlaceOfList} +

+ )} +

{words.officeWords}

+
+ + +
+ {words.later ?

{words.later}

: null} +
+
, + document.body, + ) +} diff --git a/src/components/clock/ClockOutBidDay.tsx b/src/components/clock/ClockOutBidDay.tsx index 15dc18fd24..7455df7261 100644 --- a/src/components/clock/ClockOutBidDay.tsx +++ b/src/components/clock/ClockOutBidDay.tsx @@ -1,5 +1,5 @@ import type { CSSProperties, ReactNode } from 'react' -import { bidDayRowLine, type BidDayList, type BidDayRow } from '../../lib/clock/bidDay' +import { BID_DAY_EMPTY_LEAD, bidDayEmptyWords, bidDayRowLine, type BidDayList, type BidDayRow } from '../../lib/clock/bidDay' import { formatDenverTimeOnly } from '../../utils/dateUtils' /** @@ -74,12 +74,15 @@ export default function ClockOutBidDay({ list, board, disabled = false, + noteBelow = false, onToggle, onAddFromBoard, }: { list: BidDayList board: ReadonlyArray<{ id: string; name: string }> disabled?: boolean + /** True on the clock out's sheet, which asks for a typed note under the list. The empty words name it only there. */ + noteBelow?: boolean onToggle: (bidId: string) => void onAddFromBoard: (bidId: string) => void }) { @@ -122,8 +125,8 @@ export default function ClockOutBidDay({ ) : (
- The app saw no bid today. - {list.opened.length > 0 ? 'Tick a bid below to add it, or say what you did.' : 'Add the bids you worked on, or say what you did below.'} + {BID_DAY_EMPTY_LEAD} + {bidDayEmptyWords({ opened: list.opened.length, board: board.length, noteBelow })}
)} diff --git a/src/components/clock/DoneForTheDayBidDay.tsx b/src/components/clock/DoneForTheDayBidDay.tsx index b3b2a46adb..4f0d117ed0 100644 --- a/src/components/clock/DoneForTheDayBidDay.tsx +++ b/src/components/clock/DoneForTheDayBidDay.tsx @@ -3,15 +3,12 @@ * asked: the bar ends it first. This reads the person's day and, where the day holds a bid, draws the clock out's * list in a window with one press that keeps it. A day with no bid (an estimator's too, finding 866), a read that * fails and a window closed unkept all end the ask with nothing drawn. The rule and the words are - * `lib/clock/doneForTheDay.ts`; the list itself is the clock out's own (`ClockOutBidDay`, `useClockOutBidDay`). + * `lib/clock/doneForTheDay.ts`; the list itself is the clock out's own (`ClockOutBidDay`, `useClockOutBidDay`), and + * the window is `BidDayKeepWindow`, which the Job Mode header's count opens too. */ -import { useEffect, useState, type CSSProperties } from 'react' -import { createPortal } from 'react-dom' -import ClockOutBidDay from './ClockOutBidDay' -import { useClockOutBidDay, type BidDayPick, type ClockOutBidDay as BidDay } from '../../hooks/useClockOutBidDay' -import { useToastContext } from '../../contexts/ToastContext' -import { useModalStackEntry } from '../../hooks/useModalStackEntry' -import { saveMyBidDay } from '../../lib/clock/bidDayIo' +import { useEffect, useMemo, useState } from 'react' +import { BidDayKeepWindow, type BidDayKeepWindowWords } from './BidDayKeepWindow' +import { useClockOutBidDay, type BidDayPick } from '../../hooks/useClockOutBidDay' import { DONE_LIST_CLOSE_LABEL, DONE_LIST_KEEPING_LABEL, @@ -24,27 +21,8 @@ import { doneListLaterWords, doneListStep, } from '../../lib/clock/doneForTheDay' -import { DEAD_PRESS_FILL, DEAD_PRESS_TEXT } from '../../lib/deadPress' import { fetchWorkingBoardClockBidPicks } from '../../lib/fetchWorkingBoardClockBidPicks' import type { LedgerPrefixMap } from '../../lib/ledgerDisplayPrefixes' -import { formatErrorMessage } from '../../utils/errorHandling' - -const GREEN = '#15803d' -const btn: CSSProperties = { - minHeight: 40, - padding: '0 0.85rem', - borderRadius: 8, - borderWidth: 1, - borderStyle: 'solid', - borderColor: 'var(--border-strong)', - background: 'var(--surface)', - color: 'var(--text-strong)', - fontFamily: 'inherit', - fontSize: '0.875rem', - fontWeight: 600, - cursor: 'pointer', -} -const muted: CSSProperties = { margin: 0, fontSize: '0.8125rem', color: 'var(--text-muted)' } type Props = { userId: string @@ -83,87 +61,21 @@ export function DoneForTheDayBidDay({ userId, role, prefixMap, asked, onClose }: if (step === 'none') onClose() }, [step, onClose]) - if (step !== 'list') return null - return -} - -function DoneListWindow({ bidDay, boardPicks, role, onClose }: { bidDay: BidDay; boardPicks: BidDayPick[]; role: string | null | undefined; onClose: () => void }) { - const { showToast } = useToastContext() - const [saving, setSaving] = useState(false) - const canKeep = bidDay.list.worked.length > 0 && !saving - const later = doneListLaterWords(role) - - // Escape closes the window; a window opened over it keeps the press for itself. - const isTopmost = useModalStackEntry() - useEffect(() => { - const onKey = (e: KeyboardEvent) => { - if (e.key !== 'Escape' || e.defaultPrevented || !isTopmost()) return - e.preventDefault() - e.stopPropagation() - if (!saving) onClose() - } - window.addEventListener('keydown', onKey, true) - return () => window.removeEventListener('keydown', onKey, true) - }, [onClose, isTopmost, saving]) - - const keep = async () => { - if (!canKeep) return - setSaving(true) - try { - const kept = await saveMyBidDay(bidDay.workDate, bidDay.entries()) - showToast(doneListKeptToast(kept), 'success') - onClose() - } catch (e) { - // The window stays: the person can press again, or close it and keep the list later. - showToast(`${DONE_LIST_NOT_KEPT_LEAD}: ${formatErrorMessage(e, 'the save did not go through')}`, 'error') - setSaving(false) - } - } - - return createPortal( -
{ - if (e.target === e.currentTarget && !saving) onClose() - }} - > -
-

{DONE_LIST_TITLE}

-

{DONE_LIST_LEAD}

- { - const pick = boardPicks.find((b) => b.id === bidId) - if (pick) bidDay.add(pick) - }} - /> -

{DONE_LIST_OFFICE_WORDS}

-
- - -
- {later ?

{later}

: null} -
-
, - document.body, + const words = useMemo( + () => ({ + title: DONE_LIST_TITLE, + lead: DONE_LIST_LEAD, + officeWords: DONE_LIST_OFFICE_WORDS, + closeLabel: DONE_LIST_CLOSE_LABEL, + keepingLabel: DONE_LIST_KEEPING_LABEL, + keepLabel: doneListKeepLabel, + keptToast: doneListKeptToast, + notKeptLead: DONE_LIST_NOT_KEPT_LEAD, + later: doneListLaterWords(role), + }), + [role], ) + + if (step !== 'list') return null + return } diff --git a/src/components/jobMode/DashboardJobModeCard.bids.render.test.tsx b/src/components/jobMode/DashboardJobModeCard.bids.render.test.tsx new file mode 100644 index 0000000000..ee93ad0c9c --- /dev/null +++ b/src/components/jobMode/DashboardJobModeCard.bids.render.test.tsx @@ -0,0 +1,242 @@ +// @vitest-environment jsdom +/** + * Punch list #469, the Job Mode step. While the clock is on the office job, or on no job, the card's header counts + * the bids of the day so far where the job's name was, for a role that works on bids. A press on the count opens the + * day's list in a window with one press that keeps it. The supabase stub is the press bar smoke's. Every name and + * bid here is made up. + */ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { cleanup, fireEvent, screen, waitFor } from '@testing-library/react' + +const OFFICE = '00000000-0000-0000-0000-00000000aaaa' +const JOB_B = '00000000-0000-0000-0000-00000000bbbb' +const B412 = '0b1d0000-0000-4000-8000-00000000b412' + +const scenario: { + blocks: Array> + openSession: Record | null + visited: Array<{ job_ledger_id: string }> + role: string + phone: boolean +} = { blocks: [], openSession: null, visited: [], role: 'estimator', phone: false } + +const h = vi.hoisted(() => ({ fetchDay: vi.fn(), saveDay: vi.fn(), officeJob: vi.fn() })) + +function ledgerJoin(n: number, name: string) { + return { hcp_number: `${n}`, click_number: null, job_name: name, job_address: `${n} Test St`, service_type_id: null } +} + +function makeBlocks(): Array> { + return [ + { id: 'blk-1', job_id: OFFICE, time_start: '08:00', time_end: '12:00', jobs_ledger: ledgerJoin(100, 'ZZ Test Office') }, + { id: 'blk-2', job_id: JOB_B, time_start: '13:00', time_end: '17:00', jobs_ledger: ledgerJoin(502, 'Smoke Job 2') }, + ] +} + +vi.mock('../../lib/supabase', () => { + function makeBuilder(table: string) { + let single = false + const builder: Record = {} + for (const m of ['select', 'insert', 'update', 'eq', 'neq', 'is', 'in', 'or', 'not', 'order', 'range', 'limit', 'abortSignal', 'filter']) builder[m] = () => builder + builder.single = () => { single = true; return builder } + builder.maybeSingle = () => { single = true; return builder } + const result = () => { + if (table === 'job_schedule_blocks') return Promise.resolve({ data: scenario.blocks, error: null, count: 0 }) + if (table === 'clock_sessions') { + return single + ? Promise.resolve({ data: scenario.openSession, error: null, count: 0 }) + : Promise.resolve({ data: scenario.visited, error: null, count: 0 }) + } + if (table === 'jobs_ledger' && single) return Promise.resolve({ data: { pct_complete: 40, status: 'working' }, error: null, count: 0 }) + return Promise.resolve({ data: single ? null : [], error: null, count: 0 }) + } + builder.then = (f?: (v: unknown) => unknown, r?: (e: unknown) => unknown) => result().then(f, r) + builder.catch = (r?: (e: unknown) => unknown) => result().catch(r) + builder.finally = (f?: () => void) => result().finally(f) + return builder + } + const channel = () => { + const ch: Record = {} + ch.on = () => ch + ch.subscribe = () => ch + ch.unsubscribe = () => Promise.resolve('ok') + return ch + } + return { + supabase: { + from: (table: string) => makeBuilder(table), + rpc: () => makeBuilder('__rpc__'), + channel, + removeChannel: () => {}, + functions: { invoke: () => Promise.resolve({ data: null, error: null }) }, + auth: { + getSession: () => Promise.resolve({ data: { session: null }, error: null }), + onAuthStateChange: () => ({ data: { subscription: { unsubscribe: () => {} } } }), + }, + }, + } +}) + +vi.mock('../../hooks/useAuth', () => ({ useAuth: () => ({ user: { id: 'u1' }, role: scenario.role, profileName: 'Dana Whitlock' }) })) +vi.mock('../../hooks/useNarrowViewport640', () => ({ useNarrowViewport640: () => scenario.phone })) +vi.mock('../../lib/clock/bidDayIo', () => ({ fetchMyBidDay: h.fetchDay, saveMyBidDay: h.saveDay })) +vi.mock('../../lib/overheadOfficeJobSettings', () => ({ fetchOverheadOfficeJobLedgerIdFromAppSettings: h.officeJob })) +vi.mock('../../lib/bids/bidJobsOpenedIo', () => ({ loadJobsOpenedFromBids: async () => [] })) +vi.mock('../../lib/fetchWorkingBoardClockBidPicks', () => ({ fetchWorkingBoardClockBidPicks: async () => [] })) + +import { renderWithProviders } from '../../test/renderSmokeMocks' +import { UpdateFocusOpenerBridgeProvider } from '../../contexts/UpdateFocusOpenerBridgeContext' +import { LedgerDisplayPrefixProvider } from '../../contexts/LedgerDisplayPrefixContext' +import { todayYmdInAppTz } from '../../utils/dateUtils' +import DashboardJobModeCard from './DashboardJobModeCard' + +const clockIn = new Date(Date.now() - 3 * 60 * 60 * 1000) +const at = (minutes: number) => new Date(Math.floor((clockIn.getTime() + minutes * 60_000) / 300_000) * 300_000).toISOString() +const emptyDay = { + day: todayYmdInAppTz(), + from: new Date(Date.now() - 12 * 60 * 60 * 1000).toISOString(), + to: new Date(Date.now() + 12 * 60 * 60 * 1000).toISOString(), + now: new Date().toISOString(), + changes: [], + beats: [], + kept: [], + sessions: [{ in: clockIn.toISOString(), out: null }], + bids: [], +} +const day = { + ...emptyDay, + changes: [{ bid_id: B412, at: at(30), own: 4, app: 0, tables: ['bid_pricing_assignments'] }], + beats: [{ bid_id: B412, tab: 'pricing', at: at(30), seconds: 300 }], + bids: [{ id: B412, bid_number: '412', project_name: 'ZZ Test Ridgeway Clinic', service_type_id: null }], +} + +function renderCard() { + return renderWithProviders( + + + {}} onTurnaway={() => {}} canClockOut /> + + , + ) +} + +function viewport(width: number) { + Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: width }) + scenario.phone = width <= 640 +} + +const onTheClock = (over: { job?: string | null; bid?: string | null; role?: string } = {}) => + Object.assign(scenario, { + blocks: makeBlocks(), + openSession: { id: 'sess-1', job_ledger_id: over.job === undefined ? OFFICE : over.job, bid_id: over.bid ?? null }, + visited: [], + role: over.role ?? 'estimator', + }) + +afterEach(() => { + cleanup() + h.fetchDay.mockReset() + h.saveDay.mockReset() + h.officeJob.mockReset() + document.documentElement.style.removeProperty('--job-mode-press-bar') +}) + +describe('DashboardJobModeCard — the bids of the day so far (punch list #469)', { timeout: 15_000 }, () => { + it('on the office job, the header counts the day’s bids where the job’s name was, with the job under it', async () => { + viewport(1280) + onTheClock() + h.officeJob.mockResolvedValue(OFFICE) + h.fetchDay.mockResolvedValue(day) + renderCard() + const press = await screen.findByTestId('job-mode-bids-press') + expect(press.textContent).toBe('Bids · 1 ›') + expect(press.getAttribute('aria-label')).toBe('Bids · 1. Open your bids today.') + expect(screen.getByTestId('job-mode-bids-under').textContent).toMatch(/^On .*100 · ZZ Test Office$/) + expect(screen.queryByRole('dialog')).toBeNull() + }) + + it('a press opens the day’s list in a window, and Keep my list keeps it and reads the count again', async () => { + viewport(375) + onTheClock() + h.officeJob.mockResolvedValue(OFFICE) + h.fetchDay.mockResolvedValue(day) + h.saveDay.mockResolvedValue(1) + renderCard() + fireEvent.click(await screen.findByTestId('job-mode-bids-press')) + const win = await screen.findByRole('dialog', { name: 'Your bids today' }) + expect(win.textContent).toContain('The bids you worked on so far today.') + const keep = await screen.findByRole('button', { name: 'Keep my list · 1 bid' }) + const readsBefore = h.fetchDay.mock.calls.length + fireEvent.click(keep) + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) + const [workDate, entries] = h.saveDay.mock.calls[0] as [string, Array<{ bid_id: string; state: string }>] + expect(workDate).toBe(day.day) + expect(entries.map((e) => `${e.bid_id}:${e.state}`)).toEqual([`${B412}:kept`]) + await waitFor(() => expect(h.fetchDay.mock.calls.length).toBeGreaterThan(readsBefore)) + }) + + it('the window says so while the day is read and when it cannot be, and Close closes it', async () => { + viewport(1280) + onTheClock() + h.officeJob.mockResolvedValue(OFFICE) + h.fetchDay.mockResolvedValueOnce(day).mockRejectedValue(new Error('offline')) + renderCard() + fireEvent.click(await screen.findByTestId('job-mode-bids-press')) + const win = await screen.findByRole('dialog', { name: 'Your bids today' }) + await waitFor(() => expect(win.textContent).toContain('Your day could not be read. Close this and open it again.')) + expect((screen.getByTestId('job-mode-bids-keep') as HTMLButtonElement).disabled).toBe(true) + fireEvent.click(screen.getByRole('button', { name: 'Close' })) + expect(screen.queryByRole('dialog')).toBeNull() + }) + + it('on no job at all, the header counts the bids and says so, and the office job is never read', async () => { + viewport(1280) + onTheClock({ job: null }) + h.fetchDay.mockResolvedValue(day) + renderCard() + expect((await screen.findByTestId('job-mode-bids-press')).textContent).toBe('Bids · 1 ›') + expect(screen.getByTestId('job-mode-bids-under').textContent).toBe('Clocked in with no job') + expect(h.officeJob).not.toHaveBeenCalled() + }) + + it('keeps the job’s own header on a day with no bid yet, and when the day cannot be read', async () => { + viewport(1280) + onTheClock() + h.officeJob.mockResolvedValue(OFFICE) + h.fetchDay.mockResolvedValue(emptyDay) + const first = renderCard() + await screen.findByText('ZZ Test Office') + await waitFor(() => expect(h.fetchDay).toHaveBeenCalled()) + expect(screen.queryByTestId('job-mode-bids-press')).toBeNull() + first.unmount() + + h.fetchDay.mockReset() + h.fetchDay.mockRejectedValue(new Error('offline')) + renderCard() + await screen.findByText('ZZ Test Office') + await waitFor(() => expect(h.fetchDay).toHaveBeenCalled()) + expect(screen.queryByTestId('job-mode-bids-press')).toBeNull() + }) + + it('reads nothing on a job in the field, on a bid, or for a role that does not work on bids', async () => { + viewport(1280) + h.officeJob.mockResolvedValue(OFFICE) + h.fetchDay.mockResolvedValue(day) + + onTheClock({ job: JOB_B }) + const field = renderCard() + await screen.findByText('Smoke Job 2') + await waitFor(() => expect(h.officeJob).toHaveBeenCalled()) + expect(h.fetchDay).not.toHaveBeenCalled() + expect(screen.queryByTestId('job-mode-bids-press')).toBeNull() + field.unmount() + + h.officeJob.mockClear() + onTheClock({ role: 'helpers' }) + renderCard() + await screen.findByText('ZZ Test Office') + expect(h.officeJob).not.toHaveBeenCalled() + expect(h.fetchDay).not.toHaveBeenCalled() + expect(screen.queryByTestId('job-mode-bids-press')).toBeNull() + }) +}) diff --git a/src/components/jobMode/DashboardJobModeCard.tsx b/src/components/jobMode/DashboardJobModeCard.tsx index e64f7608a7..94458a749d 100644 --- a/src/components/jobMode/DashboardJobModeCard.tsx +++ b/src/components/jobMode/DashboardJobModeCard.tsx @@ -72,6 +72,8 @@ import { PHONE_PRESS_MIN_HEIGHT } from '../../lib/phonePress' import { DEAD_PRESS_FILL, DEAD_PRESS_TEXT } from '../../lib/deadPress' import { JobModePressBar } from './JobModePressBar' import { JobModeOnBreak } from './JobModeOnBreak' +import { JobModeBidsPress, JobModeBidsWindow } from './JobModeBidsPress' +import { useJobModeBids } from '../../hooks/useJobModeBids' import { useClockBreakDoor } from '../../contexts/ClockBreakDoorContext' import { BREAK_LABEL, BREAK_TITLE } from '../../lib/clock/clockBreak' import { JobModeShortRow } from './JobModeShortRow' @@ -820,6 +822,19 @@ export default function DashboardJobModeCard({ userId, onLeaveReport, onTurnaway // Header content depends on state. function renderHeader() { + // On the office job, or on no job, with a bid in the day: the day reads as its bids (punch list #469). + if (bidsNow.header) { + return ( +
+ setBidsListOpen(true)} /> +
+ {bidsNow.header.under} +
+ {legLine} + {picked.state === 'on-off-schedule-job' && currentJobInfo ?
Not on today’s schedule
: null} +
+ ) + } // Clocked into a job that matches today's schedule. if (picked.currentBlock) { const cb = picked.currentBlock @@ -945,6 +960,26 @@ export default function DashboardJobModeCard({ userId, onLeaveReport, onTurnaway return 'your open session' })() + // The bids of the day so far (punch list #469): on the office job, or on no job, the header counts them where the + // job's name was, and a press opens the list. A job whose words are not read yet, or are masked, keeps its header. + const bidsJobId = openSession?.jobLedgerId ?? null + const bidsJobLabel = !bidsJobId ? null : picked.currentBlock || currentJobInfo ? leavingLabel : undefined + const bidsNow = useJobModeBids({ + enabled: authUser?.id === userId && !keptDay && bidsJobLabel !== undefined && !(bidsJobId && maskedJobs.has(bidsJobId)), + role, + sessionId: openSession?.id ?? null, + onBid: !!openSession?.bidId, + jobId: bidsJobId, + jobLabel: bidsJobLabel ?? null, + }) + const [bidsListOpen, setBidsListOpen] = useState(false) + const rereadBids = bidsNow.reread + const closeBidsList = useCallback(() => { + setBidsListOpen(false) + rereadBids() + }, [rereadBids]) + const bidsWindow = bidsListOpen ? : null + // Job the "Job calendar" link opens: the header's job (current block → // off-schedule clock job → next block), matching what the tech is looking at. const jobCalendarTarget: JobCalendarJobIdentity | null = (() => { @@ -1513,6 +1548,7 @@ export default function DashboardJobModeCard({ userId, onLeaveReport, onTurnaway {loading && !held ?
Loading Job Mode…
: null} {renderHeader()} {onBreakBand} + {bidsWindow} {calendarWindow} + ) +} + +/** The day's list, read when the window opens. */ +export function JobModeBidsWindow({ userId, role, prefixMap, onClose }: { userId: string; role: string | null | undefined; prefixMap: LedgerPrefixMap; onClose: () => void }) { + const [boardPicks, setBoardPicks] = useState([]) + const bidDay = useClockOutBidDay({ open: true, userId, role, prefixMap, boardPicks }) + + useEffect(() => { + let stale = false + void fetchWorkingBoardClockBidPicks(userId) + .then((picks) => { + if (!stale) setBoardPicks(picks) + }) + .catch(() => { + /* no chips from the board: the list itself still draws */ + }) + return () => { + stale = true + } + }, [userId]) + + const inPlaceOfList = useMemo(() => (bidDay.failed ? JOB_MODE_BIDS_NOT_READ : bidDay.workDate === '' ? JOB_MODE_BIDS_READING : null), [bidDay.failed, bidDay.workDate]) + return +} diff --git a/src/content/help/clock-out-with-the-bids-of-the-day.md b/src/content/help/clock-out-with-the-bids-of-the-day.md index 1e5131b411..57d56d9ed2 100644 --- a/src/content/help/clock-out-with-the-bids-of-the-day.md +++ b/src/content/help/clock-out-with-the-bids-of-the-day.md @@ -60,6 +60,8 @@ The sheet says **The app saw no bid today.** Add the bids you worked on, or type My Time on your dashboard has the same list under **Your bids today**. Keep the list there if you are on salary, or if your day ended without the clock-out sheet. See [Keep the bids you worked on today](/help/see-the-time-i-have-added-up#keep-the-bids-you-worked-on-today). +Job Mode has the list too. While you are clocked in on the office job, the top of the Job Mode card reads {{chip:gray|Bids · 3}}. The number is the bids you changed today. Press it to open **Your bids today**, then press {{button:green|Keep my list · 3 bids}}. + ## What the app can see The app sees a bid you change. The app also sees a bid you have open on the Bids page while you press, type or scroll. diff --git a/src/content/help/job-mode-clocking.md b/src/content/help/job-mode-clocking.md index 2f3aab1a74..3d014747e3 100644 --- a/src/content/help/job-mode-clocking.md +++ b/src/content/help/job-mode-clocking.md @@ -123,6 +123,7 @@ On a phone the day's presses sit in a bar at the bottom of the screen, above the - {{button:outline|Clock out}} is for lunch, a parts run, or leaving early. See Clocking out below. - On a computer or a tablet the same buttons sit inside the card, under the day's list. - Under the card, each stage with a checklist is a press. A job whose stages have no questions shows no checklist rows there. The job window still lists them. +- Do you work on bids? On the office job the card's top line reads {{chip:gray|Bids · 3}} once you change a bid. Press it to open your list. See [Keep the list without clocking out](/help/clock-out-with-the-bids-of-the-day#keep-the-list-without-clocking-out). ## Your day on the card diff --git a/src/content/releaseNotes/v2.9282.ts b/src/content/releaseNotes/v2.9282.ts new file mode 100644 index 0000000000..37c56adacf --- /dev/null +++ b/src/content/releaseNotes/v2.9282.ts @@ -0,0 +1,16 @@ +import type { ReleaseNote } from '../../lib/releaseNotes' + +const note: ReleaseNote = { + version: 'v2.9282', + date: '2026-12-03', + title: 'Job Mode: the card counts the bids of your day, and a press opens the list', + kind: 'feature', + highlights: [ + 'If you work on bids and are clocked in on the office job, the top of the Job Mode card now reads Bids · 3 in place of the office job. The office job is on the line under it.', + 'The number is the bids you changed today, the same number clock out offers to keep.', + 'Press it to open Your bids today over the card. Keep my list keeps the list for the office with no clock out.', + 'On My Time, an empty Your bids today no longer tells you to say what you did below. It names the next press that is there.', + ], +} + +export default note diff --git a/src/hooks/useJobModeBids.ts b/src/hooks/useJobModeBids.ts new file mode 100644 index 0000000000..c595baf6c7 --- /dev/null +++ b/src/hooks/useJobModeBids.ts @@ -0,0 +1,62 @@ +import { useCallback, useEffect, useState } from 'react' +import { fetchMyBidDay } from '../lib/clock/bidDayIo' +import { bidsSoFar, jobModeBidsAsked, jobModeBidsHeader, jobModeBidsNeedsOffice, type JobModeBidsHeader } from '../lib/jobMode/jobModeBids' +import { fetchOverheadOfficeJobLedgerIdFromAppSettings } from '../lib/overheadOfficeJobSettings' + +/** + * The bids of the day so far, for the Job Mode card's header (punch list #469). It reads the office job's id once, + * and the person's own day when the clock is on the office job or on no job. The rule is `lib/jobMode/jobModeBids.ts`. + * A read that fails leaves the header as the job's own words: the count never stands in the way of the card. + */ +export function useJobModeBids(opts: { + /** False for anyone's card but the person's own, and while a kept day stands in for the live read. */ + enabled: boolean + role: string | null | undefined + sessionId: string | null + onBid: boolean + jobId: string | null + /** The session's job as the card names it, 'JP000 · Office', or null on no job. */ + jobLabel: string | null +}): { header: JobModeBidsHeader | null; reread: () => void } { + const { enabled, role, sessionId, onBid, jobId, jobLabel } = opts + /** undefined until read; null when the company has no office job set. */ + const [officeJobId, setOfficeJobId] = useState(undefined) + const [count, setCount] = useState<{ sessionId: string; bids: number } | null>(null) + const [turn, setTurn] = useState(0) + + const needsOffice = enabled && officeJobId === undefined && jobModeBidsNeedsOffice({ role, sessionId, onBid, jobId }) + useEffect(() => { + if (!needsOffice) return + let stale = false + void fetchOverheadOfficeJobLedgerIdFromAppSettings() + .then((id) => { + if (!stale) setOfficeJobId(id ?? null) + }) + .catch(() => { + if (!stale) setOfficeJobId(null) + }) + return () => { + stale = true + } + }, [needsOffice]) + + const asked = enabled && jobModeBidsAsked({ role, sessionId, onBid, jobId, officeJobId }) + useEffect(() => { + if (!asked || !sessionId) return + let stale = false + void fetchMyBidDay() + .then((day) => { + if (!stale) setCount(day ? { sessionId, bids: bidsSoFar(day) } : null) + }) + .catch(() => { + /* no count: the header keeps the job's own words */ + }) + return () => { + stale = true + } + }, [asked, sessionId, turn]) + + const reread = useCallback(() => setTurn((n) => n + 1), []) + const bids = count && count.sessionId === sessionId ? count.bids : null + return { header: jobModeBidsHeader({ asked, bids, jobLabel }), reread } +} diff --git a/src/lib/clock/bidDay.test.ts b/src/lib/clock/bidDay.test.ts index 5ccac244b0..ea93300a1a 100644 --- a/src/lib/clock/bidDay.test.ts +++ b/src/lib/clock/bidDay.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' import { BID_DAY_COLORS, + bidDayEmptyWords, bidDayEntries, bidDayMarksFromKept, bidDayPressLabel, @@ -329,3 +330,17 @@ describe('worksOnBids', () => { expect(worksOnBids(null)).toBe(false) }) }) + +describe('bidDayEmptyWords', () => { + it('names a note only where there is one to type', () => { + expect(bidDayEmptyWords({ opened: 2, board: 0, noteBelow: true })).toBe('Tick a bid below to add it, or say what you did.') + expect(bidDayEmptyWords({ opened: 2, board: 0, noteBelow: false })).toBe('Tick a bid below to add it.') + expect(bidDayEmptyWords({ opened: 0, board: 3, noteBelow: true })).toBe('Add the bids you worked on, or say what you did below.') + expect(bidDayEmptyWords({ opened: 0, board: 3, noteBelow: false })).toBe('Add the bids you worked on from your board below.') + }) + + it('away from the clock out, offers no press that is not there: no opened bid and no board', () => { + expect(bidDayEmptyWords({ opened: 0, board: 0, noteBelow: false })).toBe('A bid you change on the Bids page today shows here.') + expect(bidDayEmptyWords({ opened: 0, board: 0, noteBelow: true })).toBe('Add the bids you worked on, or say what you did below.') + }) +}) diff --git a/src/lib/clock/bidDay.ts b/src/lib/clock/bidDay.ts index 3340beb9bd..bfa9ae1ca4 100644 --- a/src/lib/clock/bidDay.ts +++ b/src/lib/clock/bidDay.ts @@ -435,6 +435,21 @@ export function worksOnBids(role: string | null | undefined): boolean { return role != null && BID_DAY_ROLES.has(role) } +export const BID_DAY_EMPTY_LEAD = 'The app saw no bid today.' + +/** + * What an empty list says under its lead. The clock out's sheet has a note to type under the list, and its words + * are as they were. Elsewhere the words name the next press, and only a press that is there. My time and the windows that keep a list have none, so they never say *below* of + * a note (seen on My time in a look of punch list #469). + */ +export function bidDayEmptyWords(input: { opened: number; board: number; noteBelow: boolean }): string { + // The clock out's own words, as they were: its sheet has the note, and its own way to add a bid. + if (input.noteBelow) return input.opened > 0 ? 'Tick a bid below to add it, or say what you did.' : 'Add the bids you worked on, or say what you did below.' + if (input.opened > 0) return 'Tick a bid below to add it.' + if (input.board > 0) return 'Add the bids you worked on from your board below.' + return 'A bid you change on the Bids page today shows here.' +} + /** The press says what it keeps: 'Complete clock out · 4 bids'. With no bid it is the verb alone. */ export function bidDayPressLabel(verb: string, kept: number): string { if (!(kept > 0)) return verb diff --git a/src/lib/jobMode/jobModeBids.test.ts b/src/lib/jobMode/jobModeBids.test.ts new file mode 100644 index 0000000000..343eb9234d --- /dev/null +++ b/src/lib/jobMode/jobModeBids.test.ts @@ -0,0 +1,115 @@ +import { describe, expect, it } from 'vitest' +import type { BidDayPayload } from '../clock/bidDay' +import { bidsSoFar, JOB_MODE_BIDS_NO_JOB, jobModeBidsAsked, jobModeBidsHeader, jobModeBidsKeepLabel, jobModeBidsKeptToast, jobModeBidsNeedsOffice } from './jobModeBids' + +// A made-up day, 2026-11-25 in the company's zone: clocked in at 7:00 (13:00 UTC), read at 15:00 (21:00 UTC). +const B412 = 'b412' +const B398 = 'b398' +const B420 = 'b420' +const OFFICE = 'job-office' +const at = (hhmm: string) => `2026-11-25T${hhmm}:00+00:00` +const payload = (over: Partial = {}): BidDayPayload => ({ + day: '2026-11-25', + from: '2026-11-25T06:00:00+00:00', + to: '2026-11-26T06:00:00+00:00', + now: at('21:00'), + changes: [], + beats: [], + kept: [], + sessions: [{ in: at('13:00'), out: null }], + bids: [], + ...over, +}) +const changed = (bidId: string, hhmm: string) => ({ bid_id: bidId, at: at(hhmm), own: 2, app: 0, tables: ['bid_pricing_assignments'] }) +const beat = (bidId: string, hhmm: string, seconds = 300) => ({ bid_id: bidId, tab: 'pricing', at: at(hhmm), seconds }) + +describe('jobModeBidsAsked', () => { + const on = { role: 'estimator', sessionId: 's1', onBid: false, jobId: OFFICE, officeJobId: OFFICE } + + it('reads the day on the office job and on no job, with the clock running', () => { + expect(jobModeBidsAsked(on)).toBe(true) + expect(jobModeBidsAsked({ ...on, jobId: null, officeJobId: undefined })).toBe(true) + }) + + it('reads nothing with no clock running, on a bid, or on a job in the field', () => { + expect(jobModeBidsAsked({ ...on, sessionId: null })).toBe(false) + expect(jobModeBidsAsked({ ...on, onBid: true, jobId: null })).toBe(false) + expect(jobModeBidsAsked({ ...on, jobId: 'job-field' })).toBe(false) + }) + + it('waits for the office job’s id, and reads nothing when there is none', () => { + expect(jobModeBidsAsked({ ...on, officeJobId: undefined })).toBe(false) + expect(jobModeBidsAsked({ ...on, officeJobId: null })).toBe(false) + }) + + it('reads nothing for a role that does not work on bids', () => { + expect(jobModeBidsAsked({ ...on, role: 'helpers' })).toBe(false) + expect(jobModeBidsAsked({ ...on, role: null })).toBe(false) + }) + + it('reads the office job’s id only for a session on some job', () => { + expect(jobModeBidsNeedsOffice(on)).toBe(true) + expect(jobModeBidsNeedsOffice({ ...on, jobId: null })).toBe(false) + expect(jobModeBidsNeedsOffice({ ...on, onBid: true })).toBe(false) + expect(jobModeBidsNeedsOffice({ ...on, role: 'helpers' })).toBe(false) + expect(jobModeBidsNeedsOffice({ ...on, sessionId: null })).toBe(false) + }) +}) + +describe('bidsSoFar', () => { + it('is nothing with no read and on a day with no bid', () => { + expect(bidsSoFar(null)).toBe(0) + expect(bidsSoFar(payload())).toBe(0) + }) + + it('counts the bids the person changed, and not one that was only opened', () => { + const day = payload({ + changes: [changed(B412, '14:00'), changed(B398, '15:00')], + beats: [beat(B412, '14:00'), beat(B398, '15:00'), beat(B420, '16:00')], + }) + expect(bidsSoFar(day)).toBe(2) + }) + + it('lets a kept list win: a bid taken off is not counted, and one ticked on or added by hand is', () => { + const day = payload({ + changes: [changed(B412, '14:00'), changed(B398, '15:00')], + beats: [beat(B412, '14:00'), beat(B398, '15:00'), beat(B420, '16:00')], + kept: [ + { bid_id: B412, state: 'off', source: 'app' }, + { bid_id: B420, state: 'kept', source: 'app' }, + { bid_id: 'b500', state: 'kept', source: 'person' }, + ], + }) + // B398 as read, B420 ticked on, b500 added by hand. B412 was taken off. + expect(bidsSoFar(day)).toBe(3) + }) +}) + +describe('jobModeBidsHeader', () => { + it('says the count where the job’s name was and the job under it', () => { + expect(jobModeBidsHeader({ asked: true, bids: 3, jobLabel: 'JP000 · Office' })).toEqual({ + title: 'Bids · 3', + under: 'On JP000 · Office', + pressLabel: 'Bids · 3. Open your bids today.', + }) + }) + + it('says so on a session with no job', () => { + expect(jobModeBidsHeader({ asked: true, bids: 1, jobLabel: null })?.under).toBe(JOB_MODE_BIDS_NO_JOB) + }) + + it('leaves the job’s own words when not asked, not read yet, or with no bid yet', () => { + expect(jobModeBidsHeader({ asked: false, bids: 3, jobLabel: 'JP000 · Office' })).toBeNull() + expect(jobModeBidsHeader({ asked: true, bids: null, jobLabel: 'JP000 · Office' })).toBeNull() + expect(jobModeBidsHeader({ asked: true, bids: 0, jobLabel: 'JP000 · Office' })).toBeNull() + }) +}) + +describe('the window’s words', () => { + it('names what the press keeps and what was kept', () => { + expect(jobModeBidsKeepLabel(0)).toBe('Keep my list') + expect(jobModeBidsKeepLabel(2)).toBe('Keep my list · 2 bids') + expect(jobModeBidsKeptToast(1)).toBe('Your list for today is kept: 1 bid.') + expect(jobModeBidsKeptToast(4)).toBe('Your list for today is kept: 4 bids.') + }) +}) diff --git a/src/lib/jobMode/jobModeBids.ts b/src/lib/jobMode/jobModeBids.ts new file mode 100644 index 0000000000..8c22ad9379 --- /dev/null +++ b/src/lib/jobMode/jobModeBids.ts @@ -0,0 +1,89 @@ +import { bidDayMarksFromKept, bidDayPressLabel, buildBidDayList, readBidDay, worksOnBids, type BidDayPayload } from '../clock/bidDay' +import { bidDayJobWords } from '../clock/bidDayLabels' + +/** + * The bids of the day so far on the Job Mode card (punch list #469, the Job Mode step). + * + * The owner, 2026-12-02: a day spent on bids is to look like the bids worked on, not like the office job the clock + * was on. People → Hours reads a day's *kept* list for that. A list is kept at clock out, and after a clock out + * this card shows no session, so the kept rule would almost never change its header. The person's answers of + * 2026-12-03 settle it: while the clock is on the office job, or on no job, the header counts the bids of the day + * so far from the person's own list, kept or not. The number is the one clock out would offer to keep, and a kept + * list wins once there is one. A press on it opens the list in a window. + * + * It changes what the card says and nothing about where the hours are costed. The read is the person's own day. + */ + +type Session = { + role: string | null | undefined + /** The open session's id, or null with no clock running. */ + sessionId: string | null + /** The session is on a bid: it names its bid already. */ + onBid: boolean + /** The job the session is on, or null. */ + jobId: string | null +} + +/** Whether the office job's id is worth reading: a session on some job, for a role that works on bids. */ +export function jobModeBidsNeedsOffice(input: Session): boolean { + return worksOnBids(input.role) && !!input.sessionId && !input.onBid && input.jobId != null +} + +/** + * Whether the card reads the person's day. Only for a role that works on bids, only with the clock running, and + * only on the office job or on no job. `officeJobId` is undefined until it is read, and null when there is none. + */ +export function jobModeBidsAsked(input: Session & { officeJobId: string | null | undefined }): boolean { + if (!worksOnBids(input.role) || !input.sessionId || input.onBid) return false + if (input.jobId == null) return true + return input.officeJobId != null && input.jobId === input.officeJobId +} + +/** + * The number the header says: the bids the person changed today, with what an earlier keep of the day put on or + * took off. It is the clock out's own count (`BidDayList.keptCount`), so the card and the clock out never disagree. + * A bid that was only opened is not counted. + */ +export function bidsSoFar(payload: BidDayPayload | null | undefined): number { + if (!payload) return 0 + return buildBidDayList(readBidDay(payload), bidDayMarksFromKept(payload.kept), [], { nameOf: () => '' }).keptCount +} + +export type JobModeBidsHeader = { + /** 'Bids · 3', where the job's name was. */ + title: string + /** 'On JP000 · Office', where the address was. */ + under: string + /** What the press says to a screen reader: 'Bids · 3. Open your bids today.' */ + pressLabel: string +} + +export const JOB_MODE_BIDS_NO_JOB = 'Clocked in with no job' + +/** The header in place of the job's own, or null to leave the job's words: not asked, not read yet, or no bid yet. */ +export function jobModeBidsHeader(input: { asked: boolean; bids: number | null; jobLabel: string | null }): JobModeBidsHeader | null { + if (!input.asked || input.bids == null) return null + // Asked already means the office job or no job, so the rule's own office check is met by passing none. + const title = bidDayJobWords({ bids: input.bids, onBid: false, jobId: null, officeJobId: null }) + if (!title) return null + const job = (input.jobLabel ?? '').trim() + return { title, under: job ? `On ${job}` : JOB_MODE_BIDS_NO_JOB, pressLabel: `${title}. Open your bids today.` } +} + +export const JOB_MODE_BIDS_TITLE = 'Your bids today' +export const JOB_MODE_BIDS_LEAD = 'The bids you worked on so far today. Keep the list now, or keep it at clock out.' +export const JOB_MODE_BIDS_OFFICE_WORDS = 'The office reads the list you keep beside your hours.' +export const JOB_MODE_BIDS_CLOSE_LABEL = 'Close' +export const JOB_MODE_BIDS_KEEPING_LABEL = 'Keeping…' +export const JOB_MODE_BIDS_READING = 'Reading your day…' +export const JOB_MODE_BIDS_NOT_READ = 'Your day could not be read. Close this and open it again.' +export const JOB_MODE_BIDS_NOT_KEPT_LEAD = 'Your list was not kept' + +/** The press says what it keeps: 'Keep my list · 2 bids'. */ +export function jobModeBidsKeepLabel(kept: number): string { + return bidDayPressLabel('Keep my list', kept) +} + +export function jobModeBidsKeptToast(kept: number): string { + return kept === 1 ? 'Your list for today is kept: 1 bid.' : `Your list for today is kept: ${kept} bids.` +} diff --git a/to-dos/bids-on-my-time/README.md b/to-dos/bids-on-my-time/README.md index b04fb6f060..79b69065ab 100644 --- a/to-dos/bids-on-my-time/README.md +++ b/to-dos/bids-on-my-time/README.md @@ -2,7 +2,7 @@ name: "Hours and My time: the bids of a day as labels, not as a description" number: 469 group: ready -status: asked 2026-12-01 by the owner with a picture of People → Hours · the clock-out list and the Hours row read in the code the same day · the card and the mock-up written · step 1, the kernel, is v2.9153 (2026-12-02) · the owner's answer the same day: the day is to look like the bids worked on in place of the office job · his second answer the same day: the times of the kept bids may ride with the kept list · step 2, the labels on People → Hours, is v2.9158 · step 2a, the stretches kept with the list, is v2.9160 with its migration · step 3's first piece, today's bids on My Time with a press that keeps the list, is v2.9165 · step 2b, the bar of the day under a session on People → Hours, is v2.9189 · step 3's second piece, the day's bids in the day editor, is v2.9194 +status: asked 2026-12-01 by the owner with a picture of People → Hours · the clock-out list and the Hours row read in the code the same day · the card and the mock-up written · step 1, the kernel, is v2.9153 (2026-12-02) · the owner's answer the same day: the day is to look like the bids worked on in place of the office job · his second answer the same day: the times of the kept bids may ride with the kept list · step 2, the labels on People → Hours, is v2.9158 · step 2a, the stretches kept with the list, is v2.9160 with its migration · step 3's first piece, today's bids on My Time with a press that keeps the list, is v2.9165 · step 2b, the bar of the day under a session on People → Hours, is v2.9189 · step 3's second piece, the day's bids in the day editor, is v2.9194 · the person answered six calls on the rest of My time on 2026-12-03 · the Job Mode card's header counting the day's bids, with a press that opens the list, is v2.9282 summary: > An estimator's day is clocked to the office job, and the bids she worked on are written into that session's description. The owner wants the bids labelled on her time instead, in a way that @@ -13,9 +13,9 @@ summary: > as labels beside the hours, with what was done on each, a bar of where the bids fell in the day and an honest line of how much of the day the app saw. The note goes back to what a person typed. The session stays on the office job, so pay is not touched. -next: The rest of My time: the Job Mode card, and the week's office-job row reading as bids. Then a bid's own page, and the Schedule and Dispatch pages. +next: The week's office-job row on My time reading as bids (answered, below). Then a bid's own page, and the Schedule and Dispatch pages, whose calls are not put yet. size: M as a train of six (S · S · M · S · S · not sized); steps 1, 2, 2a and 2b and the first piece of step 3 are built -ver: v2.9194 +ver: v2.9282 blocker: Nothing. opinion: build — the rows are saved already and read by the office already, and the line they are drawn as today tells a reader less than nothing --- @@ -107,6 +107,19 @@ Three things this card does not claim. 4. **Whether a lead sees them.** The pick: no, as today. `bid_day_entries` is read by the person, a dev, payroll and the office, the owner's answer on card #445. 5. **A day in two sessions.** The picture has one day cut in two, and the same list on both rows. The pick: each session shows the bids that fell inside its own hours, from the same bar, and a bid the person added by hand shows on the day's last session. +## The calls on the rest of My time (the person, 2026-12-03) + +The card drew none of the steps left, and its one rule was *kept* bids. Six calls were put to the person, each with a pick, and they pressed an answer to each. + +| The call | The answer | +|---|---| +| J1. What the Job Mode card's header shows while a person is on the clock on the office job. A list is kept at clock out, and the card then shows no session, so the *kept* rule would almost never change it. | **The bids of the day so far**, from the person's own list, kept or not. *Bids · 3* where the job's name was, and *On JP000 · Office* under it. With no bid yet it reads as before. | +| J2. Which bids count in that number. | **The bids the person changed**, the number clock out offers to keep. A kept list wins once there is one. | +| J3. A press on it. | **It opens the list**: *Your bids today* in a window over the card, with **Keep my list**. The pick put was no press. The person chose the press. | +| W1. What the week's office-job row on My time says. It is one row a job for the whole week, opened to the notes typed that week. | **Its label reads *Bids · 7*** with the office job on hover. Opened, it shows the typed notes with their hours as today, and one line of labels above them. **No hours on a bid**: that is punch list #475's question. | +| W2. A week where only some days kept a list. | **The row reads as bids when any of its days kept a list**, and counts the bids of those days. | +| W3. Punch list #473's gap line on the week's list. | **Not drawn there.** The week's list holds no two sessions side by side. #473's line about it is closed. | + ## Where it plugs in Almost all of it is client code. No table is new. The card first said one read might need a wider door, and step 1 checked it: the kept rows hold no times, so step 2a adds one column to `bid_day_entries` and `save_my_bid_day` takes it (*Where it stands*). @@ -168,7 +181,23 @@ Two things changed from the first plan while building it. **Step 3's second piece is built (v2.9194, 2026-12-02).** The day editor, opened from My Time or from People → Hours, draws the day's kept list above its timeline: the sentence, the bar and the labels (`MyTimeDayBids`). A pressed label says what was done and has no *Open the bid*, since leaving the window would drop an edit. On a person's own day the read is made only for the roles that work on bids. The session's job still reads as the office job there, since the job is a field a person can change. -**Left, in order:** the rest of My time (the Job Mode card, the week's office-job row reading as bids), a bid's own page, and the Schedule and Dispatch pages. +**The Job Mode step is built (v2.9282, 2026-12-03).** While the clock is on the office job, or on no job, the Job Mode card's header reads *Bids · 3 ›* where the job's name was and *On JP000 · Office* under it, for the roles that work on bids (`lib/jobMode/jobModeBids.ts`, `useJobModeBids`, `JobModeBidsPress`). The number is the clock out's own count of the day so far. A press opens *Your bids today* in a window, read when it opens, with **Keep my list · N bids**. The window is the one *Done for the day* opens (`BidDayKeepWindow`), with its own words. + +- **What it reads.** The office job's id once, and the person's own day when the card draws, after a clock press and after the window closes. Nothing is read for a session on a job in the field or on a bid, or for a role that does not work on bids. A read that fails leaves the job's header. +- **Chosen in the build, to be read by the owner.** The count is as fresh as the card's last read: it does not tick while the card sits open. The line *Not on today's schedule* stays under it where it stood before. A job whose papers are still owed keeps its masked header. The window takes the cursor when it opens and gives it back when it closes, and that now holds for *Done for the day*'s window too. +- **A words mend that rode with it.** My time's *Your bids today* said *or say what you did below* on an empty day, and nothing is below there. An empty list now names a note only on the clock out's sheet (`bidDayEmptyWords`). + +**The looks owed, none made.** View as keeps no bid trace, so each needs a real sign-in as a ZZ Test person who works on bids. That sign-in is the person's call and is open with them. + +1. *The Job Mode header (v2.9282).* Job Mode on, at 375 wide and at a desk. Clock in on the office job. The header names the office job. Open a ZZ Test bid on the Bids page, change one thing, and go back to the Dashboard. The header reads *Bids · 1 ›* with *On* and the office job under it. +2. Press it. *Your bids today* opens over the card with the ZZ Test bid ticked, and the cursor is in the window. **Close** closes it and the cursor is back on the press. +3. Press it again, then **Keep my list · 1 bid**. A green note says the list is kept. `bid_day_entries` holds one row for the day. +4. Clock in on a ZZ Test job in the field: the header names that job and no count shows. +5. On the Dashboard's My Time, on a day with no bid, *Your bids today* no longer says *or say what you did below*. +6. Delete the ZZ Test sessions and the kept row, or name them in the note. +7. *Still owed from before:* the clock-out list with two bids (F469-2), step 2a's rows with `seen` pairs, step 2b's bar under a session on People → Hours (v2.9189), and the day editor's block (v2.9194). + +**Left, in order:** the week's office-job row on My time reading as bids (answered above as W1 and W2), a bid's own page, and the Schedule and Dispatch pages. The calls for the last two are not put yet. **Other places that draw a session's note** still show a list written before v2.9158 as words: the pending cell's popover, the approvals queue, Align, the week's sessions window, the match window and the Dashboard's My Team. A follow-up, not this card's train. diff --git a/to-dos/clock-break/README.md b/to-dos/clock-break/README.md index e3cd311c9b..b2ea90f68d 100644 --- a/to-dos/clock-break/README.md +++ b/to-dos/clock-break/README.md @@ -13,7 +13,7 @@ summary: > of a day as one quiet line. next: The four live looks, each in its fragment under *The look owed*, and finding 866's look, under *Finding 866* on this card. Then the owner reads what steps 2, 3 and 4 chose that the card did not say (under *Left to do*). size: M as a train of four (M · S · S · S); left: none to build -blocker: Nothing to build. My time's week list draws no gap line yet: its rows belong to punch list #469's next piece, so the line there waits for that thread. +blocker: Nothing to build. My time's week list draws no gap line, by the person's answer of 2026-12-03 on punch list #469's call W3. opinion: build — both presses already exist as clock out and clock in, so the first step is small and gives her what she asked for --- @@ -120,7 +120,7 @@ Each step is one pull request with its release note, its fragment and its guide. - **Nothing is left to build.** Step 2 is PR #10699 and step 4 is v2.9217. - **The live looks** of step 1 (v2.9178), step 2 (PR #10699), step 3 (v2.9203) and step 4 (v2.9217). Each is in its fragment under *The look owed*. Steps 1, 3 and 4 are on a ZZ Test person with the live-write slot. Step 2 is read only unless a day has to be made. -- **The gap line on My time's week list.** Step 2 drew the line on People → Hours and in the My Time day editor. The rows of the week's detail (`DashboardMyTimeSection.tsx`) belong to punch list #469's next piece, so the line there waits for that thread. +- **The gap line on My time's week list: closed, not drawn.** Step 2 drew the line on People → Hours and in the My Time day editor. The week's detail (`DashboardMyTimeSection.tsx`) is one row a job for the whole week, so no two sessions sit side by side there. Asked on 2026-12-03 as punch list #469's call W3, the person pressed *No, close the line*. - **What step 2 chose that the card did not say.** People → Hours draws a day in lists by status, so the gaps are measured in the active, pending and approved lists together and the line sits beside the later session, with the person's name where it is not between its two sessions. A salaried person's scheduled lunch draws the line too, since the card said *any gap*. A list sorted by length draws none. - **What step 4 chose that the card did not say.** *Done for the day* ends the break first, at once. The day is read after that, and the list opens in a window of its own only when the day holds a bid. As built in v2.9217 an estimator got the window on an empty day too, by the clock out's rule. The walker met that on the live site (finding 866, below) and v2.9278 took the estimator's case out. A day with no bid and a read that fails draw nothing. The window can be closed without keeping, and My time still keeps the list later for the roles that have it there. - **What step 3 chose that the card did not say.** On Job Mode, Back to work is in a band under the card's header at a desk and on the bar's small row on a phone. Break is not offered there on the way to a job. A phone bar of six presses keeps two rows.