From fb6cff2fe3101e80d2932285c0b03e0d5be872f8 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Thu, 7 Dec 2023 19:38:03 -0500 Subject: Share button --- src/app/groups/[groupId]/expenses/expense-list.tsx | 2 +- src/app/groups/[groupId]/layout.tsx | 16 ++++-- src/app/groups/[groupId]/share-button.tsx | 42 +++++++++++++++ src/app/layout.tsx | 2 +- src/components/copy-button.tsx | 34 +++++++++++++ src/components/ui/alert.tsx | 59 ++++++++++++++++++++++ src/components/ui/popover.tsx | 31 ++++++++++++ 7 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 src/app/groups/[groupId]/share-button.tsx create mode 100644 src/components/copy-button.tsx create mode 100644 src/components/ui/alert.tsx create mode 100644 src/components/ui/popover.tsx (limited to 'src') diff --git a/src/app/groups/[groupId]/expenses/expense-list.tsx b/src/app/groups/[groupId]/expenses/expense-list.tsx index 907a37a..13a85bd 100644 --- a/src/app/groups/[groupId]/expenses/expense-list.tsx +++ b/src/app/groups/[groupId]/expenses/expense-list.tsx @@ -29,7 +29,7 @@ export function ExpenseList({
{ diff --git a/src/app/groups/[groupId]/layout.tsx b/src/app/groups/[groupId]/layout.tsx index 5fbd7cb..ca50762 100644 --- a/src/app/groups/[groupId]/layout.tsx +++ b/src/app/groups/[groupId]/layout.tsx @@ -1,5 +1,6 @@ import { GroupTabs } from '@/app/groups/[groupId]/group-tabs' import { SaveGroupLocally } from '@/app/groups/[groupId]/save-recent-group' +import { ShareButton } from '@/app/groups/[groupId]/share-button' import { getGroup } from '@/lib/api' import { Metadata } from 'next' import Link from 'next/link' @@ -34,11 +35,16 @@ export default async function GroupLayout({ return ( <> -

- {group.name} -

- - +
+

+ {group.name} +

+ +
+ + +
+
{children} diff --git a/src/app/groups/[groupId]/share-button.tsx b/src/app/groups/[groupId]/share-button.tsx new file mode 100644 index 0000000..808f3a0 --- /dev/null +++ b/src/app/groups/[groupId]/share-button.tsx @@ -0,0 +1,42 @@ +import { CopyButton } from '@/components/copy-button' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { + Popover, + PopoverContent, + PopoverTrigger, +} from '@/components/ui/popover' +import { env } from '@/lib/env' +import { Share } from 'lucide-react' + +type Props = { + groupId: string +} + +export function ShareButton({ groupId }: Props) { + const url = `${env.NEXT_PUBLIC_BASE_URL}/groups/${groupId}` + + return ( + + + + + +

+ For other participants to see the group and add expenses, share its + URL with them. +

+
+ + +
+

+ Warning! Every person with the group URL will be able + to see and edit expenses. Share with caution! +

+
+
+ ) +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8943688..2c08513 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -55,7 +55,7 @@ export default function RootLayout({

Spliit { + if (copied) { + let timeout = setTimeout(() => setCopied(false), 1000) + return () => { + setCopied(false) + clearTimeout(timeout) + } + } + }, [copied]) + + return ( + + ) +} diff --git a/src/components/ui/alert.tsx b/src/components/ui/alert.tsx new file mode 100644 index 0000000..41fa7e0 --- /dev/null +++ b/src/components/ui/alert.tsx @@ -0,0 +1,59 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const alertVariants = cva( + "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground", + { + variants: { + variant: { + default: "bg-background text-foreground", + destructive: + "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", + }, + }, + defaultVariants: { + variant: "default", + }, + } +) + +const Alert = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes & VariantProps +>(({ className, variant, ...props }, ref) => ( +
+)) +Alert.displayName = "Alert" + +const AlertTitle = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertTitle.displayName = "AlertTitle" + +const AlertDescription = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertDescription.displayName = "AlertDescription" + +export { Alert, AlertTitle, AlertDescription } diff --git a/src/components/ui/popover.tsx b/src/components/ui/popover.tsx new file mode 100644 index 0000000..a0ec48b --- /dev/null +++ b/src/components/ui/popover.tsx @@ -0,0 +1,31 @@ +"use client" + +import * as React from "react" +import * as PopoverPrimitive from "@radix-ui/react-popover" + +import { cn } from "@/lib/utils" + +const Popover = PopoverPrimitive.Root + +const PopoverTrigger = PopoverPrimitive.Trigger + +const PopoverContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( + + + +)) +PopoverContent.displayName = PopoverPrimitive.Content.displayName + +export { Popover, PopoverTrigger, PopoverContent } -- cgit v1.3