From c4ace077653faa2adbb539795aec1e9f07d102b2 Mon Sep 17 00:00:00 2001 From: Johannes <72809645+jobenjada@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:09:55 -0600 Subject: [PATCH] fix: tweak sharing results UX (#1928) --- .../responses/components/ResponsePage.tsx | 17 ++++-- .../summary/components/ShareSurveyResults.tsx | 17 +++--- .../summary/components/SummaryPage.tsx | 17 ++++-- .../ResultsShareButton.tsx} | 60 ++++++++++++------- .../[surveyId]/components/SummaryHeader.tsx | 33 ++++++++-- .../app/(app)/share/[sharingKey]/layout.tsx | 2 +- oss.gg | 1 + 7 files changed, 99 insertions(+), 48 deletions(-) rename apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/{(analysis)/summary/components/SurveyShareButton.tsx => components/ResultsShareButton.tsx} (64%) create mode 160000 oss.gg diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage.tsx index 7c48452a27..20ab5150e0 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage.tsx @@ -19,6 +19,8 @@ import { TTag } from "@formbricks/types/tags"; import { TUser } from "@formbricks/types/user"; import ContentWrapper from "@formbricks/ui/ContentWrapper"; +import ResultsShareButton from "../../../components/ResultsShareButton"; + interface ResponsePageProps { environment: TEnvironment; survey: TSurvey; @@ -70,12 +72,15 @@ const ResponsePage = ({ user={user} membershipRole={membershipRole} /> - +
+ + +
@@ -77,21 +77,22 @@ export default function ShareSurveyResults({ ) : (
- +
-

Publish Results to web

+

+ You are about to release these survey results to the public. +

- Your survey results are shared with anyone who has the link. The results will not be indexed - by search engines. + Your survey results will be public. Anyone outside your team can access them if they have the + link.

-
diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage.tsx index 8bfce5803d..fbd7ee81ab 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage.tsx @@ -21,6 +21,8 @@ import { TTag } from "@formbricks/types/tags"; import { TUser } from "@formbricks/types/user"; import ContentWrapper from "@formbricks/ui/ContentWrapper"; +import ResultsShareButton from "../../../components/ResultsShareButton"; + interface SummaryPageProps { environment: TEnvironment; survey: TSurvey; @@ -76,12 +78,15 @@ const SummaryPage = ({ user={user} membershipRole={membershipRole} /> - +
+ + +
{ deleteResultShareUrlAction(survey.id) .then(() => { - toast.success("Survey Unpublished successfully"); + toast.success("Results unpublished successfully."); setShowPublishModal(false); setShowLinkModal(false); }) @@ -74,39 +74,55 @@ export default function SurveyShareButton({ survey, webAppUrl, product, user }: } }, [showResultsLinkModal]); + const copyUrlToClipboard = () => { + if (typeof window !== "undefined") { + // Check if window is defined (i.e., if the code is running in the browser) + const currentUrl = window.location.href; // Get the current URL + navigator.clipboard + .writeText(currentUrl) // Copy it to the clipboard + .then(() => { + toast.success("Link to results copied to clipboard."); // Show success message + }) + .catch((err) => { + console.error("Failed to copy: ", err); // Handle any errors + toast.error("Failed to copy link to results to clipboard."); // Show error message + }); + } else { + console.error("Cannot copy URL: not running in a browser environment."); + toast.error("Failed to copy URL: not in a browser environment."); + } + }; return ( - <> +
- Share - + Share Results +
- {survey.type === "link" && ( - { - setShowLinkModal(true); - }}> -

- Share Survey -

-
- )} + { + copyUrlToClipboard(); + }}> +

+ Copy link +

+
{ setShowResultsLinkModal(true); }}>

- Publish Results + Publish to web

@@ -132,6 +148,6 @@ export default function SurveyShareButton({ survey, webAppUrl, product, user }: showPublishModal={showPublishModal} /> )} - +
); } diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/SummaryHeader.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/SummaryHeader.tsx index 2cf13f128c..8bd4900099 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/SummaryHeader.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/SummaryHeader.tsx @@ -1,11 +1,12 @@ "use client"; import SuccessMessage from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage"; -import SurveyShareButton from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyShareButton"; +import ResultsShareButton from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResultsShareButton"; import SurveyStatusDropdown from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/SurveyStatusDropdown"; import { updateSurveyAction } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/actions"; -import { EllipsisHorizontalIcon, PencilSquareIcon } from "@heroicons/react/24/solid"; +import { EllipsisHorizontalIcon, PencilSquareIcon, ShareIcon } from "@heroicons/react/24/solid"; import { useRouter } from "next/navigation"; +import { useState } from "react"; import toast from "react-hot-toast"; import { getAccessFlags } from "@formbricks/lib/membership/utils"; @@ -30,6 +31,8 @@ import { } from "@formbricks/ui/DropdownMenu"; import { SurveyStatusIndicator } from "@formbricks/ui/SurveyStatusIndicator"; +import ShareEmbedSurvey from "../(analysis)/summary/components/ShareEmbedSurvey"; + interface SummaryHeaderProps { surveyId: string; environment: TEnvironment; @@ -54,23 +57,33 @@ const SummaryHeader = ({ const closeOnDate = survey.closeOnDate ? new Date(survey.closeOnDate) : null; const isStatusChangeDisabled = (isCloseOnDateEnabled && closeOnDate && closeOnDate < new Date()) ?? false; const { isViewer } = getAccessFlags(membershipRole); + const [showShareSurveyModal, setShowShareSurveyModal] = useState(false); return (

{survey.name}

- {survey.resultShareKey && } + {survey.resultShareKey && }
{product.name}
- + {/* */} {!isViewer && (environment?.widgetSetupCompleted || survey.type === "link") && survey?.status !== "draft" ? ( ) : null} + {survey.type === "link" && ( + + )} {!isViewer && (
); }; diff --git a/apps/web/app/(app)/share/[sharingKey]/layout.tsx b/apps/web/app/(app)/share/[sharingKey]/layout.tsx index 480eee48cb..1213bc34a8 100644 --- a/apps/web/app/(app)/share/[sharingKey]/layout.tsx +++ b/apps/web/app/(app)/share/[sharingKey]/layout.tsx @@ -7,7 +7,7 @@ export const metadata: Metadata = { export default async function EnvironmentLayout({ children }) { return ( -
+
{children}
); diff --git a/oss.gg b/oss.gg new file mode 160000 index 0000000000..3e15d79895 --- /dev/null +++ b/oss.gg @@ -0,0 +1 @@ +Subproject commit 3e15d79895d8fb4d8af88f4135807b7c949fbe28