[GH-4699]: Improve share dialog for nested docs (#4719)
Co-authored-by: Tom Moor <tom@getoutline.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { observer } from "mobx-react";
|
|||||||
import { ExpandedIcon, GlobeIcon, PadlockIcon } from "outline-icons";
|
import { ExpandedIcon, GlobeIcon, PadlockIcon } from "outline-icons";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useTranslation, Trans } from "react-i18next";
|
import { useTranslation, Trans } from "react-i18next";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { SHARE_URL_SLUG_REGEX } from "@shared/utils/urlHelpers";
|
import { SHARE_URL_SLUG_REGEX } from "@shared/utils/urlHelpers";
|
||||||
import Document from "~/models/Document";
|
import Document from "~/models/Document";
|
||||||
@@ -161,14 +162,61 @@ function SharePopover({
|
|||||||
[t, document.id, shares]
|
[t, document.id, shares]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const PublishToInternet = ({ canPublish }: { canPublish: boolean }) => {
|
||||||
|
if (!canPublish) {
|
||||||
|
return (
|
||||||
|
<Text type="secondary">
|
||||||
|
{t("Only members with permission can view")}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<SwitchWrapper>
|
||||||
|
<Switch
|
||||||
|
id="published"
|
||||||
|
label={t("Publish to internet")}
|
||||||
|
onChange={handlePublishedChange}
|
||||||
|
checked={share ? share.published : false}
|
||||||
|
disabled={!share}
|
||||||
|
/>
|
||||||
|
<SwitchLabel>
|
||||||
|
<SwitchText>
|
||||||
|
{share?.published
|
||||||
|
? t("Anyone with the link can view this document")
|
||||||
|
: t("Only members with permission can view")}
|
||||||
|
{share?.lastAccessedAt && (
|
||||||
|
<>
|
||||||
|
.{" "}
|
||||||
|
{t("The shared link was last accessed {{ timeAgo }}.", {
|
||||||
|
timeAgo: formatDistanceToNow(
|
||||||
|
Date.parse(share?.lastAccessedAt),
|
||||||
|
{
|
||||||
|
addSuffix: true,
|
||||||
|
locale,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</SwitchText>
|
||||||
|
</SwitchLabel>
|
||||||
|
</SwitchWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const userLocale = useUserLocale();
|
const userLocale = useUserLocale();
|
||||||
const locale = userLocale ? dateLocale(userLocale) : undefined;
|
const locale = userLocale ? dateLocale(userLocale) : undefined;
|
||||||
let shareUrl = team.sharing ? share?.url ?? "" : `${team.url}${document.url}`;
|
let shareUrl = team.sharing
|
||||||
|
? sharedParent?.url
|
||||||
|
? `${sharedParent.url}${document.url}`
|
||||||
|
: share?.url ?? ""
|
||||||
|
: `${team.url}${document.url}`;
|
||||||
if (isEditMode) {
|
if (isEditMode) {
|
||||||
shareUrl += "?edit=true";
|
shareUrl += "?edit=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = shareUrl.replace(/https?:\/\//, "");
|
const url = shareUrl.replace(/https?:\/\//, "");
|
||||||
|
const documentTitle = sharedParent?.documentTitle;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -182,54 +230,21 @@ function SharePopover({
|
|||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
{sharedParent && !document.isDraft && (
|
{sharedParent && !document.isDraft && (
|
||||||
<Notice>
|
<NoticeWrapper>
|
||||||
<Trans
|
<Notice>
|
||||||
defaults="This document is shared because the parent <em>{{ documentTitle }}</em> is publicly shared"
|
<Trans>
|
||||||
values={{
|
This document is shared because the parent{" "}
|
||||||
documentTitle: sharedParent.documentTitle,
|
<StyledLink to={`/doc/${sharedParent.documentId}`}>
|
||||||
}}
|
{documentTitle}
|
||||||
components={{
|
</StyledLink>{" "}
|
||||||
em: <strong />,
|
is publicly shared.
|
||||||
}}
|
</Trans>
|
||||||
/>
|
</Notice>
|
||||||
</Notice>
|
</NoticeWrapper>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{canPublish ? (
|
{canPublish && !sharedParent?.published && (
|
||||||
<SwitchWrapper>
|
<PublishToInternet canPublish />
|
||||||
<Switch
|
|
||||||
id="published"
|
|
||||||
label={t("Publish to internet")}
|
|
||||||
onChange={handlePublishedChange}
|
|
||||||
checked={share ? share.published : false}
|
|
||||||
disabled={!share}
|
|
||||||
/>
|
|
||||||
<SwitchLabel>
|
|
||||||
<SwitchText>
|
|
||||||
{share?.published
|
|
||||||
? t("Anyone with the link can view this document")
|
|
||||||
: t("Only members with permission can view")}
|
|
||||||
{share?.lastAccessedAt && (
|
|
||||||
<>
|
|
||||||
.{" "}
|
|
||||||
{t("The shared link was last accessed {{ timeAgo }}.", {
|
|
||||||
timeAgo: formatDistanceToNow(
|
|
||||||
Date.parse(share?.lastAccessedAt),
|
|
||||||
{
|
|
||||||
addSuffix: true,
|
|
||||||
locale,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</SwitchText>
|
|
||||||
</SwitchLabel>
|
|
||||||
</SwitchWrapper>
|
|
||||||
) : (
|
|
||||||
<Text type="secondary">
|
|
||||||
{t("Only members with permission can view")}
|
|
||||||
</Text>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{canPublish && share?.published && !document.isDraft && (
|
{canPublish && share?.published && !document.isDraft && (
|
||||||
@@ -254,6 +269,12 @@ function SharePopover({
|
|||||||
|
|
||||||
{expandedOptions && (
|
{expandedOptions && (
|
||||||
<>
|
<>
|
||||||
|
{canPublish && sharedParent?.published && (
|
||||||
|
<>
|
||||||
|
<Separator />
|
||||||
|
<PublishToInternet canPublish />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Separator />
|
<Separator />
|
||||||
<SwitchWrapper>
|
<SwitchWrapper>
|
||||||
<Switch
|
<Switch
|
||||||
@@ -327,6 +348,11 @@ function SharePopover({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StyledLink = styled(Link)`
|
||||||
|
color: ${(props) => props.theme.textSecondary};
|
||||||
|
text-decoration: underline;
|
||||||
|
`;
|
||||||
|
|
||||||
const Heading = styled.h2`
|
const Heading = styled.h2`
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -341,6 +367,10 @@ const SwitchWrapper = styled.div`
|
|||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const NoticeWrapper = styled.div`
|
||||||
|
margin: 20px 0;
|
||||||
|
`;
|
||||||
|
|
||||||
const MoreOptionsButton = styled(Button)`
|
const MoreOptionsButton = styled(Button)`
|
||||||
background: none;
|
background: none;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|||||||
@@ -500,12 +500,12 @@
|
|||||||
"Share": "Share",
|
"Share": "Share",
|
||||||
"Only lowercase letters, digits and dashes allowed": "Only lowercase letters, digits and dashes allowed",
|
"Only lowercase letters, digits and dashes allowed": "Only lowercase letters, digits and dashes allowed",
|
||||||
"Sorry, this link has already been used": "Sorry, this link has already been used",
|
"Sorry, this link has already been used": "Sorry, this link has already been used",
|
||||||
"Share this document": "Share this document",
|
"Only members with permission can view": "Only members with permission can view",
|
||||||
"This document is shared because the parent <em>{{ documentTitle }}</em> is publicly shared": "This document is shared because the parent <em>{{ documentTitle }}</em> is publicly shared",
|
|
||||||
"Publish to internet": "Publish to internet",
|
"Publish to internet": "Publish to internet",
|
||||||
"Anyone with the link can view this document": "Anyone with the link can view this document",
|
"Anyone with the link can view this document": "Anyone with the link can view this document",
|
||||||
"Only members with permission can view": "Only members with permission can view",
|
|
||||||
"The shared link was last accessed {{ timeAgo }}.": "The shared link was last accessed {{ timeAgo }}.",
|
"The shared link was last accessed {{ timeAgo }}.": "The shared link was last accessed {{ timeAgo }}.",
|
||||||
|
"Share this document": "Share this document",
|
||||||
|
"This document is shared because the parent<1>{documentTitle}</1>is publicly shared.": "This document is shared because the parent<1>{documentTitle}</1>is publicly shared.",
|
||||||
"Share nested documents": "Share nested documents",
|
"Share nested documents": "Share nested documents",
|
||||||
"Nested documents are publicly available": "Nested documents are publicly available",
|
"Nested documents are publicly available": "Nested documents are publicly available",
|
||||||
"Nested documents are not shared": "Nested documents are not shared",
|
"Nested documents are not shared": "Nested documents are not shared",
|
||||||
|
|||||||
Reference in New Issue
Block a user