From 4dfe1d9af016dad6113720f1b33ed8d531c09d0a Mon Sep 17 00:00:00 2001 From: Johannes <72809645+jobenjada@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:02:15 +0100 Subject: [PATCH] chore: tweak sharing results UX (#1964) --- .../summary/components/ShareSurveyResults.tsx | 2 +- .../components/ResultsShareButton.tsx | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareSurveyResults.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareSurveyResults.tsx index 4830522f62..3261f1bcec 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareSurveyResults.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareSurveyResults.tsx @@ -53,7 +53,7 @@ export default function ShareSurveyResults({ className="hover:cursor-pointer" onClick={() => { navigator.clipboard.writeText(surveyUrl); - toast.success("URL copied to clipboard!"); + toast.success("Link copied to clipboard!"); }}> diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResultsShareButton.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResultsShareButton.tsx index 3b3f6e612a..d6c6a952bb 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResultsShareButton.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResultsShareButton.tsx @@ -76,16 +76,15 @@ export default function ResultsShareButton({ survey, webAppUrl, product, user }: 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 + const currentUrl = window.location.href; navigator.clipboard - .writeText(currentUrl) // Copy it to the clipboard + .writeText(currentUrl) .then(() => { - toast.success("Link to results copied to clipboard."); // Show success message + toast.success("Link to results copied to clipboard."); }) .catch((err) => { - console.error("Failed to copy: ", err); // Handle any errors - toast.error("Failed to copy link to results to clipboard."); // Show error message + console.error("Failed to copy: ", err); + toast.error("Failed to copy link to results to clipboard."); }); } else { console.error("Cannot copy URL: not running in a browser environment."); @@ -107,22 +106,36 @@ export default function ResultsShareButton({ survey, webAppUrl, product, user }: - { - copyUrlToClipboard(); - }}> - - Copy link - - + {survey.resultShareKey ? ( + { + navigator.clipboard.writeText(surveyUrl); + toast.success("Link to public results copied"); + }}> + + Copy link to public results + + + ) : ( + { + copyUrlToClipboard(); + }}> + + Copy link + + + )} { setShowResultsLinkModal(true); }}> - Publish to web + {survey.resultShareKey ? "Unpublish from web" : "Publish to web"} +
- Copy link -
+ Copy link to public results +
+ Copy link +
- Publish to web + {survey.resultShareKey ? "Unpublish from web" : "Publish to web"} +