Skip to content

Commit eb57547

Browse files
authored
Fix downloads (#399)
1 parent d75518e commit eb57547

File tree

11 files changed

+116
-68
lines changed

11 files changed

+116
-68
lines changed

apps/dashboard/src/app/[locale]/(public)/i/[token]/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ export default async function Page(props: Props) {
140140
</div>
141141
</div>
142142

143-
<InvoiceToolbar token={invoice.token} />
143+
<InvoiceToolbar
144+
token={invoice.token}
145+
invoiceNumber={invoice.invoiceNumber || "invoice"}
146+
/>
144147

145148
<div className="fixed bottom-4 right-4 hidden md:block">
146149
<a

apps/dashboard/src/components/document-actions.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useDocumentParams } from "@/hooks/use-document-params";
4+
import { downloadFile } from "@/lib/download";
45
import { useTRPC } from "@/trpc/client";
56
import { Button } from "@midday/ui/button";
67
import { Icons } from "@midday/ui/icons";
@@ -61,14 +62,20 @@ export function DocumentActions({ showDelete = false, filePath }: Props) {
6162

6263
return (
6364
<div className="flex flex-row">
64-
<a
65-
href={`/api/download/file?path=${filePath?.join("/")}&filename=${filename}`}
66-
download
65+
<Button
66+
variant="ghost"
67+
size="icon"
68+
onClick={() => {
69+
if (filePath && filename) {
70+
downloadFile(
71+
`/api/download/file?path=${filePath.join("/")}&filename=${filename}`,
72+
filename,
73+
);
74+
}
75+
}}
6776
>
68-
<Button variant="ghost" size="icon">
69-
<Icons.ArrowCoolDown className="size-4" />
70-
</Button>
71-
</a>
77+
<Icons.ArrowCoolDown className="size-4" />
78+
</Button>
7279

7380
<Button
7481
variant="ghost"

apps/dashboard/src/components/export-status.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { shareFileAction } from "@/actions/share-file-action";
44
import { useExportStatus } from "@/hooks/use-export-status";
5+
import { downloadFile } from "@/lib/download";
56
import { useExportStore } from "@/store/export";
67
import { Button } from "@midday/ui/button";
78
import {
@@ -151,14 +152,20 @@ export function ExportStatus() {
151152
</DropdownMenuContent>
152153
</DropdownMenu>
153154

154-
<a
155-
href={`/api/download/file?path=${result.fullPath}&filename=${result.fileName}`}
156-
download
155+
<Button
156+
size="sm"
157+
onClick={() => {
158+
if (result?.fullPath && result?.fileName) {
159+
downloadFile(
160+
`/api/download/file?path=${result.fullPath}&filename=${result.fileName}`,
161+
result.fileName,
162+
);
163+
}
164+
handleOnDownload();
165+
}}
157166
>
158-
<Button size="sm" onClick={handleOnDownload}>
159-
Download
160-
</Button>
161-
</a>
167+
Download
168+
</Button>
162169
</div>
163170
),
164171
});

apps/dashboard/src/components/inbox/inbox-details.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FormatAmount } from "@/components/format-amount";
33
import { useInboxFilterParams } from "@/hooks/use-inbox-filter-params";
44
import { useInboxParams } from "@/hooks/use-inbox-params";
55
import { useUserQuery } from "@/hooks/use-user";
6+
import { downloadFile } from "@/lib/download";
67
import { useTRPC } from "@/trpc/client";
78
import { getUrl } from "@/utils/environment";
89
import { formatDate } from "@/utils/format";
@@ -211,15 +212,17 @@ export function InboxDetails() {
211212
</DialogTrigger>
212213
</DropdownMenuItem>
213214

214-
<DropdownMenuItem>
215-
<a
216-
href={`/api/download/file?path=${data?.filePath?.join(
217-
"/",
218-
)}&filename=${data?.fileName}`}
219-
download
220-
>
221-
Download
222-
</a>
215+
<DropdownMenuItem
216+
onClick={() => {
217+
if (data?.filePath && data?.fileName) {
218+
downloadFile(
219+
`/api/download/file?path=${data.filePath.join("/")}&filename=${data.fileName}`,
220+
data.fileName,
221+
);
222+
}
223+
}}
224+
>
225+
Download
223226
</DropdownMenuItem>
224227
<DropdownMenuItem
225228
onClick={() =>

apps/dashboard/src/components/invoice-details.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useInvoiceParams } from "@/hooks/use-invoice-params";
4+
import { downloadFile } from "@/lib/download";
45
import { useTRPC } from "@/trpc/client";
56
import { getUrl } from "@/utils/environment";
67
import { getWebsiteLogo } from "@/utils/logos";
@@ -196,16 +197,20 @@ export function InvoiceDetails() {
196197
</div>
197198

198199
{status !== "draft" && (
199-
<a href={`/api/download/invoice?id=${id}`} download>
200-
<Button
201-
variant="secondary"
202-
className="size-[38px] hover:bg-secondary shrink-0"
203-
>
204-
<div>
205-
<Icons.ArrowCoolDown className="size-4" />
206-
</div>
207-
</Button>
208-
</a>
200+
<Button
201+
variant="secondary"
202+
className="size-[38px] hover:bg-secondary shrink-0"
203+
onClick={() => {
204+
downloadFile(
205+
`/api/download/invoice?id=${id}`,
206+
`${invoiceNumber}.pdf`,
207+
);
208+
}}
209+
>
210+
<div>
211+
<Icons.ArrowCoolDown className="size-4" />
212+
</div>
213+
</Button>
209214
)}
210215
</div>
211216
</div>

apps/dashboard/src/components/invoice-success.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useInvoiceParams } from "@/hooks/use-invoice-params";
4+
import { downloadFile } from "@/lib/download";
45
import { useTRPC } from "@/trpc/client";
56
import { getUrl } from "@/utils/environment";
67
import { formatEditorContent } from "@midday/invoice/format-to-html";
@@ -141,16 +142,20 @@ export function InvoiceSuccess() {
141142
<CopyInput value={`${getUrl()}/i/${invoice.token}`} />
142143
</div>
143144

144-
<a href={`/api/download/invoice?id=${invoice.id}`} download>
145-
<Button
146-
variant="secondary"
147-
className="size-[40px] hover:bg-secondary shrink-0"
148-
>
149-
<div>
150-
<Icons.ArrowCoolDown className="size-4" />
151-
</div>
152-
</Button>
153-
</a>
145+
<Button
146+
variant="secondary"
147+
className="size-[40px] hover:bg-secondary shrink-0"
148+
onClick={() => {
149+
downloadFile(
150+
`/api/download/invoice?id=${invoice.id}`,
151+
`${invoice.invoiceNumber}.pdf`,
152+
);
153+
}}
154+
>
155+
<div>
156+
<Icons.ArrowCoolDown className="size-4" />
157+
</div>
158+
</Button>
154159
</div>
155160
</div>
156161
</motion.div>

apps/dashboard/src/components/invoice-toolbar.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { downloadFile } from "@/lib/download";
34
import { Button } from "@midday/ui/button";
45
import {
56
Tooltip,
@@ -13,9 +14,10 @@ import { useCopyToClipboard } from "usehooks-ts";
1314

1415
type Props = {
1516
token: string;
17+
invoiceNumber: string;
1618
};
1719

18-
export default function InvoiceToolbar({ token }: Props) {
20+
export default function InvoiceToolbar({ token, invoiceNumber }: Props) {
1921
const [, copy] = useCopyToClipboard();
2022

2123
const handleCopyLink = () => {
@@ -34,15 +36,19 @@ export default function InvoiceToolbar({ token }: Props) {
3436
<TooltipProvider delayDuration={0}>
3537
<Tooltip>
3638
<TooltipTrigger asChild>
37-
<a href={`/api/download/invoice?token=${token}`} download>
38-
<Button
39-
variant="ghost"
40-
size="icon"
41-
className="rounded-full size-8"
42-
>
43-
<MdOutlineFileDownload className="size-[18px]" />
44-
</Button>
45-
</a>
39+
<Button
40+
variant="ghost"
41+
size="icon"
42+
className="rounded-full size-8"
43+
onClick={() => {
44+
downloadFile(
45+
`/api/download/invoice?token=${token}`,
46+
`${invoiceNumber}.pdf`,
47+
);
48+
}}
49+
>
50+
<MdOutlineFileDownload className="size-[18px]" />
51+
</Button>
4652
</TooltipTrigger>
4753
<TooltipContent
4854
sideOffset={15}

apps/dashboard/src/components/tables/invoices/actions-menu.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { OpenURL } from "@/components/open-url";
44
import { useInvoiceParams } from "@/hooks/use-invoice-params";
5+
import { downloadFile } from "@/lib/download";
56
import { useTRPC } from "@/trpc/client";
67
import { getUrl } from "@/utils/environment";
78
import { Button } from "@midday/ui/button";
@@ -137,10 +138,15 @@ export function ActionsMenu({ row }: Props) {
137138
</DropdownMenuItem>
138139

139140
{row.status !== "draft" && (
140-
<DropdownMenuItem>
141-
<a href={`/api/download/invoice?id=${row.id}`} download>
142-
Download
143-
</a>
141+
<DropdownMenuItem
142+
onClick={() => {
143+
downloadFile(
144+
`/api/download/invoice?id=${row.id}`,
145+
`${row.invoiceNumber || "invoice"}.pdf`,
146+
);
147+
}}
148+
>
149+
Download
144150
</DropdownMenuItem>
145151
)}
146152

apps/dashboard/src/components/vault/vault-item-actions.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { downloadFile } from "@/lib/download";
34
import { useTRPC } from "@/trpc/client";
45
import { Button } from "@midday/ui/button";
56
import { Icons } from "@midday/ui/icons";
@@ -55,15 +56,19 @@ export function VaultItemActions({ id, filePath, hideDelete }: Props) {
5556

5657
return (
5758
<div className="flex flex-row gap-2">
58-
<a href={`${downloadUrl}&filename=${fileName}`} download>
59-
<Button
60-
variant="outline"
61-
size="icon"
62-
className="rounded-full size-7 bg-background"
63-
>
64-
<Icons.ArrowCoolDown className="size-3.5" />
65-
</Button>
66-
</a>
59+
<Button
60+
variant="outline"
61+
size="icon"
62+
className="rounded-full size-7 bg-background"
63+
onClick={() => {
64+
downloadFile(
65+
`${downloadUrl}&filename=${fileName}`,
66+
fileName || "download",
67+
);
68+
}}
69+
>
70+
<Icons.ArrowCoolDown className="size-3.5" />
71+
</Button>
6772

6873
<Button
6974
variant="outline"

apps/desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "Midday"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
description = ""
55
authors = ["Midday Labs AB"]
66
edition = "2024"

0 commit comments

Comments
 (0)