Refactor PathToDocument

This commit is contained in:
Saumya Pandey committed 2021-08-11 01:16:01 +05:30
1 parent 44f3ef869a
commit ef8be0dd0b
2 files changed
+12 -12

No files matched your search

+3 -11
View File
@@ -13,7 +13,7 @@ type Props = {
result: DocumentPath,
document?: ?Document,
collection: ?Collection,
onSuccess?: () => void,
onSuccess?: (DocumentPath) => Promise<void>,
style?: Object,
ref?: (?React.ElementRef<"div">) => void,
};
@@ -22,16 +22,8 @@ type Props = {
class PathToDocument extends React.Component<Props> {
handleClick = async (ev: SyntheticEvent<>) => {
ev.preventDefault();
const { document, result, onSuccess } = this.props;
if (!document) return;
if (result.type === "document") {
await document.move(result.collectionId, result.id);
} else {
await document.move(result.collectionId, null);
}
if (onSuccess) onSuccess();
const { onSuccess, result } = this.props;
if (onSuccess) await onSuccess(result);
};
render() {
+9 -1
View File
@@ -78,7 +78,15 @@ function DocumentMove({ document, onRequestClose }: Props) {
return results;
}, [document, collections, searchTerm, searchIndex]);
const handleSuccess = () => {
const handleSuccess = async (result: DocumentPath) => {
if (!document) return;
if (result.type === "document") {
await document.move(result.collectionId, result.id);
} else {
await document.move(result.collectionId, null);
}
showToast(t("Document moved"), { type: "info" });
onRequestClose();
};