"use client"; import { DocumentIcon, CheckCircleIcon, XCircleIcon } from "@heroicons/react/24/outline"; import { Bill, BillingLocation } from "../lib/db-types"; import React, { FC } from "react"; import { updateOrAddBill } from "../lib/actions/billActions"; import Link from "next/link"; import { formatYearMonth } from "../lib/format"; import { useLocale, useTranslations } from "next-intl"; // Next.js does not encode an utf-8 file name correctly when sending a form with a file attachment // This is a workaround for that const updateOrAddBillMiddleware = (locationId: string, billId:string|undefined, billYear:number|undefined, billMonth:number|undefined, prevState:any, formData: FormData) => { // URL encode the file name of the attachment so it is correctly sent to the server const billAttachment = formData.get('billAttachment') as File; formData.set('billAttachment', billAttachment, encodeURIComponent(billAttachment.name)); return updateOrAddBill(locationId, billId, billYear, billMonth, prevState, formData); } export interface ViewBillCardProps { location: BillingLocation, bill?: Bill, } export const ViewBillCard:FC = ({ location, bill }) => { const t = useTranslations("bill-edit-form"); const locale = useLocale(); const { _id: billID, name, paid, attachment, notes, payedAmount, barcodeImage } = bill ?? { _id:undefined, name:"", paid:false, notes:"" }; const { yearMonth:{year: billYear, month: billMonth}, _id: locationID } = location; return(

{`${formatYearMonth(location.yearMonth)} ${location.name}`}

{name}

{t("paid-checkbox")} {paid ? : }

{t("payed-amount")} {payedAmount ? payedAmount/100 : ""}

{ notes ?

{t("notes-placeholder")}

{notes}

: null } { attachment ?

{t("attachment")}

{decodeURIComponent(attachment.fileName)}
: null } { barcodeImage ?

{t.rich('barcode-disclaimer', { br: () =>
})}

: null }
{t("back-button")}
); }