|
@@ -8,8 +8,8 @@ export function Save(props: { disabled: boolean }) {
|
|
|
const clientContext = useClientContext();
|
|
const clientContext = useClientContext();
|
|
|
|
|
|
|
|
const updateValidateData = useCallback(() => {
|
|
const updateValidateData = useCallback(() => {
|
|
|
- const allForms = clientContext.document.getAllNodes().map(node => getNodeForm(node));
|
|
|
|
|
- const count = allForms.filter(form => form?.state.invalid).length;
|
|
|
|
|
|
|
+ const allForms = clientContext.document.getAllNodes().map((node) => getNodeForm(node));
|
|
|
|
|
+ const count = allForms.filter((form) => form?.state.invalid).length;
|
|
|
setErrorCount(count);
|
|
setErrorCount(count);
|
|
|
}, [clientContext]);
|
|
}, [clientContext]);
|
|
|
|
|
|
|
@@ -17,8 +17,8 @@ export function Save(props: { disabled: boolean }) {
|
|
|
* Validate all node and Save
|
|
* Validate all node and Save
|
|
|
*/
|
|
*/
|
|
|
const onSave = useCallback(async () => {
|
|
const onSave = useCallback(async () => {
|
|
|
- const allForms = clientContext.document.getAllNodes().map(node => getNodeForm(node));
|
|
|
|
|
- await Promise.all(allForms.map(async form => form?.validate()));
|
|
|
|
|
|
|
+ const allForms = clientContext.document.getAllNodes().map((node) => getNodeForm(node));
|
|
|
|
|
+ await Promise.all(allForms.map(async (form) => form?.validate()));
|
|
|
console.log('>>>>> save data: ', clientContext.document.toJSON());
|
|
console.log('>>>>> save data: ', clientContext.document.toJSON());
|
|
|
}, [clientContext]);
|
|
}, [clientContext]);
|
|
|
|
|
|
|
@@ -33,24 +33,33 @@ export function Save(props: { disabled: boolean }) {
|
|
|
node.onDispose(() => formValidateDispose.dispose());
|
|
node.onDispose(() => formValidateDispose.dispose());
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
- clientContext.document.getAllNodes().map(node => listenSingleNodeValidate(node));
|
|
|
|
|
|
|
+ clientContext.document.getAllNodes().map((node) => listenSingleNodeValidate(node));
|
|
|
const dispose = clientContext.document.onNodeCreate(({ node }) =>
|
|
const dispose = clientContext.document.onNodeCreate(({ node }) =>
|
|
|
- listenSingleNodeValidate(node),
|
|
|
|
|
|
|
+ listenSingleNodeValidate(node)
|
|
|
);
|
|
);
|
|
|
return () => dispose.dispose();
|
|
return () => dispose.dispose();
|
|
|
}, [clientContext]);
|
|
}, [clientContext]);
|
|
|
|
|
|
|
|
if (errorCount === 0) {
|
|
if (errorCount === 0) {
|
|
|
return (
|
|
return (
|
|
|
- <Button disabled={props.disabled} onClick={onSave} style={{ backgroundColor: "rgba(171,181,255,0.3)", borderRadius: "8px" }}>
|
|
|
|
|
|
|
+ <Button
|
|
|
|
|
+ disabled={props.disabled}
|
|
|
|
|
+ onClick={onSave}
|
|
|
|
|
+ style={{ backgroundColor: 'rgba(171,181,255,0.3)', borderRadius: '8px' }}
|
|
|
|
|
+ >
|
|
|
Save
|
|
Save
|
|
|
</Button>
|
|
</Button>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
return (
|
|
return (
|
|
|
<Badge count={errorCount} position="rightTop" type="danger">
|
|
<Badge count={errorCount} position="rightTop" type="danger">
|
|
|
- <Button type="danger" disabled={props.disabled} onClick={onSave} style={{ backgroundColor: "rgba(255, 179, 171, 0.3)", borderRadius: "8px" }} >
|
|
|
|
|
- Save
|
|
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="danger"
|
|
|
|
|
+ disabled={props.disabled}
|
|
|
|
|
+ onClick={onSave}
|
|
|
|
|
+ style={{ backgroundColor: 'rgba(255, 179, 171, 0.3)', borderRadius: '8px' }}
|
|
|
|
|
+ >
|
|
|
|
|
+ Save
|
|
|
</Button>
|
|
</Button>
|
|
|
</Badge>
|
|
</Badge>
|
|
|
);
|
|
);
|