diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx
index 3d9e18c89a..99d289b6af 100644
--- a/app/actions/definitions/documents.tsx
+++ b/app/actions/definitions/documents.tsx
@@ -358,8 +358,6 @@ export const shareDocument = createAction({
}
const document = stores.documents.get(activeDocumentId);
- const share = stores.shares.getByDocumentId(activeDocumentId);
- const sharedParent = stores.shares.getByDocumentParents(activeDocumentId);
if (!document) {
return;
}
@@ -370,8 +368,6 @@ export const shareDocument = createAction({
content: (
diff --git a/app/components/Sharing/Document/PublicAccess.tsx b/app/components/Sharing/Document/PublicAccess.tsx
index 4855cb2b5b..38353e7099 100644
--- a/app/components/Sharing/Document/PublicAccess.tsx
+++ b/app/components/Sharing/Document/PublicAccess.tsx
@@ -1,4 +1,3 @@
-import invariant from "invariant";
import debounce from "lodash/debounce";
import isEmpty from "lodash/isEmpty";
import { observer } from "mobx-react";
@@ -17,7 +16,6 @@ import Input, { NativeInput } from "~/components/Input";
import Switch from "~/components/Switch";
import env from "~/env";
import usePolicy from "~/hooks/usePolicy";
-import useStores from "~/hooks/useStores";
import { AvatarSize } from "../../Avatar";
import CopyToClipboard from "../../CopyToClipboard";
import NudeButton from "../../NudeButton";
@@ -39,7 +37,6 @@ type Props = {
};
function PublicAccess({ document, share, sharedParent }: Props) {
- const { shares } = useStores();
const { t } = useTranslation();
const theme = useTheme();
const [validationError, setValidationError] = React.useState("");
@@ -55,18 +52,15 @@ function PublicAccess({ document, share, sharedParent }: Props) {
const handlePublishedChange = React.useCallback(
async (event) => {
- const share = shares.getByDocumentId(document.id);
- invariant(share, "Share must exist");
-
try {
- await share.save({
+ await share?.save({
published: event.currentTarget.checked,
});
} catch (err) {
toast.error(err.message);
}
},
- [document.id, shares]
+ [share]
);
const handleUrlChange = React.useMemo(
diff --git a/app/components/Sharing/Document/SharePopover.tsx b/app/components/Sharing/Document/SharePopover.tsx
index 6ab0f6262e..007633977c 100644
--- a/app/components/Sharing/Document/SharePopover.tsx
+++ b/app/components/Sharing/Document/SharePopover.tsx
@@ -8,7 +8,6 @@ import { toast } from "sonner";
import { DocumentPermission } from "@shared/types";
import Document from "~/models/Document";
import Group from "~/models/Group";
-import Share from "~/models/Share";
import User from "~/models/User";
import { Avatar, GroupAvatar, AvatarSize } from "~/components/Avatar";
import NudeButton from "~/components/NudeButton";
@@ -32,26 +31,19 @@ import { AccessControlList } from "./AccessControlList";
type Props = {
/** The document to share. */
document: Document;
- /** The existing share model, if any. */
- share: Share | null | undefined;
- /** The existing share parent model, if any. */
- sharedParent: Share | null | undefined;
/** Callback fired when the popover requests to be closed. */
onRequestClose: () => void;
/** Whether the popover is visible. */
visible: boolean;
};
-function SharePopover({
- document,
- share,
- sharedParent,
- onRequestClose,
- visible,
-}: Props) {
+function SharePopover({ document, onRequestClose, visible }: Props) {
const team = useCurrentTeam();
const { t } = useTranslation();
const can = usePolicy(document);
+ const { shares } = useStores();
+ const share = shares.getByDocumentId(document.id);
+ const sharedParent = shares.getByDocumentParents(document.id);
const [hasRendered, setHasRendered] = React.useState(visible);
const { users, userMemberships, groups, groupMemberships } = useStores();
const [query, setQuery] = React.useState("");
diff --git a/app/scenes/Document/components/ShareButton.tsx b/app/scenes/Document/components/ShareButton.tsx
index 4df7ba7515..290a9c2cb4 100644
--- a/app/scenes/Document/components/ShareButton.tsx
+++ b/app/scenes/Document/components/ShareButton.tsx
@@ -53,8 +53,6 @@ function ShareButton({ document }: Props) {
>