@mohasinac/appkit 4.21.0 → 4.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +5 -0
- package/dist/client.js +3 -0
- package/dist/features/account/components/AddressForm.js +45 -29
- package/dist/features/admin/components/AdminBundleEditorView.js +3 -0
- package/dist/features/auctions/components/PlaceBidFormClient.js +3 -1
- package/dist/features/catalogue/components/CatalogueItemEditorView.js +3 -1
- package/dist/features/layout/BottomActions.js +18 -1
- package/dist/features/layout/BottomActionsContext.d.ts +19 -0
- package/dist/features/layout/BottomActionsContext.js +37 -0
- package/dist/features/layout/hooks/useBottomActions.d.ts +10 -0
- package/dist/features/layout/hooks/useBottomActions.js +48 -11
- package/dist/features/layout/hooks/useFormBottomActions.d.ts +57 -0
- package/dist/features/layout/hooks/useFormBottomActions.js +89 -0
- package/dist/features/layout/index.d.ts +2 -0
- package/dist/features/layout/index.js +1 -0
- package/dist/features/products/components/MakeOfferButton.js +5 -3
- package/dist/features/shell/QuickFormDrawer.js +15 -1
- package/dist/features/shell/SectionForm.d.ts +16 -2
- package/dist/features/shell/SectionForm.js +28 -2
- package/dist/features/shipments/components/AdminShipmentEditorView.js +3 -1
- package/dist/features/tester/seed-data/tester-checklist-seed-data.js +36 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/ui/components/Form.d.ts +22 -1
- package/dist/ui/components/Form.js +30 -2
- package/dist/ui/components/Modal.js +4 -3
- package/dist/ui/components/SideDrawer.js +5 -4
- package/dist/ui/components/overlay-context.d.ts +21 -0
- package/dist/ui/components/overlay-context.js +25 -0
- package/dist/ui/forms/FormErrorList.d.ts +29 -0
- package/dist/ui/forms/FormErrorList.js +36 -0
- package/dist/ui/forms/FormErrorSummary.d.ts +8 -0
- package/dist/ui/forms/FormErrorSummary.js +15 -8
- package/dist/ui/forms/FormShell.d.ts +25 -1
- package/dist/ui/forms/FormShell.js +39 -4
- package/dist/ui/forms/index.d.ts +2 -0
- package/dist/ui/forms/index.js +1 -0
- package/package.json +1 -1
|
@@ -45,6 +45,9 @@ export function applyZodIssues(issues, setFieldError) {
|
|
|
45
45
|
*/
|
|
46
46
|
export function useFormShellState(schema, nav) {
|
|
47
47
|
const [errors, setErrors] = useState({});
|
|
48
|
+
const [submitAttemptCount, setSubmitAttemptCount] = useState(0);
|
|
49
|
+
const markSubmitAttempted = useCallback(() => setSubmitAttemptCount((n) => n + 1), []);
|
|
50
|
+
const submitAttempted = submitAttemptCount > 0;
|
|
48
51
|
const setFieldError = useCallback((name, error) => {
|
|
49
52
|
setErrors((prev) => {
|
|
50
53
|
if (!error) {
|
|
@@ -59,6 +62,19 @@ export function useFormShellState(schema, nav) {
|
|
|
59
62
|
}, []);
|
|
60
63
|
const clearErrors = useCallback(() => setErrors({}), []);
|
|
61
64
|
const validate = useCallback((values) => {
|
|
65
|
+
/*
|
|
66
|
+
* 🛑 validate() does NOT mark the submit attempt, and must not.
|
|
67
|
+
*
|
|
68
|
+
* ELEVEN views call `validate(draft)` from a MOUNT EFFECT to keep the
|
|
69
|
+
* summary and the submit-button state live as the user types — which
|
|
70
|
+
* is the behaviour worth having. Marking here would fire on first
|
|
71
|
+
* paint in exactly those views and defeat the gate entirely.
|
|
72
|
+
*
|
|
73
|
+
* The attempt is marked where an attempt actually happens: <Form>'s
|
|
74
|
+
* native submit handler, <SectionForm>'s submit button, and
|
|
75
|
+
* QuickFormDrawer's. A caller whose submit is an onClick on a
|
|
76
|
+
* type="button" calls markSubmitAttempted() itself.
|
|
77
|
+
*/
|
|
62
78
|
if (!schema)
|
|
63
79
|
return values;
|
|
64
80
|
const parsed = schema.safeParse(values);
|
|
@@ -90,12 +106,28 @@ export function useFormShellState(schema, nav) {
|
|
|
90
106
|
isSubmitting: false,
|
|
91
107
|
stepErrorCounts: [],
|
|
92
108
|
fieldToStepIndex: navFieldMap,
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
submitAttempted,
|
|
110
|
+
submitAttemptCount,
|
|
111
|
+
markSubmitAttempted,
|
|
112
|
+
}), [errors, setFieldError, navSections, navGoTo, navFieldMap, submitAttempted, submitAttemptCount, markSubmitAttempted]);
|
|
113
|
+
return {
|
|
114
|
+
shellCtx,
|
|
115
|
+
setFieldError,
|
|
116
|
+
clearErrors,
|
|
117
|
+
hasErrors: Object.keys(errors).length > 0,
|
|
118
|
+
validate,
|
|
119
|
+
submitAttempted,
|
|
120
|
+
submitAttemptCount,
|
|
121
|
+
markSubmitAttempted,
|
|
122
|
+
};
|
|
95
123
|
}
|
|
96
|
-
export function FormShellProvider({ children, onSaveDraft, isDirty = false, autoSaveDelayMs = 2000, values = {}, schema, fieldToStepIndex, onGoToStep, sections, }) {
|
|
124
|
+
export function FormShellProvider({ children, onSaveDraft, isDirty = false, autoSaveDelayMs = 2000, values = {}, schema, fieldToStepIndex, onGoToStep, sections, submitAttempted: submitAttemptedProp = false, }) {
|
|
97
125
|
const [errors, setErrors] = useState({});
|
|
98
126
|
const [touched, setTouched] = useState({});
|
|
127
|
+
const [ownAttemptCount, setOwnAttemptCount] = useState(0);
|
|
128
|
+
const markSubmitAttempted = useCallback(() => setOwnAttemptCount((n) => n + 1), []);
|
|
129
|
+
const submitAttemptCount = ownAttemptCount + (submitAttemptedProp ? 1 : 0);
|
|
130
|
+
const submitAttempted = submitAttemptCount > 0;
|
|
99
131
|
const autoSaveTimer = useRef(null);
|
|
100
132
|
const valuesRef = useRef(values);
|
|
101
133
|
valuesRef.current = values;
|
|
@@ -169,6 +201,9 @@ export function FormShellProvider({ children, onSaveDraft, isDirty = false, auto
|
|
|
169
201
|
isSubmitting: false,
|
|
170
202
|
stepErrorCounts: [],
|
|
171
203
|
fieldToStepIndex,
|
|
172
|
-
|
|
204
|
+
submitAttempted,
|
|
205
|
+
submitAttemptCount,
|
|
206
|
+
markSubmitAttempted,
|
|
207
|
+
}), [errors, touched, setFieldError, setFieldTouched, clearFieldError, isDirty, onGoToStep, fieldToStepIndex, sections, submitAttempted, submitAttemptCount, markSubmitAttempted]);
|
|
173
208
|
return _jsx(FormShellContext.Provider, { value: ctx, children: children });
|
|
174
209
|
}
|
package/dist/ui/forms/index.d.ts
CHANGED
|
@@ -12,3 +12,5 @@ export type { ColorPickerFieldProps } from "./ColorPickerField";
|
|
|
12
12
|
export { ColorPickerField } from "./ColorPickerField";
|
|
13
13
|
export type { FormErrorSummaryProps } from "./FormErrorSummary";
|
|
14
14
|
export { FormErrorSummary } from "./FormErrorSummary";
|
|
15
|
+
export type { FormErrorListProps } from "./FormErrorList";
|
|
16
|
+
export { FormErrorList } from "./FormErrorList";
|
package/dist/ui/forms/index.js
CHANGED