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
+274
-685
No files matched your search
@@ -966,6 +966,7 @@ function CreateFlowLayoutContent({
|
|||||||
<form
|
<form
|
||||||
id={CREATE_FLOW_COMMUNITY_SAVE_FORM_ID}
|
id={CREATE_FLOW_COMMUNITY_SAVE_FORM_ID}
|
||||||
className="hidden"
|
className="hidden"
|
||||||
|
noValidate
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
markAttempted();
|
markAttempted();
|
||||||
@@ -1052,6 +1053,7 @@ function CreateFlowLayoutContent({
|
|||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
form={CREATE_FLOW_COMMUNITY_SAVE_FORM_ID}
|
form={CREATE_FLOW_COMMUNITY_SAVE_FORM_ID}
|
||||||
|
formNoValidate
|
||||||
buttonType="filled"
|
buttonType="filled"
|
||||||
palette="default"
|
palette="default"
|
||||||
size="xsmall"
|
size="xsmall"
|
||||||
|
|||||||
+1
-2
@@ -5,8 +5,7 @@
|
|||||||
* (facet screens + final-review chip edit). When `onBlocksChange` is omitted,
|
* (facet screens + final-review chip edit). When `onBlocksChange` is omitted,
|
||||||
* blocks render read-only (disabled controls).
|
* blocks render read-only (disabled controls).
|
||||||
*
|
*
|
||||||
* Layout matches preset method editors ({@link CommunicationMethodEditFields},
|
* Layout matches the deck policy editors: {@link ModalTextAreaField},
|
||||||
* {@link DecisionApproachEditFields}): {@link ModalTextAreaField},
|
|
||||||
* {@link ApplicableScopeField} chip rows, {@link IncrementerBlock}.
|
* {@link ApplicableScopeField} chip rows, {@link IncrementerBlock}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Final-review chip modal: **Core values** use {@link ValueDialog} (Deselect +
|
* Final-review chip modal: **Core values** use {@link ValueDialog} (Deselect +
|
||||||
* Cancel + Save; kebab Customize / Duplicate under the cap). **Method** facets
|
* Cancel + Save; kebab Customize / Duplicate under the cap). **Method** chips
|
||||||
* keep `Create` with kebab Duplicate/Remove plus a footer **Remove** when the
|
* use {@link MethodCardPolicyDialog}, the same routing card as the decks: a
|
||||||
* chip is already in the selection. Values and method chips also offer
|
* row per part, then that part's editor. Footer **Deselect** when the chip is
|
||||||
* **Customize**, which opens {@link CustomMethodCardWizard} prefilled from the
|
* already selected; Save stays off until the draft changes. Values and method
|
||||||
* chip. Fields are editable on open; Save persists body edits without renaming.
|
* chips also offer **Customize**, which opens {@link CustomMethodCardWizard}
|
||||||
|
* prefilled from the chip.
|
||||||
*
|
*
|
||||||
* Template-only chips without an `overrideKey` never mount this component; they
|
* Template-only chips without an `overrideKey` never mount this component; they
|
||||||
* use {@link TemplateChipDetailModal} from the parent.
|
* use {@link TemplateChipDetailModal} from the parent.
|
||||||
@@ -15,16 +16,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import Create from "../../../components/modals/Create";
|
import { useMessages } from "../../../contexts/MessagesContext";
|
||||||
import ContentLockup from "../../../components/type/ContentLockup";
|
|
||||||
import { useMessages, useTranslation } from "../../../contexts/MessagesContext";
|
|
||||||
import {
|
|
||||||
CommunicationMethodEditFields,
|
|
||||||
ConflictManagementEditFields,
|
|
||||||
DecisionApproachEditFields,
|
|
||||||
MembershipMethodEditFields,
|
|
||||||
} from "./methodEditFields";
|
|
||||||
import { ValueDialog } from "./ValueDialog";
|
import { ValueDialog } from "./ValueDialog";
|
||||||
|
import { MethodCardPolicyDialog } from "./MethodCardPolicyDialog";
|
||||||
|
import {
|
||||||
|
useCommunicationPolicySteps,
|
||||||
|
useConflictPolicySteps,
|
||||||
|
useDecisionApproachPolicySteps,
|
||||||
|
useMembershipPolicySteps,
|
||||||
|
} from "./methodCardPolicySteps";
|
||||||
import CustomMethodCardModalBody from "./CustomMethodCardModalBody";
|
import CustomMethodCardModalBody from "./CustomMethodCardModalBody";
|
||||||
import { buildCustomRuleModalKebabMenu } from "./customRuleModalKebabMenu";
|
import { buildCustomRuleModalKebabMenu } from "./customRuleModalKebabMenu";
|
||||||
import { useDiscardCustomizeConfirm } from "../hooks/useDiscardCustomizeConfirm";
|
import { useDiscardCustomizeConfirm } from "../hooks/useDiscardCustomizeConfirm";
|
||||||
@@ -187,9 +187,6 @@ export function FinalReviewChipEditModal({
|
|||||||
const tDa = cr.decisionApproaches;
|
const tDa = cr.decisionApproaches;
|
||||||
const tCm = cr.conflictManagement;
|
const tCm = cr.conflictManagement;
|
||||||
const modalKebabMenu = cr.modalKebabMenu;
|
const modalKebabMenu = cr.modalKebabMenu;
|
||||||
const tModal = useTranslation(
|
|
||||||
"create.reviewAndComplete.finalReview.chipEditModal",
|
|
||||||
);
|
|
||||||
const { confirmDiscard, confirmDialog } = useDiscardCustomizeConfirm();
|
const { confirmDiscard, confirmDialog } = useDiscardCustomizeConfirm();
|
||||||
|
|
||||||
const [draft, setDraft] = useState<Draft | null>(null);
|
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 facet = CUSTOM_RULE_FACET_BY_GROUP.get(target.groupKey)!;
|
||||||
const pendingId = target.overrideKey;
|
const pendingId = target.overrideKey;
|
||||||
const sel = [...facet.selectionIds(state)];
|
const sel = [...facet.selectionIds(state)];
|
||||||
|
if (sel.includes(pendingId) && methodCustomizeSaveDisabled) return;
|
||||||
onInteract?.();
|
onInteract?.();
|
||||||
|
|
||||||
const persistWizardBlocks = draftFieldBlocks !== null;
|
const persistWizardBlocks = draftFieldBlocks !== null;
|
||||||
@@ -906,6 +904,7 @@ export function FinalReviewChipEditModal({
|
|||||||
draft,
|
draft,
|
||||||
draftFieldBlocks,
|
draftFieldBlocks,
|
||||||
finalizeModalClose,
|
finalizeModalClose,
|
||||||
|
methodCustomizeSaveDisabled,
|
||||||
onInteract,
|
onInteract,
|
||||||
onSave,
|
onSave,
|
||||||
replaceState,
|
replaceState,
|
||||||
@@ -1044,44 +1043,48 @@ export function FinalReviewChipEditModal({
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleNext = useCallback(() => {
|
const communicationSteps = useCommunicationPolicySteps(
|
||||||
if (!target || !draft) return;
|
draft?.groupKey === "communication"
|
||||||
if (target.groupKey === "coreValues") {
|
? draft.value
|
||||||
handleCoreSave();
|
: emptyCommunicationDetails(),
|
||||||
} else {
|
(value) => setDraft({ groupKey: "communication", value }),
|
||||||
handleMethodPrimary();
|
target?.groupKey === "communication"
|
||||||
}
|
? communicationPresetFor(target.overrideKey)
|
||||||
}, [draft, handleCoreSave, handleMethodPrimary, target]);
|
: undefined,
|
||||||
|
);
|
||||||
const nextButtonText = useMemo(() => {
|
const membershipSteps = useMembershipPolicySteps(
|
||||||
if (!target) return tModal("saveButton");
|
draft?.groupKey === "membership" ? draft.value : emptyMembershipDetails(),
|
||||||
if (target.groupKey === "coreValues") {
|
(value) => setDraft({ groupKey: "membership", value }),
|
||||||
return tModal("saveButton");
|
target?.groupKey === "membership"
|
||||||
}
|
? membershipPresetFor(target.overrideKey)
|
||||||
if (!isChipInSelection) {
|
: undefined,
|
||||||
return addPrimaryLabelForMethodFacet(target.groupKey, cr);
|
);
|
||||||
}
|
const decisionSteps = useDecisionApproachPolicySteps(
|
||||||
return tModal("saveButton");
|
draft?.groupKey === "decisionApproaches"
|
||||||
}, [cr, isChipInSelection, target, tModal]);
|
? draft.value
|
||||||
|
: emptyDecisionApproachTextFields(decisionApproachPresetFor("")),
|
||||||
const headerContent = useMemo(() => {
|
(value) => setDraft({ groupKey: "decisionApproaches", value }),
|
||||||
if (!target) return undefined;
|
target?.groupKey === "decisionApproaches"
|
||||||
return (
|
? decisionApproachPresetFor(target.overrideKey)
|
||||||
<div className="bg-[var(--color-surface-default-primary)] px-[24px] py-[12px] shrink-0">
|
: undefined,
|
||||||
<ContentLockup
|
);
|
||||||
title={target.chipLabel}
|
const conflictSteps = useConflictPolicySteps(
|
||||||
description={subtitle}
|
draft?.groupKey === "conflictManagement"
|
||||||
variant="modal"
|
? draft.value
|
||||||
alignment="left"
|
: emptyConflictManagementDetails(),
|
||||||
/>
|
(value) => setDraft({ groupKey: "conflictManagement", value }),
|
||||||
</div>
|
target?.groupKey === "conflictManagement"
|
||||||
);
|
? conflictManagementPresetFor(target.overrideKey)
|
||||||
}, [subtitle, target]);
|
: undefined,
|
||||||
|
);
|
||||||
const showFooterRemove =
|
const methodSteps =
|
||||||
target != null &&
|
draft?.groupKey === "membership"
|
||||||
target.groupKey !== "coreValues" &&
|
? membershipSteps
|
||||||
isChipInSelection;
|
: draft?.groupKey === "decisionApproaches"
|
||||||
|
? decisionSteps
|
||||||
|
: draft?.groupKey === "conflictManagement"
|
||||||
|
? conflictSteps
|
||||||
|
: communicationSteps;
|
||||||
|
|
||||||
const isCoreValuesTarget = target?.groupKey === "coreValues";
|
const isCoreValuesTarget = target?.groupKey === "coreValues";
|
||||||
const coreDraftValue =
|
const coreDraftValue =
|
||||||
@@ -1103,7 +1106,7 @@ export function FinalReviewChipEditModal({
|
|||||||
onClose={() => {
|
onClose={() => {
|
||||||
void handleModalClose();
|
void handleModalClose();
|
||||||
}}
|
}}
|
||||||
onConfirm={handleNext}
|
onConfirm={handleCoreSave}
|
||||||
onDeselect={handleRemoveCoreValueFromModal}
|
onDeselect={handleRemoveCoreValueFromModal}
|
||||||
nextButtonDisabled={coreCustomizeSaveDisabled}
|
nextButtonDisabled={coreCustomizeSaveDisabled}
|
||||||
kebabTriggerAriaLabel={modalKebabMenu.triggerAriaLabel}
|
kebabTriggerAriaLabel={modalKebabMenu.triggerAriaLabel}
|
||||||
@@ -1131,151 +1134,52 @@ export function FinalReviewChipEditModal({
|
|||||||
/>
|
/>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
</ValueDialog>
|
</ValueDialog>
|
||||||
<Create
|
<MethodCardPolicyDialog
|
||||||
isOpen={
|
isOpen={isOpen && !addCustomWizardOpen && !isCoreValuesTarget}
|
||||||
isOpen && !addCustomWizardOpen && !isCoreValuesTarget
|
cardLabel={target?.chipLabel ?? ""}
|
||||||
}
|
description={subtitle}
|
||||||
onClose={handleModalClose}
|
editing={isChipInSelection}
|
||||||
onBack={handleModalClose}
|
steps={methodSteps}
|
||||||
showBackButton={!showFooterRemove}
|
onClose={() => {
|
||||||
showRemoveButton={showFooterRemove}
|
void handleModalClose();
|
||||||
onRemove={
|
}}
|
||||||
target?.groupKey === "coreValues"
|
onConfirm={handleMethodPrimary}
|
||||||
? handleRemoveCoreValueFromModal
|
onDeselect={
|
||||||
: handleRemoveSelectedFromModal
|
isChipInSelection
|
||||||
}
|
? () => {
|
||||||
backdropVariant="blurredYellow"
|
void handleRemoveSelectedFromModal();
|
||||||
headerContent={headerContent}
|
|
||||||
showNextButton={true}
|
|
||||||
onNext={handleNext}
|
|
||||||
nextButtonText={nextButtonText}
|
|
||||||
nextButtonDisabled={
|
|
||||||
target?.groupKey === "coreValues"
|
|
||||||
? coreCustomizeSaveDisabled
|
|
||||||
: methodCustomizeSaveDisabled
|
|
||||||
}
|
|
||||||
kebabTriggerAriaLabel={modalKebabMenu.triggerAriaLabel}
|
|
||||||
kebabMenuAriaLabel={modalKebabMenu.menuAriaLabel}
|
|
||||||
kebabMenuItems={
|
|
||||||
target && 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" &&
|
|
||||||
target &&
|
|
||||||
(modalUsesWizardFieldBlocksBody ? (
|
|
||||||
<CustomMethodCardModalBody
|
|
||||||
cardId={target.overrideKey}
|
|
||||||
blocksById={state.customMethodCardFieldBlocksById}
|
|
||||||
blocksOverride={
|
|
||||||
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
|
||||||
}
|
}
|
||||||
policyMeta={
|
: undefined
|
||||||
state.customMethodCardMetaById?.[target.overrideKey]
|
}
|
||||||
}
|
confirmDisabled={isChipInSelection && methodCustomizeSaveDisabled}
|
||||||
showPolicyContentLockupWhenNoBlocks={false}
|
kebabTriggerAriaLabel={modalKebabMenu.triggerAriaLabel}
|
||||||
onFieldBlocksChange={
|
kebabMenuAriaLabel={modalKebabMenu.menuAriaLabel}
|
||||||
draftFieldBlocks === null
|
kebabMenuItems={
|
||||||
? undefined
|
target && !isCoreValuesTarget && kebabMenuItems.length > 0
|
||||||
: handleWizardFieldBlocksChange
|
? kebabMenuItems
|
||||||
}
|
: undefined
|
||||||
/>
|
}
|
||||||
) : (
|
ariaLabel={target?.chipLabel || "Edit chip details"}
|
||||||
<CommunicationMethodEditFields
|
>
|
||||||
value={draft.value}
|
{modalUsesWizardFieldBlocksBody &&
|
||||||
onChange={(value) =>
|
target &&
|
||||||
setDraft({ groupKey: "communication", value })
|
isMethodFacetGroup(target.groupKey) ? (
|
||||||
}
|
<CustomMethodCardModalBody
|
||||||
generateDraft={communicationPresetFor(target.overrideKey)}
|
cardId={target.overrideKey}
|
||||||
/>
|
blocksById={state.customMethodCardFieldBlocksById}
|
||||||
))}
|
blocksOverride={
|
||||||
{draft?.groupKey === "membership" &&
|
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
||||||
target &&
|
}
|
||||||
(modalUsesWizardFieldBlocksBody ? (
|
policyMeta={state.customMethodCardMetaById?.[target.overrideKey]}
|
||||||
<CustomMethodCardModalBody
|
showPolicyContentLockupWhenNoBlocks={false}
|
||||||
cardId={target.overrideKey}
|
onFieldBlocksChange={
|
||||||
blocksById={state.customMethodCardFieldBlocksById}
|
draftFieldBlocks === null
|
||||||
blocksOverride={
|
? undefined
|
||||||
draftFieldBlocks !== null ? draftFieldBlocks : undefined
|
: handleWizardFieldBlocksChange
|
||||||
}
|
}
|
||||||
policyMeta={
|
/>
|
||||||
state.customMethodCardMetaById?.[target.overrideKey]
|
) : null}
|
||||||
}
|
</MethodCardPolicyDialog>
|
||||||
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>
|
|
||||||
<CustomMethodCardWizard
|
<CustomMethodCardWizard
|
||||||
isOpen={addCustomWizardOpen}
|
isOpen={addCustomWizardOpen}
|
||||||
onClose={handleCloseAddWizard}
|
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(
|
function seedDraftForTarget(
|
||||||
target: FinalReviewChipEditTarget,
|
target: FinalReviewChipEditTarget,
|
||||||
state: CreateFlowState,
|
state: CreateFlowState,
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ export type MethodCardPolicyDialogProps = {
|
|||||||
ariaLabel?: string;
|
ariaLabel?: string;
|
||||||
/** Customized field-blocks body. Replaces the routing steps. */
|
/** Customized field-blocks body. Replaces the routing steps. */
|
||||||
children?: ReactNode;
|
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({
|
function MethodCardPolicyDialogComponent({
|
||||||
@@ -52,6 +57,7 @@ function MethodCardPolicyDialogComponent({
|
|||||||
kebabMenuItems,
|
kebabMenuItems,
|
||||||
ariaLabel,
|
ariaLabel,
|
||||||
children,
|
children,
|
||||||
|
confirmDisabled = false,
|
||||||
}: MethodCardPolicyDialogProps) {
|
}: MethodCardPolicyDialogProps) {
|
||||||
const m = useMessages();
|
const m = useMessages();
|
||||||
const t = m.create.customRule.cardDialog;
|
const t = m.create.customRule.cardDialog;
|
||||||
@@ -104,6 +110,7 @@ function MethodCardPolicyDialogComponent({
|
|||||||
onRemove={onDeselect}
|
onRemove={onDeselect}
|
||||||
cancelButtonText={t.cancel}
|
cancelButtonText={t.cancel}
|
||||||
nextButtonText={primaryLabel}
|
nextButtonText={primaryLabel}
|
||||||
|
nextButtonDisabled={activeStepId == null && confirmDisabled}
|
||||||
removeButtonText={t.deselect}
|
removeButtonText={t.deselect}
|
||||||
stepper={false}
|
stepper={false}
|
||||||
backdropVariant="blurredYellow"
|
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:
|
* Two modals coexist on this screen:
|
||||||
*
|
*
|
||||||
* - {@link FinalReviewChipEditModal} — core values + method chips: footer
|
* - {@link FinalReviewChipEditModal} — core values use the value card;
|
||||||
* **Remove** when the chip is already selected, plus kebab **Remove**;
|
* 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
|
* values also offer Duplicate under the five-chip cap; method chips
|
||||||
* offer Customize (prefilled custom-policy wizard). Fields are editable on
|
* offer Customize (prefilled custom-policy wizard). Save writes
|
||||||
* open. Save writes `{group}DetailsById` and field blocks; wizard Finalize
|
* `{group}DetailsById` and field blocks; wizard Finalize also writes
|
||||||
* also writes `customMethodCardMetaById`.
|
* `customMethodCardMetaById`.
|
||||||
* - {@link TemplateChipDetailModal} — read-only fallback for chips we
|
* - {@link TemplateChipDetailModal} — read-only fallback for chips we
|
||||||
* can't map to an override key (e.g. template body entries on the
|
* can't map to an override key (e.g. template body entries on the
|
||||||
* "Use without changes" path where no preset matches the title).
|
* "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
|
* 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
|
* 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.
|
* and `buildPublishPayload` for the read side.
|
||||||
*/
|
*/
|
||||||
const COMMUNICATION_STEPS = [
|
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() {
|
async function confirmDiscardCustomizeEdits() {
|
||||||
fireEvent.click(
|
fireEvent.click(
|
||||||
await screen.findByRole("button", { name: "Discard" }),
|
await screen.findByRole("button", { name: "Discard" }),
|
||||||
@@ -312,12 +316,18 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
|||||||
await screen.findByRole("button", { name: catalogChipName("Video meetings") }),
|
await screen.findByRole("button", { name: catalogChipName("Video meetings") }),
|
||||||
);
|
);
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
expect(within(dialog).getAllByRole("textbox")).toHaveLength(3);
|
expect(within(dialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||||
expect(
|
expect(
|
||||||
within(dialog).queryByText("No custom fields yet."),
|
within(dialog).queryByText("No custom fields yet."),
|
||||||
).not.toBeInTheDocument();
|
).not.toBeInTheDocument();
|
||||||
expect(
|
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();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -571,26 +581,33 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
|||||||
expect(screen.getByPlaceholderText("Policy description")).toHaveValue("");
|
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 />);
|
render(<FinalReviewWithCustomizeSelections />);
|
||||||
|
|
||||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
|
|
||||||
const saveButton = within(dialog).getByRole("button", { name: "Save" });
|
expect(within(dialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||||
expect(saveButton).toBeDisabled();
|
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", {
|
const principleField = within(dialog).getByRole("textbox", {
|
||||||
name: /core principle/i,
|
name: /core principle/i,
|
||||||
});
|
});
|
||||||
expect(principleField).not.toBeDisabled();
|
expect(principleField).not.toBeDisabled();
|
||||||
|
expect(principleField).toHaveValue("");
|
||||||
|
|
||||||
fireEvent.change(principleField, { target: { value: "Edited principle" } });
|
fireEvent.change(principleField, { target: { value: "Edited principle" } });
|
||||||
|
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(
|
expect(
|
||||||
within(dialog).getByRole("button", { name: "Save" }),
|
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||||
).not.toBeDisabled();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
expect(within(dialog).getByRole("button", { name: "Save" })).toBeEnabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens a core-values chip with the matching preset meaning/signals", async () => {
|
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") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const methodDialog = await screen.findByRole("dialog");
|
const methodDialog = await screen.findByRole("dialog");
|
||||||
expect(within(methodDialog).getAllByRole("textbox").length).toBeGreaterThan(
|
expect(
|
||||||
0,
|
within(methodDialog).getByRole("button", { name: "Core principle and scope" }),
|
||||||
);
|
).toBeInTheDocument();
|
||||||
|
expect(within(methodDialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||||
fireEvent.keyDown(document, { key: "Escape" });
|
fireEvent.keyDown(document, { key: "Escape" });
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||||
@@ -818,7 +836,7 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
|||||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
expect(
|
expect(
|
||||||
within(dialog).getByRole("button", { name: "Remove" }),
|
within(dialog).getByRole("button", { name: "Deselect" }),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
expect(
|
expect(
|
||||||
within(dialog).queryByRole("button", { name: "Back" }),
|
within(dialog).queryByRole("button", { name: "Back" }),
|
||||||
@@ -845,7 +863,7 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
|||||||
|
|
||||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
fireEvent.click(within(dialog).getByRole("button", { name: "Remove" }));
|
fireEvent.click(within(dialog).getByRole("button", { name: "Deselect" }));
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
@@ -855,13 +873,10 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save semantics for {@link FinalReviewChipEditModal}. Mirrors the
|
* Save semantics for {@link FinalReviewChipEditModal}. A method chip opens
|
||||||
* "edits ride along to publish" promise documented in the modal:
|
* the deck routing card. Save on a part returns to the rows. Save on the
|
||||||
*
|
* card writes `{group}MethodDetailsById[id]`. Closing without that card
|
||||||
* 1. Save starts disabled (no edits yet → nothing to persist).
|
* Save discards the typed change.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||||
const baseSelections: CreateFlowState = {
|
const baseSelections: CreateFlowState = {
|
||||||
@@ -883,20 +898,18 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
|||||||
|
|
||||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
const saveButton = within(dialog).getByRole("button", { name: "Save" });
|
expect(within(dialog).getByRole("button", { name: "Save" })).toBeDisabled();
|
||||||
expect(saveButton).toBeDisabled();
|
openMethodStep(dialog, "Core principle and scope");
|
||||||
const principleField = within(dialog).getByRole("textbox", {
|
fireEvent.change(
|
||||||
name: /core principle/i,
|
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||||
});
|
{ target: { value: "Edited principle" } },
|
||||||
|
);
|
||||||
fireEvent.change(principleField, {
|
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||||
target: { value: "Edited principle" },
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(
|
expect(
|
||||||
within(dialog).getByRole("button", { name: "Save" }),
|
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") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
const principleField = within(dialog).getByRole("textbox", {
|
openMethodStep(dialog, "Core principle and scope");
|
||||||
name: /core principle/i,
|
fireEvent.change(
|
||||||
});
|
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||||
fireEvent.change(principleField, {
|
{ target: { value: "Edited principle" } },
|
||||||
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" }));
|
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
@@ -941,13 +955,14 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
|||||||
|
|
||||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
const principleField = within(dialog).getByRole("textbox", {
|
openMethodStep(dialog, "Core principle and scope");
|
||||||
name: /core principle/i,
|
fireEvent.change(
|
||||||
});
|
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||||
fireEvent.change(principleField, {
|
{ target: { value: "Should NOT persist" } },
|
||||||
target: { value: "Should NOT persist" },
|
);
|
||||||
});
|
|
||||||
|
|
||||||
|
fireEvent.keyDown(document, { key: "Escape" });
|
||||||
|
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
||||||
fireEvent.keyDown(document, { key: "Escape" });
|
fireEvent.keyDown(document, { key: "Escape" });
|
||||||
await confirmDiscardCustomizeEdits();
|
await confirmDiscardCustomizeEdits();
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
@@ -970,12 +985,11 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
|||||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||||
const dialog = await screen.findByRole("dialog");
|
const dialog = await screen.findByRole("dialog");
|
||||||
expect(dispatchBeforeUnload()).toBe(false);
|
expect(dispatchBeforeUnload()).toBe(false);
|
||||||
const principleField = within(dialog).getByRole("textbox", {
|
openMethodStep(dialog, "Core principle and scope");
|
||||||
name: /core principle/i,
|
fireEvent.change(
|
||||||
});
|
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||||
fireEvent.change(principleField, {
|
{ target: { value: "Unsaved on tab close" } },
|
||||||
target: { value: "Unsaved on tab close" },
|
);
|
||||||
});
|
|
||||||
expect(dispatchBeforeUnload()).toBe(true);
|
expect(dispatchBeforeUnload()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user