From 439de9d305be150d4d263df3451c3c284585af54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Fri, 13 Dec 2024 15:38:48 +0100 Subject: [PATCH] implementirano kopiranje linka --- app/ui/LocationCard.tsx | 14 +++++++++++++- app/ui/MonthLocationList.tsx | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index 822ecc8..1ed0c93 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -1,6 +1,6 @@ 'use client'; -import { Cog8ToothIcon, PlusCircleIcon } from "@heroicons/react/24/outline"; +import { Cog8ToothIcon, PlusCircleIcon, LinkIcon } from "@heroicons/react/24/outline"; import { FC } from "react"; import { BillBadge } from "./BillBadge"; import { BillingLocation } from "../lib/db-types"; @@ -8,6 +8,7 @@ import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; import Link from "next/link"; import { useTranslations } from "next-intl"; +import { toast, useToast } from "react-toastify"; export interface LocationCardProps { location: BillingLocation @@ -19,6 +20,15 @@ export const LocationCard:FC = ({location: { _id, name, yearM // sum all the billAmounts const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); + + const handleCopyLinkClick = () => { + // copy URL to clipboard + const url = `${window.location.origin}/share/location/${_id}`; + navigator.clipboard.writeText(url); + + // use NextJS toast to notiy user that the link was copied + toast.success(t("link-copy-message"), {theme: "dark"}); + } return(
@@ -42,6 +52,8 @@ export const LocationCard:FC = ({location: { _id, name, yearM

: null } + +
); }; \ No newline at end of file diff --git a/app/ui/MonthLocationList.tsx b/app/ui/MonthLocationList.tsx index 6a59ad6..8555cc6 100644 --- a/app/ui/MonthLocationList.tsx +++ b/app/ui/MonthLocationList.tsx @@ -8,6 +8,8 @@ import Pagination from "./Pagination"; import { LocationCard } from "./LocationCard"; import { BillingLocation, YearMonth } from "../lib/db-types"; import { useRouter, useSearchParams } from "next/navigation"; +import { ToastContainer } from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; const getNextYearMonth = (yearMonth:YearMonth) => { const {year, month} = yearMonth; @@ -88,6 +90,6 @@ export const MonthLocationList:React.FC = ({
- + ) } \ No newline at end of file