mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 07:43:16 +10:00
fix: add tooltip
This commit is contained in:
@ -15,6 +15,7 @@ import { trpc } from '@documenso/trpc/react';
|
|||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { Switch } from '@documenso/ui/primitives/switch';
|
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 { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import { SettingsHeader } from '~/components/(dashboard)/settings/layout/header';
|
import { SettingsHeader } from '~/components/(dashboard)/settings/layout/header';
|
||||||
@ -54,6 +55,7 @@ export const PublicProfilePageView = ({ user, team, profile }: PublicProfilePage
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const [isPublicProfileVisible, setIsPublicProfileVisible] = useState(profile.enabled);
|
const [isPublicProfileVisible, setIsPublicProfileVisible] = useState(profile.enabled);
|
||||||
|
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
|
||||||
|
|
||||||
const { data } = trpc.template.findTemplates.useQuery({
|
const { data } = trpc.template.findTemplates.useQuery({
|
||||||
perPage: 100,
|
perPage: 100,
|
||||||
@ -80,16 +82,22 @@ export const PublicProfilePageView = ({ user, team, profile }: PublicProfilePage
|
|||||||
|
|
||||||
const onProfileUpdate = async (data: TPublicProfileFormSchema) => {
|
const onProfileUpdate = async (data: TPublicProfileFormSchema) => {
|
||||||
if (team) {
|
if (team) {
|
||||||
return updateTeamProfile({
|
await updateTeamProfile({
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
...data,
|
...data,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await updateUserProfile(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateUserProfile(data);
|
if (data.enabled === undefined && !isPublicProfileVisible) {
|
||||||
|
setIsTooltipOpen(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const togglePublicProfileVisibility = async (isVisible: boolean) => {
|
const togglePublicProfileVisibility = async (isVisible: boolean) => {
|
||||||
|
setIsTooltipOpen(false);
|
||||||
|
|
||||||
if (isUpdating) {
|
if (isUpdating) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -127,23 +135,47 @@ export const PublicProfilePageView = ({ user, team, profile }: PublicProfilePage
|
|||||||
return (
|
return (
|
||||||
<div className="max-w-2xl">
|
<div className="max-w-2xl">
|
||||||
<SettingsHeader title={profileText.settingsTitle} subtitle={profileText.settingsSubtitle}>
|
<SettingsHeader title={profileText.settingsTitle} subtitle={profileText.settingsSubtitle}>
|
||||||
<div
|
<Tooltip open={isTooltipOpen} onOpenChange={setIsTooltipOpen}>
|
||||||
className={cn(
|
<TooltipTrigger asChild>
|
||||||
'text-muted-foreground/50 flex flex-row items-center justify-center space-x-2 text-xs',
|
<div
|
||||||
{
|
className={cn(
|
||||||
'[&>*:first-child]:text-muted-foreground': !isPublicProfileVisible,
|
'text-muted-foreground/50 flex flex-row items-center justify-center space-x-2 text-xs',
|
||||||
'[&>*:last-child]:text-muted-foreground': isPublicProfileVisible,
|
{
|
||||||
},
|
'[&>*:first-child]:text-muted-foreground': !isPublicProfileVisible,
|
||||||
)}
|
'[&>*:last-child]:text-muted-foreground': isPublicProfileVisible,
|
||||||
>
|
},
|
||||||
<span>Hide</span>
|
)}
|
||||||
<Switch
|
>
|
||||||
disabled={isUpdating}
|
<span>Hide</span>
|
||||||
checked={isPublicProfileVisible}
|
<Switch
|
||||||
onCheckedChange={togglePublicProfileVisibility}
|
disabled={isUpdating}
|
||||||
/>
|
checked={isPublicProfileVisible}
|
||||||
<span>Show</span>
|
onCheckedChange={togglePublicProfileVisibility}
|
||||||
</div>
|
/>
|
||||||
|
<span>Show</span>
|
||||||
|
</div>
|
||||||
|
</TooltipTrigger>
|
||||||
|
|
||||||
|
<TooltipContent className="text-muted-foreground max-w-[40ch] space-y-2 py-2">
|
||||||
|
{isPublicProfileVisible ? (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
Profile is currently <strong>visible</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Toggle the switch to hide your profile from the public.</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
Profile is currently <strong>hidden</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Toggle the switch to show your profile to the public.</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
</SettingsHeader>
|
</SettingsHeader>
|
||||||
|
|
||||||
<PublicProfileForm
|
<PublicProfileForm
|
||||||
|
|||||||
@ -58,7 +58,7 @@ export default async function PublicProfilePage({ params }: PublicProfilePagePro
|
|||||||
<div className="flex flex-col items-center justify-center py-4 sm:py-32">
|
<div className="flex flex-col items-center justify-center py-4 sm:py-32">
|
||||||
<div className="flex flex-col items-center">
|
<div className="flex flex-col items-center">
|
||||||
<Avatar className="dark:border-border h-24 w-24 border-2 border-solid">
|
<Avatar className="dark:border-border h-24 w-24 border-2 border-solid">
|
||||||
<AvatarFallback className="text-xs text-gray-400">
|
<AvatarFallback className="text-sm text-gray-400">
|
||||||
{extractInitials(publicProfile.name)}
|
{extractInitials(publicProfile.name)}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { AnimatePresence } 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 { useForm } from 'react-hook-form';
|
||||||
import type { z } from 'zod';
|
import type { z } from 'zod';
|
||||||
|
|
||||||
@ -55,6 +57,8 @@ export const PublicProfileForm = ({
|
|||||||
|
|
||||||
const [, copy] = useCopyToClipboard();
|
const [, copy] = useCopyToClipboard();
|
||||||
|
|
||||||
|
const [copiedTimeout, setCopiedTimeout] = useState<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
const form = useForm<TPublicProfileFormSchema>({
|
const form = useForm<TPublicProfileFormSchema>({
|
||||||
values: {
|
values: {
|
||||||
url: profileUrl ?? '',
|
url: profileUrl ?? '',
|
||||||
@ -103,14 +107,25 @@ export const PublicProfileForm = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCopy = async () =>
|
const onCopy = async () => {
|
||||||
copy(formatUserProfilePath(form.getValues('url') ?? '')).then(() => {
|
await copy(formatUserProfilePath(form.getValues('url') ?? '')).then(() => {
|
||||||
toast({
|
toast({
|
||||||
title: 'Copied to clipboard',
|
title: 'Copied to clipboard',
|
||||||
description: 'The profile link has been copied to your clipboard',
|
description: 'The profile link has been copied to your clipboard',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (copiedTimeout) {
|
||||||
|
clearTimeout(copiedTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
setCopiedTimeout(
|
||||||
|
setTimeout(() => {
|
||||||
|
setCopiedTimeout(null);
|
||||||
|
}, 2000),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
@ -152,7 +167,21 @@ export const PublicProfileForm = ({
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="ml-1 flex h-6 w-6 items-center justify-center rounded transition-all hover:bg-neutral-200 hover:active:bg-neutral-300 dark:hover:bg-neutral-500 dark:hover:active:bg-neutral-400">
|
<div className="ml-1 flex h-6 w-6 items-center justify-center rounded transition-all hover:bg-neutral-200 hover:active:bg-neutral-300 dark:hover:bg-neutral-500 dark:hover:active:bg-neutral-400">
|
||||||
<CopyIcon className="h-3.5 w-3.5" />
|
<AnimatePresence mode="wait" initial={false}>
|
||||||
|
<motion.div
|
||||||
|
key={copiedTimeout ? 'copied' : 'copy'}
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={{ opacity: 0, transition: { duration: 0.1 } }}
|
||||||
|
className="absolute"
|
||||||
|
>
|
||||||
|
{copiedTimeout ? (
|
||||||
|
<CheckSquareIcon className="h-3.5 w-3.5" />
|
||||||
|
) : (
|
||||||
|
<CopyIcon className="h-3.5 w-3.5" />
|
||||||
|
)}
|
||||||
|
</motion.div>
|
||||||
|
</AnimatePresence>
|
||||||
</div>
|
</div>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user