From cd8c42914fcfeeda7b8471cf84538a1b37cf24ed Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Mon, 10 Jun 2024 20:07:32 +1000 Subject: [PATCH] fix: add tooltip --- .../public-profile-page-view.tsx | 70 ++++++++++++++----- apps/web/src/app/(profile)/p/[url]/page.tsx | 2 +- .../components/forms/public-profile-form.tsx | 37 ++++++++-- 3 files changed, 85 insertions(+), 24 deletions(-) diff --git a/apps/web/src/app/(dashboard)/settings/public-profile/public-profile-page-view.tsx b/apps/web/src/app/(dashboard)/settings/public-profile/public-profile-page-view.tsx index 7af86553d..90759f68e 100644 --- a/apps/web/src/app/(dashboard)/settings/public-profile/public-profile-page-view.tsx +++ b/apps/web/src/app/(dashboard)/settings/public-profile/public-profile-page-view.tsx @@ -15,6 +15,7 @@ import { trpc } from '@documenso/trpc/react'; import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; import { Switch } from '@documenso/ui/primitives/switch'; +import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip'; import { useToast } from '@documenso/ui/primitives/use-toast'; import { SettingsHeader } from '~/components/(dashboard)/settings/layout/header'; @@ -54,6 +55,7 @@ export const PublicProfilePageView = ({ user, team, profile }: PublicProfilePage const { toast } = useToast(); const [isPublicProfileVisible, setIsPublicProfileVisible] = useState(profile.enabled); + const [isTooltipOpen, setIsTooltipOpen] = useState(false); const { data } = trpc.template.findTemplates.useQuery({ perPage: 100, @@ -80,16 +82,22 @@ export const PublicProfilePageView = ({ user, team, profile }: PublicProfilePage const onProfileUpdate = async (data: TPublicProfileFormSchema) => { if (team) { - return updateTeamProfile({ + await updateTeamProfile({ teamId: team.id, ...data, }); + } else { + await updateUserProfile(data); } - return updateUserProfile(data); + if (data.enabled === undefined && !isPublicProfileVisible) { + setIsTooltipOpen(true); + } }; const togglePublicProfileVisibility = async (isVisible: boolean) => { + setIsTooltipOpen(false); + if (isUpdating) { return; } @@ -127,23 +135,47 @@ export const PublicProfilePageView = ({ user, team, profile }: PublicProfilePage return (
-
*:first-child]:text-muted-foreground': !isPublicProfileVisible, - '[&>*:last-child]:text-muted-foreground': isPublicProfileVisible, - }, - )} - > - Hide - - Show -
+ + +
*:first-child]:text-muted-foreground': !isPublicProfileVisible, + '[&>*:last-child]:text-muted-foreground': isPublicProfileVisible, + }, + )} + > + Hide + + Show +
+
+ + + {isPublicProfileVisible ? ( + <> +

+ Profile is currently visible. +

+ +

Toggle the switch to hide your profile from the public.

+ + ) : ( + <> +

+ Profile is currently hidden. +

+ +

Toggle the switch to show your profile to the public.

+ + )} +
+
- + {extractInitials(publicProfile.name)} diff --git a/apps/web/src/components/forms/public-profile-form.tsx b/apps/web/src/components/forms/public-profile-form.tsx index a4263e423..b370b866c 100644 --- a/apps/web/src/components/forms/public-profile-form.tsx +++ b/apps/web/src/components/forms/public-profile-form.tsx @@ -1,9 +1,11 @@ 'use client'; +import { useState } from 'react'; + import { zodResolver } from '@hookform/resolvers/zod'; import { motion } from 'framer-motion'; import { AnimatePresence } from 'framer-motion'; -import { CopyIcon } from 'lucide-react'; +import { CheckSquareIcon, CopyIcon } from 'lucide-react'; import { useForm } from 'react-hook-form'; import type { z } from 'zod'; @@ -55,6 +57,8 @@ export const PublicProfileForm = ({ const [, copy] = useCopyToClipboard(); + const [copiedTimeout, setCopiedTimeout] = useState(null); + const form = useForm({ values: { url: profileUrl ?? '', @@ -103,14 +107,25 @@ export const PublicProfileForm = ({ } }; - const onCopy = async () => - copy(formatUserProfilePath(form.getValues('url') ?? '')).then(() => { + const onCopy = async () => { + await copy(formatUserProfilePath(form.getValues('url') ?? '')).then(() => { toast({ title: 'Copied to clipboard', description: 'The profile link has been copied to your clipboard', }); }); + if (copiedTimeout) { + clearTimeout(copiedTimeout); + } + + setCopiedTimeout( + setTimeout(() => { + setCopiedTimeout(null); + }, 2000), + ); + }; + return (
- + + + {copiedTimeout ? ( + + ) : ( + + )} + +