Skip to content

Commit

Permalink
Export
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 20, 2023
1 parent 9d37379 commit 795ec16
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 33 deletions.
1 change: 0 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NEXTAUTH_URL=http://localhost:3000
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
RESEND_API_KEY=
Expand Down
8 changes: 4 additions & 4 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "NODE_ENV=production next build",
"clean": "git clean -xdf .next .turbo node_modules",
"jobs": "bunx @trigger.dev/cli@latest dev --port 3001",
"jobs": "bunx @trigger.dev/cli@latest dev --port 3001 --client-id=midday-CpkS",
"dev": "next dev -p 3001",
"lint": "next lint",
"format": "biome format --write .",
Expand Down Expand Up @@ -38,16 +38,16 @@
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.48.2",
"recharts": "^2.9.3",
"recharts": "^2.10.1",
"sharp": "^0.32.6",
"zod": "^3.22.4"
},
"devDependencies": {
"@midday/tsconfig": "workspace:*",
"@t3-oss/env-nextjs": "^0.7.1",
"@types/node": "^20.9.1",
"@types/node": "^20.9.2",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion apps/dashboard/src/actions/export-transactions-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const exportTransactionsAction = action(
},
});

console.log(event);
return event;
}
);
4 changes: 2 additions & 2 deletions apps/dashboard/src/actions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export const createAttachmentsSchema = z.array(
export const deleteAttachmentSchema = z.string();

export const exportTransactionsSchema = z.object({
from: z.string(),
to: z.string(),
from: z.coerce.date(),
to: z.coerce.date(),
});
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/api/download/document/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function GET(req, res) {
const path = requestUrl.searchParams.get("path");
const filename = requestUrl.searchParams.get("filename");

const { data } = await supabase.storage.from("files").download(path);
const { data } = await supabase.storage.from("vault").download(path);
const responseHeaders = new Headers(res.headers);

responseHeaders.set(
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/src/components/attachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function Attachments({ id, data }) {
const uploadedFiles = await Promise.all(
acceptedFiles.map(async (acceptedFile) => {
const { path } = await uploadFile({
bucket: "files",
bucket: "vault",
path: `${userData?.team_id}/transactions/${id}`,
file: acceptedFile,
});
Expand All @@ -99,7 +99,7 @@ export function Attachments({ id, data }) {
transaction_id: id,
type: acceptedFile.type,
};
}),
})
);

const { data: newFiles } = await createAttachmentsAction(uploadedFiles);
Expand All @@ -120,7 +120,7 @@ export function Attachments({ id, data }) {
<div
className={cn(
"w-full h-[120px] border-dotted border-2 border-border rounded-xl text-center flex flex-col justify-center space-y-1 transition-colors text-[#606060]",
isDragActive && "bg-secondary text-white",
isDragActive && "bg-secondary text-white"
)}
{...getRootProps()}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,40 @@ import {
DialogHeader,
DialogTitle,
} from "@midday/ui/dialog";
import { useToast } from "@midday/ui/use-toast";
import { Loader2 } from "lucide-react";
import { useAction } from "next-safe-action/hook";
import { useSearchParams } from "next/navigation";
import { useEffect } from "react";

export function ExportTransactionsModal({ isOpen, setOpen }) {
const searchParams = useSearchParams();
const { execute, status } = useAction(exportTransactionsAction);
const { execute, status, result } = useAction(exportTransactionsAction);
const filter = searchParams.get("filter");
const date = filter ? JSON.parse(filter)?.date : null;
const { toast } = useToast();

useEffect(() => {
if (status === "hasSucceeded" && isOpen) {
setOpen(false);
}
}, [status]);

useEffect(() => {
if (result.data) {
toast({
duration: 6000,
title: "Exporting...",
description: "Your export is ready base on 46 transactions.",
// action: (
// <ToastAction altText="Yes" onClick={handleUpdateSimilar}>
// Yes
// </ToastAction>
// ),
});
}
}, [result]);

return (
<Dialog open={isOpen} onOpenChange={setOpen}>
<DialogContent>
Expand Down
29 changes: 24 additions & 5 deletions apps/dashboard/src/jobs/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TransactionsEmail } from "@midday/email/emails/transactions";
import { getI18n } from "@midday/email/locales";
import { getTransactions } from "@midday/gocardless";
import { TriggerEvents, triggerBulk } from "@midday/notification";
import { getTransactionsQuery } from "@midday/supabase/queries";
import { Database } from "@midday/supabase/src/types";
import { renderAsync } from "@react-email/components";
import { eventTrigger } from "@trigger.dev/sdk";
Expand Down Expand Up @@ -287,23 +288,41 @@ client.defineJob({
trigger: eventTrigger({
name: "transactions.export",
schema: z.object({
from: z.string().datetime(),
to: z.string().datetime(),
from: z.coerce.date(),
to: z.coerce.date(),
teamId: z.string(),
}),
}),
integrations: { supabase },
run: async (payload, io) => {
const { from, to, teamId } = payload;

const generateExport = await io.createStatus("generate-export", {
label: "Generating memes",
const client = await io.supabase.client;

const generateExport = await io.createStatus("generate-export-start", {
label: "Generating export",
state: "loading",
});

await io.logger.info("Transactions Export");

await generateExport.update("generate-export", {
console.log(from, to);

const data = await getTransactionsQuery(client, {
teamId,
from: 0,
to: 100000,
filter: {
date: {
from: from.toDateString(),
to: to.toDateString(),
},
},
});

await io.logger.info(`Transactions: ${JSON.stringify(data, null, 2)}`);

await generateExport.update("generate-export-done", {
state: "success",
data: {
url: "",
Expand Down
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"@midday/tsconfig": "workspace:*",
"@types/node": "^20.9.1",
"@types/node": "^20.9.2",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
email: "Enter your email",
open: "Open source",
live: "Live profit/loss",
document: "Files",
document: "Vault",
reciept: "Receipt linking",
time: "Time tracking",
ai: "AI-enhanced filter & search",
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@biomejs/biome": "1.3.3",
"@manypkg/cli": "^0.21.0",
"turbo": "^1.10.16",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"devDependencies": {
"vercel": "^32.5.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"react-email": "1.9.5"
},
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/gocardless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@midday/kv": "workspace:*"
},
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/location/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"check:types": "tsc --noEmit"
},
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@novu/node": "^0.21.0"
},
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/supabase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"supabase": "^1.112.0"
},
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"exports": {
"./server": "./src/client/server.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/supabase/src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export async function deleteAttachment(supabase: Client, id: string) {
.single();

remove(supabase, {
bucket: "files",
bucket: "vault",
path: `${data.team_id}/transactions/${data.transaction_id}/${data.name}`,
});

Expand Down
1 change: 0 additions & 1 deletion packages/supabase/src/queries/cached-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export const getMetrics = async (params) => {
["metrics", teamId],
{
tags: [`metrics_${teamId}`],
revalidate: 10,
}
)(params);
};
2 changes: 1 addition & 1 deletion packages/supabase/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export async function getSpendingQuery(

type GetTransactionsParams = {
teamId: string;
from: number;
to: number;
from: number;
sort: {
column: string;
value: "asc" | "desc";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"autoprefixer": "^10.4.16",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"exports": {
"./calendar": "./src/components/calendar.tsx",
Expand Down
4 changes: 1 addition & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
}
},
"globalEnv": [
"POSTGRES_URL",
"NEXTAUTH_SECRET",
"NEXTAUTH_URL"
"POSTGRES_URL"
]
}

0 comments on commit 795ec16

Please sign in to comment.