feat(rectification): 删掉年月录入卡,年月阶段打字回答且不被追问覆盖
Independent Staging Quality Gate / validate (push) Successful in 10m1s
Independent Staging Quality Gate / publish (push) Successful in 36m54s

This commit is contained in:
jesse-ux
2026-09-16 23:22:32 +08:00
parent abcfdac523
commit 6aabbe386f
49 changed files with 1035 additions and 431 deletions
@@ -1,119 +0,0 @@
"use client";
import { useMemo, useState } from "react";
import { EventDatePicker, type EventDateValue } from "@/components/event-date-picker";
import { Button } from "@/components/ui/button";
import {
COLLECT_KIND_ORDER,
GUIDED_ANY_DOMAIN,
type CollectKind,
type GuidedWindowDomain,
} from "@/lib/rectification-agentic/v9/collection-question-pool";
import { RANGE_DELIVERY_DOMAIN_LABEL } from "@/lib/rectification-agentic/user-copy";
export type EventDateEntrySubmit = Readonly<{
domain: CollectKind;
year: number;
month: number;
day: number | null;
}>;
/**
* BUG-750: the card already knows the date and the domain the user picked, so
* it states the one fact. The old text pasted the question's option list
* ("开始认真关系、分手或结婚"), which the ledger then stored as the summary.
*/
export function formatEventDateEntryMessage(input: EventDateEntrySubmit): string {
const when = input.day
? `${input.year} 年 ${input.month} 月 ${input.day} 日`
: `${input.year} 年 ${input.month} 月`;
const label = RANGE_DELIVERY_DOMAIN_LABEL[input.domain] ?? input.domain;
return `${when},${label}方面有一件事`;
}
export function eventDateYearRange(
birthYear: number | null | undefined,
nowYear = new Date().getFullYear(),
): { minYear: number; maxYear: number } {
const maxYear = nowYear;
if (typeof birthYear === "number" && birthYear >= 1900 && birthYear <= maxYear) {
return { minYear: birthYear, maxYear };
}
return { minYear: Math.max(1900, maxYear - 80), maxYear };
}
export function resolveEntryDomain(
domain: GuidedWindowDomain,
openDomains: readonly CollectKind[] = COLLECT_KIND_ORDER,
): CollectKind {
if (domain !== GUIDED_ANY_DOMAIN) return domain;
return openDomains[0] ?? COLLECT_KIND_ORDER[0];
}
export function EventDateEntryCard({
defaultDomain,
openDomains,
defaultYear,
defaultMonth,
minYear,
maxYear,
disabled = false,
onSubmit,
}: {
readonly defaultDomain: GuidedWindowDomain;
readonly openDomains?: readonly CollectKind[];
readonly defaultYear?: number;
readonly defaultMonth?: number;
readonly minYear: number;
readonly maxYear: number;
readonly disabled?: boolean;
readonly onSubmit: (value: EventDateEntrySubmit) => void;
}) {
const [domain, setDomain] = useState<CollectKind>(
resolveEntryDomain(defaultDomain, openDomains),
);
const initial = useMemo<EventDateValue | null>(() => {
if (!defaultYear || defaultYear < minYear || defaultYear > maxYear) return null;
const month = defaultMonth && defaultMonth >= 1 && defaultMonth <= 12 ? defaultMonth : 1;
return { year: defaultYear, month, day: null };
}, [defaultYear, defaultMonth, minYear, maxYear]);
const [date, setDate] = useState<EventDateValue | null>(initial);
return (
<form
className="rectification-event-entry"
onSubmit={(event) => {
event.preventDefault();
if (!date || disabled) return;
onSubmit({ domain, year: date.year, month: date.month, day: date.day });
}}
>
<p className="rectification-event-entry__label">哪一类事</p>
<div className="rectification-event-entry__chips" role="group" aria-label="经历类型">
{COLLECT_KIND_ORDER.map((kind) => (
<button
key={kind}
type="button"
className="rectification-event-entry__chip"
data-selected={kind === domain}
disabled={disabled}
onClick={() => setDomain(kind)}
>
{RANGE_DELIVERY_DOMAIN_LABEL[kind] ?? kind}
</button>
))}
</div>
<EventDatePicker
value={date}
minYear={minYear}
maxYear={maxYear}
disabled={disabled}
onChange={setDate}
/>
<Button type="submit" disabled={disabled || !date}>
记下这件
</Button>
</form>
);
}
@@ -1,105 +0,0 @@
"use client";
import { useId, useState } from "react";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
export type EventDateValue = Readonly<{
year: number;
month: number;
day: number | null;
}>;
type EventDatePickerProps = {
readonly value: EventDateValue | null;
readonly minYear: number;
readonly maxYear: number;
readonly disabled?: boolean;
readonly onChange: (value: EventDateValue) => void;
};
function clampYear(year: number, minYear: number, maxYear: number): number {
return Math.min(maxYear, Math.max(minYear, year));
}
function formatValue(value: EventDateValue | null): string {
if (!value) return "选择年月";
if (value.day) return `${value.year} 年 ${value.month} 月 ${value.day} 日`;
return `${value.year} 年 ${value.month} 月`;
}
export function EventDatePicker({
value,
minYear,
maxYear,
disabled = false,
onChange,
}: EventDatePickerProps) {
const labelId = useId();
const valueId = useId();
const [open, setOpen] = useState(false);
const selected = value
? new Date(value.year, value.month - 1, value.day ?? 1)
: undefined;
const startMonth = new Date(minYear, 0);
const endMonth = new Date(maxYear, 11);
return (
<div className="rectification-event-date">
<span id={labelId}>发生年月</span>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger
render={<Button
type="button"
variant="outline"
disabled={disabled}
aria-labelledby={`${labelId} ${valueId}`}
data-empty={!value}
className="w-full justify-start px-3 text-left font-normal data-[empty=true]:text-muted-foreground"
/>}
>
<span id={valueId}>{formatValue(value)}</span>
</PopoverTrigger>
<PopoverContent align="start" className="w-auto p-0">
<Calendar
key={value ? `${value.year}-${value.month}-${value.day ?? 0}` : "empty"}
mode="single"
className="[--cell-size:2.75rem] [&_button[data-selected-single=true]]:text-primary-foreground!"
selected={selected}
defaultMonth={selected ?? new Date(clampYear(maxYear - 10, minYear, maxYear), 0)}
captionLayout="dropdown"
navLayout="after"
startMonth={startMonth}
endMonth={endMonth}
reverseYears
disabled={{ before: new Date(minYear, 0, 1), after: new Date(maxYear, 11, 31) }}
onSelect={(nextDate) => {
if (nextDate === undefined) return;
onChange({
year: nextDate.getFullYear(),
month: nextDate.getMonth() + 1,
day: nextDate.getDate(),
});
}}
/>
<div className="rectification-event-date__footer">
<Button
type="button"
variant="ghost"
disabled={disabled || !value}
onClick={() => {
if (!value) return;
onChange({ year: value.year, month: value.month, day: null });
setOpen(false);
}}
>
只要年月
</Button>
</div>
</PopoverContent>
</Popover>
</div>
);
}
@@ -113,13 +113,6 @@ import {
import { ModelSelector } from "./model-selector";
import { RectificationBoard, RectificationBoardPeek } from "./rectification-board";
import { RectificationChoiceCard } from "./rectification-choice-card";
import {
EventDateEntryCard,
eventDateYearRange,
formatEventDateEntryMessage,
} from "./event-date-entry-card";
import { parseYearEntryQuestionId } from "@/lib/rectification-agentic/v9/collection-question-pool";
import { birthYearFromDate } from "@/lib/rectification-agentic/v9/adult-floor";
import {
applyLiveCandidateOffer,
copyTextForMessage,
@@ -1424,8 +1417,6 @@ export function RectificationAgenticChat(props: RectificationAgenticChatProps) {
answeredProbeCount: candidateResult?.answeredProbeCount ?? null,
datedEventCount: candidateResult?.rangeDelivery?.event_count ?? null,
});
const yearEntry = parseYearEntryQuestionId(currentQuestion?.question_id);
const yearRange = eventDateYearRange(birthYearFromDate(birthDate));
const persistedOfferKey = [...messages].reverse().find((message) => message.candidateOffer)?.renderKey;
const liveSelectionCardKey = persistedOfferKey
?? (canOfferCards && !candidateResult?.selectedTime ? latestSettledAssistant?.renderKey : undefined);
@@ -1739,7 +1730,7 @@ export function RectificationAgenticChat(props: RectificationAgenticChatProps) {
})}
{questionGap === "persisted_question" && currentQuestion?.prompt && (
<div className="rectification-message-wrap rectification-message-entry" data-testid="persisted-question">
<div className="rectification-message-question">
<div className="rectification-message-question is-standalone">
{persistedQuestionSurface({
questionKind: currentQuestion.kind,
hasChoiceCard: Boolean(choiceCard),
@@ -1758,21 +1749,6 @@ export function RectificationAgenticChat(props: RectificationAgenticChatProps) {
onStop={submitStop}
/>
</>
) : yearEntry ? (
<>
<p className="rectification-message-question__prompt">{currentQuestion.prompt}</p>
<EventDateEntryCard
defaultDomain={yearEntry.domain}
defaultYear={yearEntry.year ?? undefined}
defaultMonth={yearEntry.month ?? undefined}
minYear={yearRange.minYear}
maxYear={yearRange.maxYear}
disabled={busy || readonly}
onSubmit={(value) => {
void send("message", formatEventDateEntryMessage(value));
}}
/>
</>
) : (
<p className="rectification-message-question__prompt">{currentQuestion.prompt}</p>
)}