implementiran share by link

This commit is contained in:
2024-12-13 17:50:12 +01:00
parent 439de9d305
commit 4ab61f9917
15 changed files with 312 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ import { BillingLocation } from "../lib/db-types";
import { formatYearMonth } from "../lib/format";
import { formatCurrency } from "../lib/formatStrings";
import Link from "next/link";
import { useTranslations } from "next-intl";
import { useLocale, useTranslations } from "next-intl";
import { toast, useToast } from "react-toastify";
export interface LocationCardProps {
@@ -17,13 +17,14 @@ export interface LocationCardProps {
export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, yearMonth, bills }}) => {
const t = useTranslations("home-page.location-card");
const currentLocale = useLocale();
// 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}`;
const url = `${window.location.origin}/${currentLocale}/share/location/${_id}`;
navigator.clipboard.writeText(url);
// use NextJS toast to notiy user that the link was copied