Show our own save-email error, and open review cards as the deck row view.
A bad address was stopped by the browser bubble before the designed line could appear. Final review opened every part of a method card at once instead of the three-row policy the decks use.
This commit is contained in:
1 parent
0efc907633
commit
7336cba6f5
13 files changed
+252
-663
No files matched your search
@@ -966,6 +966,7 @@ function CreateFlowLayoutContent({
|
||||
<form
|
||||
id={CREATE_FLOW_COMMUNITY_SAVE_FORM_ID}
|
||||
className="hidden"
|
||||
noValidate
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
markAttempted();
|
||||
@@ -1052,6 +1053,7 @@ function CreateFlowLayoutContent({
|
||||
<Button
|
||||
type="submit"
|
||||
form={CREATE_FLOW_COMMUNITY_SAVE_FORM_ID}
|
||||
formNoValidate
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
size="xsmall"
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@
|
||||
* (facet screens + final-review chip edit). When `onBlocksChange` is omitted,
|
||||
* blocks render read-only (disabled controls).
|
||||
*
|
||||
* Layout matches preset method editors ({@link CommunicationMethodEditFields},
|
||||
* {@link DecisionApproachEditFields}): {@link ModalTextAreaField},
|
||||
* Layout matches the deck policy editors: {@link ModalTextAreaField},
|
||||
* {@link ApplicableScopeField} chip rows, {@link IncrementerBlock}.
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
/**
|
||||
* Final-review chip modal: **Core values** use {@link ValueDialog} (Deselect +
|
||||
* Cancel + Save; kebab Customize / Duplicate under the cap). **Method** facets
|
||||
* keep `Create` with kebab Duplicate/Remove plus a footer **Remove** when the
|
||||
* chip is already in the selection. Values and method chips also offer
|
||||
* **Customize**, which opens {@link CustomMethodCardWizard} prefilled from the
|
||||
* chip. Fields are editable on open; Save persists body edits without renaming.
|
||||
* Cancel + Save; kebab Customize / Duplicate under the cap). **Method** chips
|
||||
* use {@link MethodCardPolicyDialog}, the same routing card as the decks: a
|
||||
* row per part, then that part's editor. Footer **Deselect** when the chip is
|
||||
* already selected; Save stays off until the draft changes. Values and method
|
||||
* chips also offer **Customize**, which opens {@link CustomMethodCardWizard}
|
||||
* prefilled from the chip.
|
||||
*
|
||||
* Template-only chips without an `overrideKey` never mount this component; they
|
||||
* use {@link TemplateChipDetailModal} from the parent.
|
||||
@@ -15,16 +16,15 @@
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import Create from "../../../components/modals/Create";
|
||||
import ContentLockup from "../../../components/type/ContentLockup";
|
||||
import { useMessages, useTranslation } from "../../../contexts/MessagesContext";
|
||||
import {
|
||||
CommunicationMethodEditFields,
|
||||
ConflictManagementEditFields,
|
||||
DecisionApproachEditFields,
|
||||
MembershipMethodEditFields,
|
||||
} from "./methodEditFields";
|
||||
import { useMessages } from "../../../contexts/MessagesContext";
|
||||
import { ValueDialog } from "./ValueDialog";
|
||||
import { MethodCardPolicyDialog } from "./MethodCardPolicyDialog";
|
||||
import {
|
||||
useCommunicationPolicySteps,
|
||||
useConflictPolicySteps,
|
||||
useDecisionApproachPolicySteps,
|
||||
useMembershipPolicySteps,
|
||||
} from "./methodCardPolicySteps";
|
||||
import CustomMethodCardModalBody from "./CustomMethodCardModalBody";
|
||||
import { buildCustomRuleModalKebabMenu } from "./customRuleModalKebabMenu";
|
||||
import { useDiscardCustomizeConfirm } from "../hooks/useDiscardCustomizeConfirm";
|
||||
@@ -187,9 +187,6 @@ export function FinalReviewChipEditModal({
|
||||
const tDa = cr.decisionApproaches;
|
||||
const tCm = cr.conflictManagement;
|
||||
const modalKebabMenu = cr.modalKebabMenu;
|
||||
const tModal = useTranslation(
|
||||
"create.reviewAndComplete.finalReview.chipEditModal",
|
||||
);
|
||||
const { confirmDiscard, confirmDialog } = useDiscardCustomizeConfirm();
|
||||
|
||||
const [draft, setDraft] = useState<Draft | null>(null);
|
||||
@@ -831,6 +828,7 @@ export function FinalReviewChipEditModal({
|
||||
const facet = CUSTOM_RULE_FACET_BY_GROUP.get(target.groupKey)!;
|
||||
const pendingId = target.overrideKey;
|
||||
const sel = [...facet.selectionIds(state)];
|
||||
if (sel.includes(pendingId) && methodCustomizeSaveDisabled) return;
|
||||
onInteract?.();
|
||||
|
||||
const persistWizardBlocks = draftFieldBlocks !== null;
|
||||
@@ -906,6 +904,7 @@ export function FinalReviewChipEditModal({
|
||||
draft,
|
||||
draftFieldBlocks,
|
||||
finalizeModalClose,
|
||||
methodCustomizeSaveDisabled,
|
||||
onInteract,
|
||||
onSave,
|
||||
replaceState,
|
||||
@@ -1044,44 +1043,48 @@ export function FinalReviewChipEditModal({
|
||||
],
|
||||
);
|
||||
|
||||
const handleNext = useCallback(() => {
|
||||
if (!target || !draft) return;
|
||||
if (target.groupKey === "coreValues") {
|
||||
handleCoreSave();
|
||||
} else {
|
||||
handleMethodPrimary();
|
||||
}
|
||||
}, [draft, handleCoreSave, handleMethodPrimary, target]);
|
||||
|
||||
const nextButtonText = useMemo(() => {
|
||||
if (!target) return tModal("saveButton");
|
||||
if (target.groupKey === "coreValues") {
|
||||
return tModal("saveButton");
|
||||
}
|
||||
if (!isChipInSelection) {
|
||||
return addPrimaryLabelForMethodFacet(target.groupKey, cr);
|
||||
}
|
||||
return tModal("saveButton");
|
||||
}, [cr, isChipInSelection, target, tModal]);
|
||||
|
||||
const headerContent = useMemo(() => {
|
||||
if (!target) return undefined;
|
||||
return (
|
||||
<div className="bg-[var(--color-surface-default-primary)] px-[24px] py-[12px] shrink-0">
|
||||
<ContentLockup
|
||||
title={target.chipLabel}
|
||||
description={subtitle}
|
||||
variant="modal"
|
||||
alignment="left"
|
||||
/>
|
||||
</div>
|
||||
const communicationSteps = useCommunicationPolicySteps(
|
||||
draft?.groupKey === "communication"
|
||||
? draft.value
|
||||
: emptyCommunicationDetails(),
|
||||
(value) => setDraft({ groupKey: "communication", value }),
|
||||
target?.groupKey === "communication"
|
||||
? communicationPresetFor(target.overrideKey)
|
||||
: undefined,
|
||||
);
|
||||
}, [subtitle, target]);
|
||||
|
||||
const showFooterRemove =
|
||||
target != null &&
|
||||
target.groupKey !== "coreValues" &&
|
||||
isChipInSelection;
|
||||
const membershipSteps = useMembershipPolicySteps(
|
||||
draft?.groupKey === "membership" ? draft.value : emptyMembershipDetails(),
|
||||
(value) => setDraft({ groupKey: "membership", value }),
|
||||
target?.groupKey === "membership"
|
||||
? membershipPresetFor(target.overrideKey)
|
||||
: undefined,
|
||||
);
|
||||
const decisionSteps = useDecisionApproachPolicySteps(
|
||||
draft?.groupKey === "decisionApproaches"
|
||||
? draft.value
|
||||
: emptyDecisionApproachTextFields(decisionApproachPresetFor("")),
|
||||
(value) => setDraft({ groupKey: "decisionApproaches", value }),
|
||||
target?.groupKey === "decisionApproaches"
|
||||
? decisionApproachPresetFor(target.overrideKey)
|
||||
: undefined,
|
||||
);
|
||||
const conflictSteps = useConflictPolicySteps(
|
||||
draft?.groupKey === "conflictManagement"
|
||||
? draft.value
|
||||
: emptyConflictManagementDetails(),
|
||||
(value) => setDraft({ groupKey: "conflictManagement", value }),
|
||||
target?.groupKey === "conflictManagement"
|
||||
? conflictManagementPresetFor(target.overrideKey)
|
||||
: undefined,
|
||||
);
|
||||
const methodSteps =
|
||||
draft?.groupKey === "membership"
|
||||
? membershipSteps
|
||||
: draft?.groupKey === "decisionApproaches"
|
||||
? decisionSteps
|
||||
: draft?.groupKey === "conflictManagement"
|
||||
? conflictSteps
|
||||
: communicationSteps;
|
||||
|
||||
const isCoreValuesTarget = target?.groupKey === "coreValues";
|
||||
const coreDraftValue =
|
||||
@@ -1103,7 +1106,7 @@ export function FinalReviewChipEditModal({
|
||||
onClose={() => {
|
||||
void handleModalClose();
|
||||
}}
|
||||
onConfirm={handleNext}
|
||||
onConfirm={handleCoreSave}
|
||||
onDeselect={handleRemoveCoreValueFromModal}
|
||||
nextButtonDisabled={coreCustomizeSaveDisabled}
|
||||
kebabTriggerAriaLabel={modalKebabMenu.triggerAriaLabel}
|
||||
@@ -1131,49 +1134,43 @@ export function FinalReviewChipEditModal({
|
||||
/>
|
||||
) : undefined}
|
||||
</ValueDialog>
|
||||
<Create
|
||||
isOpen={
|
||||
isOpen && !addCustomWizardOpen && !isCoreValuesTarget
|
||||
<MethodCardPolicyDialog
|
||||
isOpen={isOpen && !addCustomWizardOpen && !isCoreValuesTarget}
|
||||
cardLabel={target?.chipLabel ?? ""}
|
||||
description={subtitle}
|
||||
editing={isChipInSelection}
|
||||
steps={methodSteps}
|
||||
onClose={() => {
|
||||
void handleModalClose();
|
||||
}}
|
||||
onConfirm={handleMethodPrimary}
|
||||
onDeselect={
|
||||
isChipInSelection
|
||||
? () => {
|
||||
void handleRemoveSelectedFromModal();
|
||||
}
|
||||
onClose={handleModalClose}
|
||||
onBack={handleModalClose}
|
||||
showBackButton={!showFooterRemove}
|
||||
showRemoveButton={showFooterRemove}
|
||||
onRemove={
|
||||
target?.groupKey === "coreValues"
|
||||
? handleRemoveCoreValueFromModal
|
||||
: handleRemoveSelectedFromModal
|
||||
}
|
||||
backdropVariant="blurredYellow"
|
||||
headerContent={headerContent}
|
||||
showNextButton={true}
|
||||
onNext={handleNext}
|
||||
nextButtonText={nextButtonText}
|
||||
nextButtonDisabled={
|
||||
target?.groupKey === "coreValues"
|
||||
? coreCustomizeSaveDisabled
|
||||
: methodCustomizeSaveDisabled
|
||||
: undefined
|
||||
}
|
||||
confirmDisabled={isChipInSelection && methodCustomizeSaveDisabled}
|
||||
kebabTriggerAriaLabel={modalKebabMenu.triggerAriaLabel}
|
||||
kebabMenuAriaLabel={modalKebabMenu.menuAriaLabel}
|
||||
kebabMenuItems={
|
||||
target && kebabMenuItems.length > 0 ? kebabMenuItems : undefined
|
||||
target && !isCoreValuesTarget && kebabMenuItems.length > 0
|
||||
? kebabMenuItems
|
||||
: undefined
|
||||
}
|
||||
ariaLabel={target?.chipLabel || "Edit chip details"}
|
||||
>
|
||||
<div className="flex flex-col gap-[var(--space-600)] pb-2">
|
||||
{draft?.groupKey === "communication" &&
|
||||
{modalUsesWizardFieldBlocksBody &&
|
||||
target &&
|
||||
(modalUsesWizardFieldBlocksBody ? (
|
||||
isMethodFacetGroup(target.groupKey) ? (
|
||||
<CustomMethodCardModalBody
|
||||
cardId={target.overrideKey}
|
||||
blocksById={state.customMethodCardFieldBlocksById}
|
||||
blocksOverride={
|
||||
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
||||
}
|
||||
policyMeta={
|
||||
state.customMethodCardMetaById?.[target.overrideKey]
|
||||
}
|
||||
policyMeta={state.customMethodCardMetaById?.[target.overrideKey]}
|
||||
showPolicyContentLockupWhenNoBlocks={false}
|
||||
onFieldBlocksChange={
|
||||
draftFieldBlocks === null
|
||||
@@ -1181,101 +1178,8 @@ export function FinalReviewChipEditModal({
|
||||
: handleWizardFieldBlocksChange
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<CommunicationMethodEditFields
|
||||
value={draft.value}
|
||||
onChange={(value) =>
|
||||
setDraft({ groupKey: "communication", value })
|
||||
}
|
||||
generateDraft={communicationPresetFor(target.overrideKey)}
|
||||
/>
|
||||
))}
|
||||
{draft?.groupKey === "membership" &&
|
||||
target &&
|
||||
(modalUsesWizardFieldBlocksBody ? (
|
||||
<CustomMethodCardModalBody
|
||||
cardId={target.overrideKey}
|
||||
blocksById={state.customMethodCardFieldBlocksById}
|
||||
blocksOverride={
|
||||
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
||||
}
|
||||
policyMeta={
|
||||
state.customMethodCardMetaById?.[target.overrideKey]
|
||||
}
|
||||
showPolicyContentLockupWhenNoBlocks={false}
|
||||
onFieldBlocksChange={
|
||||
draftFieldBlocks === null
|
||||
? undefined
|
||||
: handleWizardFieldBlocksChange
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<MembershipMethodEditFields
|
||||
value={draft.value}
|
||||
onChange={(value) =>
|
||||
setDraft({ groupKey: "membership", value })
|
||||
}
|
||||
generateDraft={membershipPresetFor(target.overrideKey)}
|
||||
/>
|
||||
))}
|
||||
{draft?.groupKey === "decisionApproaches" &&
|
||||
target &&
|
||||
(modalUsesWizardFieldBlocksBody ? (
|
||||
<CustomMethodCardModalBody
|
||||
cardId={target.overrideKey}
|
||||
blocksById={state.customMethodCardFieldBlocksById}
|
||||
blocksOverride={
|
||||
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
||||
}
|
||||
policyMeta={
|
||||
state.customMethodCardMetaById?.[target.overrideKey]
|
||||
}
|
||||
showPolicyContentLockupWhenNoBlocks={false}
|
||||
onFieldBlocksChange={
|
||||
draftFieldBlocks === null
|
||||
? undefined
|
||||
: handleWizardFieldBlocksChange
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<DecisionApproachEditFields
|
||||
value={draft.value}
|
||||
onChange={(value) =>
|
||||
setDraft({ groupKey: "decisionApproaches", value })
|
||||
}
|
||||
generateDraft={decisionApproachPresetFor(target.overrideKey)}
|
||||
/>
|
||||
))}
|
||||
{draft?.groupKey === "conflictManagement" &&
|
||||
target &&
|
||||
(modalUsesWizardFieldBlocksBody ? (
|
||||
<CustomMethodCardModalBody
|
||||
cardId={target.overrideKey}
|
||||
blocksById={state.customMethodCardFieldBlocksById}
|
||||
blocksOverride={
|
||||
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
||||
}
|
||||
policyMeta={
|
||||
state.customMethodCardMetaById?.[target.overrideKey]
|
||||
}
|
||||
showPolicyContentLockupWhenNoBlocks={false}
|
||||
onFieldBlocksChange={
|
||||
draftFieldBlocks === null
|
||||
? undefined
|
||||
: handleWizardFieldBlocksChange
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<ConflictManagementEditFields
|
||||
value={draft.value}
|
||||
onChange={(value) =>
|
||||
setDraft({ groupKey: "conflictManagement", value })
|
||||
}
|
||||
generateDraft={conflictManagementPresetFor(target.overrideKey)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Create>
|
||||
) : null}
|
||||
</MethodCardPolicyDialog>
|
||||
<CustomMethodCardWizard
|
||||
isOpen={addCustomWizardOpen}
|
||||
onClose={handleCloseAddWizard}
|
||||
@@ -1336,22 +1240,6 @@ function facetSeedSignature(
|
||||
}
|
||||
}
|
||||
|
||||
function addPrimaryLabelForMethodFacet(
|
||||
groupKey: MethodFacetGroupKey,
|
||||
cr: ReturnType<typeof useMessages>["create"]["customRule"],
|
||||
): string {
|
||||
switch (groupKey) {
|
||||
case "communication":
|
||||
return cr.communication.addPlatform.nextButtonText;
|
||||
case "membership":
|
||||
return cr.membership.addPlatform.nextButtonText;
|
||||
case "decisionApproaches":
|
||||
return cr.decisionApproaches.addApproach.nextButtonText;
|
||||
case "conflictManagement":
|
||||
return cr.conflictManagement.addApproach.nextButtonText;
|
||||
}
|
||||
}
|
||||
|
||||
function seedDraftForTarget(
|
||||
target: FinalReviewChipEditTarget,
|
||||
state: CreateFlowState,
|
||||
|
||||
@@ -36,6 +36,11 @@ export type MethodCardPolicyDialogProps = {
|
||||
ariaLabel?: string;
|
||||
/** Customized field-blocks body. Replaces the routing steps. */
|
||||
children?: ReactNode;
|
||||
/**
|
||||
* Disables the routing-view primary action (Add to Rule / Save).
|
||||
* A step's own Save stays enabled so the reader can return to the rows.
|
||||
*/
|
||||
confirmDisabled?: boolean;
|
||||
};
|
||||
|
||||
function MethodCardPolicyDialogComponent({
|
||||
@@ -52,6 +57,7 @@ function MethodCardPolicyDialogComponent({
|
||||
kebabMenuItems,
|
||||
ariaLabel,
|
||||
children,
|
||||
confirmDisabled = false,
|
||||
}: MethodCardPolicyDialogProps) {
|
||||
const m = useMessages();
|
||||
const t = m.create.customRule.cardDialog;
|
||||
@@ -104,6 +110,7 @@ function MethodCardPolicyDialogComponent({
|
||||
onRemove={onDeselect}
|
||||
cancelButtonText={t.cancel}
|
||||
nextButtonText={primaryLabel}
|
||||
nextButtonDisabled={activeStepId == null && confirmDisabled}
|
||||
removeButtonText={t.deselect}
|
||||
stepper={false}
|
||||
backdropVariant="blurredYellow"
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Controlled section editor for a communication-method chip. Used by both
|
||||
* the custom-rule `communication-methods` add-method modal and the
|
||||
* `final-review` chip edit modal — caller owns draft state and decides when
|
||||
* to persist or discard.
|
||||
*/
|
||||
|
||||
import { memo, useCallback } from "react";
|
||||
import { useMessages } from "../../../../contexts/MessagesContext";
|
||||
import ModalTextAreaField from "../ModalTextAreaField";
|
||||
import type { CommunicationMethodDetailEntry } from "../../types";
|
||||
|
||||
export interface CommunicationMethodEditFieldsProps {
|
||||
value: CommunicationMethodDetailEntry;
|
||||
onChange: (_next: CommunicationMethodDetailEntry) => void;
|
||||
/** When true, fields are not editable (view mode). */
|
||||
readOnly?: boolean;
|
||||
/** Catalog copy inserted by Generate draft. */
|
||||
generateDraft?: CommunicationMethodDetailEntry;
|
||||
}
|
||||
|
||||
const FIELDS: ReadonlyArray<keyof CommunicationMethodDetailEntry> = [
|
||||
"corePrinciple",
|
||||
"logisticsAdmin",
|
||||
"codeOfConduct",
|
||||
];
|
||||
|
||||
function CommunicationMethodEditFieldsComponent({
|
||||
value,
|
||||
onChange,
|
||||
readOnly = false,
|
||||
generateDraft,
|
||||
}: CommunicationMethodEditFieldsProps) {
|
||||
const m = useMessages();
|
||||
const t = m.create.customRule.communication;
|
||||
const draftField = m.create.draftField;
|
||||
|
||||
const patch = useCallback(
|
||||
<K extends keyof CommunicationMethodDetailEntry>(
|
||||
key: K,
|
||||
next: CommunicationMethodDetailEntry[K],
|
||||
) => {
|
||||
onChange({ ...value, [key]: next });
|
||||
},
|
||||
[value, onChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{FIELDS.map((field) => (
|
||||
<ModalTextAreaField
|
||||
key={field}
|
||||
label={t.sectionHeadings[field]}
|
||||
rows={6}
|
||||
value={value[field]}
|
||||
onChange={(v) => patch(field, v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.[field]}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
CommunicationMethodEditFieldsComponent.displayName =
|
||||
"CommunicationMethodEditFields";
|
||||
|
||||
export default memo(CommunicationMethodEditFieldsComponent);
|
||||
@@ -1,121 +0,0 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Controlled section editor for a conflict-management chip. Used by both the
|
||||
* custom-rule `conflict-management` add-method modal and the `final-review`
|
||||
* chip edit modal. Caller owns draft state and persistence.
|
||||
*/
|
||||
|
||||
import { memo, useCallback } from "react";
|
||||
import { formatConflictApplicableScopeForTextarea } from "../../../../../lib/create/ruleSectionsFromMethodSelections";
|
||||
import { useMessages } from "../../../../contexts/MessagesContext";
|
||||
import ModalTextAreaField from "../ModalTextAreaField";
|
||||
import type { ConflictManagementDetailEntry } from "../../types";
|
||||
|
||||
function conflictScopeTextareaValue(value: ConflictManagementDetailEntry): string {
|
||||
return formatConflictApplicableScopeForTextarea(
|
||||
value.selectedApplicableScope,
|
||||
value.applicableScope,
|
||||
);
|
||||
}
|
||||
|
||||
function conflictDetailWithScopeTextarea(
|
||||
value: ConflictManagementDetailEntry,
|
||||
text: string,
|
||||
): ConflictManagementDetailEntry {
|
||||
const lines = text
|
||||
.split("\n")
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0);
|
||||
return {
|
||||
...value,
|
||||
applicableScope: lines,
|
||||
selectedApplicableScope: [...lines],
|
||||
};
|
||||
}
|
||||
|
||||
export interface ConflictManagementEditFieldsProps {
|
||||
value: ConflictManagementDetailEntry;
|
||||
onChange: (_next: ConflictManagementDetailEntry) => void;
|
||||
readOnly?: boolean;
|
||||
/** Catalog copy inserted by Generate draft. */
|
||||
generateDraft?: ConflictManagementDetailEntry;
|
||||
}
|
||||
|
||||
function ConflictManagementEditFieldsComponent({
|
||||
value,
|
||||
onChange,
|
||||
readOnly = false,
|
||||
generateDraft,
|
||||
}: ConflictManagementEditFieldsProps) {
|
||||
const m = useMessages();
|
||||
const t = m.create.customRule.conflictManagement;
|
||||
const draftField = m.create.draftField;
|
||||
|
||||
const patch = useCallback(
|
||||
<K extends keyof ConflictManagementDetailEntry>(
|
||||
key: K,
|
||||
next: ConflictManagementDetailEntry[K],
|
||||
) => {
|
||||
onChange({ ...value, [key]: next });
|
||||
},
|
||||
[value, onChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.corePrinciple}
|
||||
value={value.corePrinciple}
|
||||
onChange={(v) => patch("corePrinciple", v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.corePrinciple}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.applicableScope}
|
||||
value={conflictScopeTextareaValue(value)}
|
||||
placeholder={t.applicableScopePlaceholder}
|
||||
onChange={(v) => onChange(conflictDetailWithScopeTextarea(value, v))}
|
||||
rows={4}
|
||||
disabled={readOnly}
|
||||
generateDraftText={
|
||||
generateDraft && generateDraft.applicableScope.length > 0
|
||||
? generateDraft.applicableScope.join("\n")
|
||||
: generateDraft
|
||||
? conflictScopeTextareaValue(generateDraft)
|
||||
: undefined
|
||||
}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.processProtocol}
|
||||
value={value.processProtocol}
|
||||
onChange={(v) => patch("processProtocol", v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.processProtocol}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.restorationFallbacks}
|
||||
value={value.restorationFallbacks}
|
||||
onChange={(v) => patch("restorationFallbacks", v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.restorationFallbacks}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
ConflictManagementEditFieldsComponent.displayName =
|
||||
"ConflictManagementEditFields";
|
||||
|
||||
export default memo(ConflictManagementEditFieldsComponent);
|
||||
@@ -1,137 +0,0 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Controlled section editor for a decision-approach chip. Used by both the
|
||||
* custom-rule `decision-approaches` add-method modal and the `final-review`
|
||||
* chip edit modal. Caller owns draft state — Confirm/Save persistence and
|
||||
* `markCreateFlowInteraction` live in the parent.
|
||||
*/
|
||||
|
||||
import { memo, useCallback, useMemo } from "react";
|
||||
import { useMessages } from "../../../../contexts/MessagesContext";
|
||||
import ModalTextAreaField from "../ModalTextAreaField";
|
||||
import ApplicableScopeField from "../ApplicableScopeField";
|
||||
import IncrementerBlock from "../../../../components/controls/IncrementerBlock";
|
||||
import type { DecisionApproachDetailEntry } from "../../types";
|
||||
import { withDecisionApproachKeyResourceScopes } from "../../../../../lib/create/decisionApproachKeyResources";
|
||||
|
||||
export interface DecisionApproachEditFieldsProps {
|
||||
value: DecisionApproachDetailEntry;
|
||||
onChange: (_next: DecisionApproachDetailEntry) => void;
|
||||
readOnly?: boolean;
|
||||
/** Catalog copy inserted by Generate draft on text fields. */
|
||||
generateDraft?: DecisionApproachDetailEntry;
|
||||
}
|
||||
|
||||
const CONSENSUS_LEVEL_MIN = 0;
|
||||
const CONSENSUS_LEVEL_MAX = 100;
|
||||
const CONSENSUS_LEVEL_STEP = 5;
|
||||
|
||||
function DecisionApproachEditFieldsComponent({
|
||||
value,
|
||||
onChange,
|
||||
readOnly = false,
|
||||
generateDraft,
|
||||
}: DecisionApproachEditFieldsProps) {
|
||||
const m = useMessages();
|
||||
const t = m.create.customRule.decisionApproaches;
|
||||
const draftField = m.create.draftField;
|
||||
|
||||
const scopes = useMemo(
|
||||
() => withDecisionApproachKeyResourceScopes(value.applicableScope),
|
||||
[value.applicableScope],
|
||||
);
|
||||
|
||||
const patch = useCallback(
|
||||
<K extends keyof DecisionApproachDetailEntry>(
|
||||
key: K,
|
||||
next: DecisionApproachDetailEntry[K],
|
||||
) => {
|
||||
onChange({ ...value, [key]: next });
|
||||
},
|
||||
[value, onChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.corePrinciple}
|
||||
value={value.corePrinciple}
|
||||
onChange={(v) => patch("corePrinciple", v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.corePrinciple}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
<ApplicableScopeField
|
||||
label={t.sectionHeadings.applicableScope}
|
||||
addLabel={t.scopeAddButtonLabel}
|
||||
scopes={scopes}
|
||||
selectedScopes={value.selectedApplicableScope}
|
||||
readOnly={readOnly}
|
||||
onToggleScope={(scope) =>
|
||||
patch(
|
||||
"selectedApplicableScope",
|
||||
value.selectedApplicableScope.includes(scope)
|
||||
? value.selectedApplicableScope.filter((s) => s !== scope)
|
||||
: [...value.selectedApplicableScope, scope],
|
||||
)
|
||||
}
|
||||
onAddScope={(scope) =>
|
||||
patch("applicableScope", [...value.applicableScope, scope])
|
||||
}
|
||||
/>
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.stepByStepInstructions}
|
||||
value={value.stepByStepInstructions}
|
||||
onChange={(v) => patch("stepByStepInstructions", v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.stepByStepInstructions}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
{value.consensusLevel === undefined ? (
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.consensusLevel}
|
||||
value={t.consensusLevelDisplay.supermajorityShare}
|
||||
onChange={() => {}}
|
||||
disabled
|
||||
rows={1}
|
||||
/>
|
||||
) : (
|
||||
<IncrementerBlock
|
||||
label={t.sectionHeadings.consensusLevel}
|
||||
helpIcon={false}
|
||||
value={value.consensusLevel}
|
||||
min={CONSENSUS_LEVEL_MIN}
|
||||
max={CONSENSUS_LEVEL_MAX}
|
||||
step={CONSENSUS_LEVEL_STEP}
|
||||
onChange={(next) => patch("consensusLevel", next)}
|
||||
formatValue={(v) =>
|
||||
v === 0 ? t.consensusLevelDisplay.noSetShare : `${v}%`
|
||||
}
|
||||
decrementAriaLabel="Decrease consensus level"
|
||||
incrementAriaLabel="Increase consensus level"
|
||||
disabled={readOnly}
|
||||
/>
|
||||
)}
|
||||
<ModalTextAreaField
|
||||
label={t.sectionHeadings.objectionsDeadlocks}
|
||||
value={value.objectionsDeadlocks}
|
||||
onChange={(v) => patch("objectionsDeadlocks", v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.objectionsDeadlocks}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
DecisionApproachEditFieldsComponent.displayName =
|
||||
"DecisionApproachEditFields";
|
||||
|
||||
export default memo(DecisionApproachEditFieldsComponent);
|
||||
@@ -1,72 +0,0 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Controlled section editor for a membership-method chip. Used by both the
|
||||
* custom-rule `membership-methods` add-method modal and the `final-review`
|
||||
* chip edit modal — caller owns draft state and decides when to persist or
|
||||
* discard.
|
||||
*/
|
||||
|
||||
import { memo, useCallback } from "react";
|
||||
import { useMessages } from "../../../../contexts/MessagesContext";
|
||||
import ModalTextAreaField from "../ModalTextAreaField";
|
||||
import type { MembershipMethodDetailEntry } from "../../types";
|
||||
|
||||
export interface MembershipMethodEditFieldsProps {
|
||||
value: MembershipMethodDetailEntry;
|
||||
onChange: (_next: MembershipMethodDetailEntry) => void;
|
||||
readOnly?: boolean;
|
||||
/** Catalog copy inserted by Generate draft. */
|
||||
generateDraft?: MembershipMethodDetailEntry;
|
||||
}
|
||||
|
||||
const FIELDS: ReadonlyArray<keyof MembershipMethodDetailEntry> = [
|
||||
"eligibility",
|
||||
"joiningProcess",
|
||||
"expectations",
|
||||
];
|
||||
|
||||
function MembershipMethodEditFieldsComponent({
|
||||
value,
|
||||
onChange,
|
||||
readOnly = false,
|
||||
generateDraft,
|
||||
}: MembershipMethodEditFieldsProps) {
|
||||
const m = useMessages();
|
||||
const t = m.create.customRule.membership;
|
||||
const draftField = m.create.draftField;
|
||||
|
||||
const patch = useCallback(
|
||||
<K extends keyof MembershipMethodDetailEntry>(
|
||||
key: K,
|
||||
next: MembershipMethodDetailEntry[K],
|
||||
) => {
|
||||
onChange({ ...value, [key]: next });
|
||||
},
|
||||
[value, onChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{FIELDS.map((field) => (
|
||||
<ModalTextAreaField
|
||||
key={field}
|
||||
label={t.sectionHeadings[field]}
|
||||
rows={6}
|
||||
value={value[field]}
|
||||
onChange={(v) => patch(field, v)}
|
||||
disabled={readOnly}
|
||||
placeholder={draftField.placeholder}
|
||||
generateDraftText={generateDraft?.[field]}
|
||||
generateDraftLabel={draftField.generateDraft}
|
||||
generateDraftHint={draftField.generateDraftHint}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
MembershipMethodEditFieldsComponent.displayName =
|
||||
"MembershipMethodEditFields";
|
||||
|
||||
export default memo(MembershipMethodEditFieldsComponent);
|
||||
@@ -1,11 +0,0 @@
|
||||
export { default as CommunicationMethodEditFields } from "./CommunicationMethodEditFields";
|
||||
export type { CommunicationMethodEditFieldsProps } from "./CommunicationMethodEditFields";
|
||||
|
||||
export { default as MembershipMethodEditFields } from "./MembershipMethodEditFields";
|
||||
export type { MembershipMethodEditFieldsProps } from "./MembershipMethodEditFields";
|
||||
|
||||
export { default as DecisionApproachEditFields } from "./DecisionApproachEditFields";
|
||||
export type { DecisionApproachEditFieldsProps } from "./DecisionApproachEditFields";
|
||||
|
||||
export { default as ConflictManagementEditFields } from "./ConflictManagementEditFields";
|
||||
export type { ConflictManagementEditFieldsProps } from "./ConflictManagementEditFields";
|
||||
@@ -86,12 +86,13 @@ export function FinalReviewScreen({
|
||||
/**
|
||||
* Two modals coexist on this screen:
|
||||
*
|
||||
* - {@link FinalReviewChipEditModal} — core values + method chips: footer
|
||||
* **Remove** when the chip is already selected, plus kebab **Remove**;
|
||||
* - {@link FinalReviewChipEditModal} — core values use the value card;
|
||||
* method chips use the deck's routing card (a row per part). Footer
|
||||
* **Deselect** when the chip is already selected, plus kebab **Remove**;
|
||||
* values also offer Duplicate under the five-chip cap; method chips
|
||||
* offer Customize (prefilled custom-policy wizard). Fields are editable on
|
||||
* open. Save writes `{group}DetailsById` and field blocks; wizard Finalize
|
||||
* also writes `customMethodCardMetaById`.
|
||||
* offer Customize (prefilled custom-policy wizard). Save writes
|
||||
* `{group}DetailsById` and field blocks; wizard Finalize also writes
|
||||
* `customMethodCardMetaById`.
|
||||
* - {@link TemplateChipDetailModal} — read-only fallback for chips we
|
||||
* can't map to an override key (e.g. template body entries on the
|
||||
* "Use without changes" path where no preset matches the title).
|
||||
|
||||
@@ -59,7 +59,7 @@ function ScreenWithStateProbe({
|
||||
/**
|
||||
* Confirms the persistence half of the Add-Platform flow that lets the
|
||||
* final-review chip edit modal start from a known seed instead of always
|
||||
* snapping back to preset copy. See {@link CommunicationMethodEditFields}
|
||||
* snapping back to preset copy. See {@link MethodCardPolicyDialog}
|
||||
* and `buildPublishPayload` for the read side.
|
||||
*/
|
||||
const COMMUNICATION_STEPS = [
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import CreateFlowLayoutClient from "../../app/(app)/create/CreateFlowLayoutClient";
|
||||
import { CreateFlowTextFieldScreen } from "../../app/(app)/create/screens/text/CreateFlowTextFieldScreen";
|
||||
import { CREATE_FLOW_COMMUNITY_SAVE_FORM_ID } from "../../app/(app)/create/utils/createFlowPaths";
|
||||
import {
|
||||
cleanup,
|
||||
renderWithProviders as render,
|
||||
screen,
|
||||
waitFor,
|
||||
} from "../utils/test-utils";
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
back: vi.fn(),
|
||||
}),
|
||||
usePathname: () => "/create/community-save",
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
}));
|
||||
|
||||
const errorCopy = "Check your email address. We need it to send your link.";
|
||||
|
||||
function renderSaveStep() {
|
||||
return render(
|
||||
<CreateFlowLayoutClient>
|
||||
<CreateFlowTextFieldScreen
|
||||
messageNamespace="create.community.communitySave"
|
||||
stateField="communitySaveEmail"
|
||||
maxLength={254}
|
||||
inputType="email"
|
||||
showCharacterCount={false}
|
||||
/>
|
||||
</CreateFlowLayoutClient>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("community-save email", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("shows the designed error for an address the browser would reject", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () =>
|
||||
new Response(JSON.stringify({ user: null }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}),
|
||||
),
|
||||
);
|
||||
renderSaveStep();
|
||||
|
||||
const form = await waitFor(() => {
|
||||
const node = document.getElementById(CREATE_FLOW_COMMUNITY_SAVE_FORM_ID);
|
||||
expect(node).not.toBeNull();
|
||||
return node as HTMLFormElement;
|
||||
});
|
||||
expect(form).toHaveAttribute("novalidate");
|
||||
|
||||
const input = screen.getByRole("textbox", { name: "Email address" });
|
||||
fireEvent.change(input, { target: { value: "not-an-email" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Submit email" }));
|
||||
|
||||
expect(await screen.findByText(errorCopy)).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Submit email" })).toHaveAttribute(
|
||||
"formnovalidate",
|
||||
);
|
||||
});
|
||||
|
||||
it("shows the same error for an address with no dot in the domain", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () =>
|
||||
new Response(JSON.stringify({ user: null }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}),
|
||||
),
|
||||
);
|
||||
renderSaveStep();
|
||||
const input = await screen.findByRole("textbox", { name: "Email address" });
|
||||
fireEvent.change(input, { target: { value: "maya@example" } });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Submit email" }));
|
||||
expect(await screen.findByText(errorCopy)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,10 @@ function catalogChipName(label: string) {
|
||||
);
|
||||
}
|
||||
|
||||
function openMethodStep(dialog: HTMLElement, name: string) {
|
||||
fireEvent.click(within(dialog).getByRole("button", { name }));
|
||||
}
|
||||
|
||||
async function confirmDiscardCustomizeEdits() {
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: "Discard" }),
|
||||
@@ -312,12 +316,18 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
await screen.findByRole("button", { name: catalogChipName("Video meetings") }),
|
||||
);
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(within(dialog).getAllByRole("textbox")).toHaveLength(3);
|
||||
expect(within(dialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||
expect(
|
||||
within(dialog).queryByText("No custom fields yet."),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).getByText(/core principle/i),
|
||||
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "How it works" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Norms" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -571,26 +581,33 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
expect(screen.getByPlaceholderText("Policy description")).toHaveValue("");
|
||||
});
|
||||
|
||||
it("opens method chip modal editable, with Save disabled until a field changes", async () => {
|
||||
it("opens a method chip as the deck's routing card, with Save off until a part changes", async () => {
|
||||
render(<FinalReviewWithCustomizeSelections />);
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
|
||||
const saveButton = within(dialog).getByRole("button", { name: "Save" });
|
||||
expect(saveButton).toBeDisabled();
|
||||
expect(within(dialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
expect(within(dialog).getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
expect(principleField).not.toBeDisabled();
|
||||
expect(principleField).toHaveValue("");
|
||||
|
||||
fireEvent.change(principleField, { target: { value: "Edited principle" } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Save" }),
|
||||
).not.toBeDisabled();
|
||||
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
expect(within(dialog).getByRole("button", { name: "Save" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("opens a core-values chip with the matching preset meaning/signals", async () => {
|
||||
@@ -792,9 +809,10 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const methodDialog = await screen.findByRole("dialog");
|
||||
expect(within(methodDialog).getAllByRole("textbox").length).toBeGreaterThan(
|
||||
0,
|
||||
);
|
||||
expect(
|
||||
within(methodDialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
expect(within(methodDialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
@@ -818,7 +836,7 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Remove" }),
|
||||
within(dialog).getByRole("button", { name: "Deselect" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).queryByRole("button", { name: "Back" }),
|
||||
@@ -845,7 +863,7 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Remove" }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Deselect" }));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -855,13 +873,10 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Save semantics for {@link FinalReviewChipEditModal}. Mirrors the
|
||||
* "edits ride along to publish" promise documented in the modal:
|
||||
*
|
||||
* 1. Save starts disabled (no edits yet → nothing to persist).
|
||||
* 2. Editing any field flips Save on; clicking it writes the typed
|
||||
* `{group}MethodDetailsById[id]` entry into create-flow state.
|
||||
* 3. Closing without Save discards every typed change.
|
||||
* Save semantics for {@link FinalReviewChipEditModal}. A method chip opens
|
||||
* the deck routing card. Save on a part returns to the rows. Save on the
|
||||
* card writes `{group}MethodDetailsById[id]`. Closing without that card
|
||||
* Save discards the typed change.
|
||||
*/
|
||||
describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
const baseSelections: CreateFlowState = {
|
||||
@@ -883,20 +898,18 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
const saveButton = within(dialog).getByRole("button", { name: "Save" });
|
||||
expect(saveButton).toBeDisabled();
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Edited principle" },
|
||||
});
|
||||
expect(within(dialog).getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Edited principle" } },
|
||||
);
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Save" }),
|
||||
).not.toBeDisabled();
|
||||
).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -913,12 +926,13 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Edited principle" },
|
||||
});
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Edited principle" } },
|
||||
);
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
expect(latest.communicationMethodDetailsById?.signal?.corePrinciple).toBeUndefined();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -941,13 +955,14 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Should NOT persist" },
|
||||
});
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Should NOT persist" } },
|
||||
);
|
||||
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
await confirmDiscardCustomizeEdits();
|
||||
await waitFor(() => {
|
||||
@@ -970,12 +985,11 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(dispatchBeforeUnload()).toBe(false);
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Unsaved on tab close" },
|
||||
});
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Unsaved on tab close" } },
|
||||
);
|
||||
expect(dispatchBeforeUnload()).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user