Skip to content

Commit

Permalink
Vault
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 28, 2023
1 parent 3a48081 commit 6602b85
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Breadcrumbs } from "@/components/breadcrumbs";
import { Table } from "@/components/tables/vault";
import { Metadata } from "next";

Expand All @@ -6,5 +7,10 @@ export const metadata: Metadata = {
};

export default function Vault({ params }) {
return <Table path={params?.folders?.join("/")} />;
return (
<div>
<Breadcrumbs folders={params?.folders} />
<Table path={params?.folders?.join("/")} />
</div>
);
}
3 changes: 3 additions & 0 deletions apps/dashboard/src/components/breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Breadcrumbs({ folders }) {
return folders?.map((folder) => <span key={folder}>{folder}</span>);
}
28 changes: 28 additions & 0 deletions apps/dashboard/src/components/file-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Icons } from "@midday/ui/icons";

export function FileIcon({ mimetype, name }) {
if (name === "exports") {
return <Icons.DriveFileMove size={16} className="text-[#878787]" />;
}

if (name === "inbox") {
return <Icons.FolderOpen size={16} className="text-[#878787]" />;
}

if (name === "transactions") {
return <Icons.Topic size={16} className="text-[#878787]" />;
}

if (mimetype?.startsWith("image")) {
return <Icons.BrokenImage size={16} className="text-[#878787]" />;
}

switch (mimetype) {
case "application/pdf":
return <Icons.Pdf size={16} className="text-[#878787]" />;
case "application/zip":
return <Icons.FolderZip size={16} className="text-[#878787]" />;
default:
return <Icons.Description size={16} className="text-[#878787]" />;
}
}
25 changes: 22 additions & 3 deletions apps/dashboard/src/components/tables/vault/data-table-row.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
"use client";

import { FileIcon } from "@/components/file-icon";
import { formatSize } from "@/utils/format";
import { Icons } from "@midday/ui/icons";
import { TableCell, TableRow } from "@midday/ui/table";
import { format } from "date-fns";
import { usePathname, useRouter } from "next/navigation";

export function DataTableRow({ data }) {
const router = useRouter();
const pathname = usePathname();

const handleNavigate = () => router.push(`${pathname}/${data.name}`);

return (
<TableRow className="h-[45px]" onClick={handleNavigate}>
<TableCell>{data.name}</TableCell>
<TableCell>{data.created_at}</TableCell>
<TableCell>wef</TableCell>
<TableCell>
<div className="flex items-center space-x-2">
<FileIcon mimetype={data?.metadata?.mimetype} name={data.name} />
<span>{data.name}</span>
{data?.metadata?.size && (
<span className="text-[#878787]">
{formatSize(data.metadata.size)}
</span>
)}
</div>
</TableCell>
<TableCell>
{data?.created_at && format(new Date(data.created_at), "MMM d, yyyy")}
</TableCell>
<TableCell>
<Icons.MoreHoriz size={16} />
</TableCell>
</TableRow>
);
}
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/tables/vault/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export function DataTable({ data }) {
<TableHeader>
<TableRow>
<TableHead className="w-[60%]">Name</TableHead>
<TableHead>Uploaded</TableHead>
<TableHead className="text-right">Actions</TableHead>
<TableHead className="w-full">Uploaded</TableHead>
<TableHead className="text-right w-full">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
Expand Down
139 changes: 68 additions & 71 deletions packages/jobs/src/transactions/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getI18n } from "@midday/email/locales";
import { TriggerEvents, triggerBulk } from "@midday/notification";
import { renderAsync } from "@react-email/components";
import { eventTrigger } from "@trigger.dev/sdk";
import { revalidateTag } from "next/cache";
import { z } from "zod";
import { client, supabase } from "../client";
import { Events, Jobs } from "../constants";
Expand Down Expand Up @@ -36,83 +35,81 @@ client.defineJob({
.select("team_id, user:user_id(id, full_name, avatar_url, email, locale)")
.eq("team_id", teamId);

if (transactions?.length && transactions.length > 0) {
revalidateTag(`transactions_${teamId}`);
revalidateTag(`spending_${teamId}`);
revalidateTag(`metrics_${teamId}`);
const notificationEvents = await Promise.all(
usersData?.map(async ({ user, team_id }) => {
const { t } = getI18n({ locale: user.locale });

const notificationEvents = await Promise.all(
usersData?.map(async ({ user, team_id }) => {
const { t } = getI18n({ locale: user.locale });
return transactions.map((transaction) => ({
name: TriggerEvents.TransactionNewInApp,
payload: {
transactionId: transaction.id,
description: t(
{ id: "notifications.transaction" },
{
amount: Intl.NumberFormat(user.locale, {
style: "currency",
currency: transaction.currency,
}).format(transaction.amount),
from: transaction.name,
}
),
},
user: {
subscriberId: user.id,
teamId: team_id,
email: user.email,
fullName: user.full_name,
avatarUrl: user.avatar_url,
},
}));
})
);

return transactions.map((transaction) => ({
name: TriggerEvents.TransactionNewInApp,
payload: {
transactionId: transaction.id,
description: t(
{ id: "notifications.transaction" },
{
amount: Intl.NumberFormat(user.locale, {
style: "currency",
currency: transaction.currency,
}).format(transaction.amount),
from: transaction.name,
}
),
},
user: {
subscriberId: user.id,
teamId: team_id,
email: user.email,
fullName: user.full_name,
avatarUrl: user.avatar_url,
},
}));
})
if (notificationEvents?.length) {
await io.logger.log(
`Sending notifications: ${notificationEvents.length}`
);
triggerBulk(notificationEvents.flat());
}

if (notificationEvents?.length) {
triggerBulk(notificationEvents.flat());
}

const emailEvents = await Promise.all(
usersData?.map(async ({ user, team_id }) => {
const { t } = getI18n({ locale: user.locale });
const emailEvents = await Promise.all(
usersData?.map(async ({ user, team_id }) => {
const { t } = getI18n({ locale: user.locale });

const html = await renderAsync(
TransactionsEmail({
fullName: user.full_name,
transactions: transactions.map((transaction) => ({
id: transaction.id,
date: transaction.date,
amount: transaction.amount,
name: transaction.name,
currency: transaction.currency,
})),
locale: user.locale,
})
);
const html = await renderAsync(
TransactionsEmail({
fullName: user.full_name,
transactions: transactions.map((transaction) => ({
id: transaction.id,
date: transaction.date,
amount: transaction.amount,
name: transaction.name,
currency: transaction.currency,
})),
locale: user.locale,
})
);

return {
name: TriggerEvents.TransactionNewEmail,
payload: {
subject: t({ id: "transactions.subject" }),
html,
},
user: {
subscriberId: user.id,
teamId: team_id,
email: user.email,
fullName: user.full_name,
avatarUrl: user.avatar_url,
},
};
})
);
return {
name: TriggerEvents.TransactionNewEmail,
payload: {
subject: t({ id: "transactions.subject" }),
html,
},
user: {
subscriberId: user.id,
teamId: team_id,
email: user.email,
fullName: user.full_name,
avatarUrl: user.avatar_url,
},
};
})
);

if (emailEvents?.length) {
triggerBulk(emailEvents);
}
if (emailEvents?.length) {
await io.logger.log(`Sending emails: ${emailEvents.length}`);
triggerBulk(emailEvents);
}
},
});
42 changes: 26 additions & 16 deletions packages/jobs/src/transactions/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ client.defineJob({
.eq("id", ctx.source.id)
.single();

const teamId = data?.team_id;

// Update bank account last_accessed
await io.supabase.client
.from("bank_accounts")
Expand All @@ -26,8 +28,8 @@ client.defineJob({
})
.eq("id", ctx.source.id);

revalidateTag(`bank_accounts_${data?.team_id}`);
await io.logger.info(`bank_accounts_${data?.team_id}`);
revalidateTag(`bank_accounts_${teamId}`);
await io.logger.info(`bank_accounts_${teamId}`);

if (!data) {
await io.logger.error(`Bank account not found: ${ctx.source.id}`);
Expand All @@ -42,7 +44,7 @@ client.defineJob({
.upsert(
transformTransactions(transactions?.booked, {
accountId: data?.id,
teamId: data?.team_id,
teamId,
}),
{
onConflict: "internal_id",
Expand All @@ -51,20 +53,28 @@ client.defineJob({
)
.select();

await io.sendEvent("🔔 Send notifications", {
name: Events.TRANSACTIONS_NOTIFICATION,
payload: {
teamId: data?.team_id,
transactions: transactionsData,
},
});
if (transactionsData && transactionsData.length > 0) {
await io.logger.log(`Sending notifications: ${transactionsData.length}`);

revalidateTag(`transactions_${teamId}`);
revalidateTag(`spending_${teamId}`);
revalidateTag(`metrics_${teamId}`);

await io.sendEvent("💅 Enrich Transactions", {
name: Events.TRANSACTIONS_ENCRICHMENT,
payload: {
teamId: data?.team_id,
},
});
await io.sendEvent("🔔 Send notifications", {
name: Events.TRANSACTIONS_NOTIFICATION,
payload: {
teamId,
transactions: transactionsData,
},
});

await io.sendEvent("💅 Enrich Transactions", {
name: Events.TRANSACTIONS_ENCRICHMENT,
payload: {
teamId,
},
});
}

if (error) {
await io.logger.error(JSON.stringify(error, null, 2));
Expand Down
16 changes: 16 additions & 0 deletions packages/ui/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { Settings } from "lucide-react";
import {
MdApartment,
MdBarChart,
MdBrokenImage,
MdCelebration,
MdDescription,
MdDesk,
MdDevices,
MdDriveFileMove,
MdDynamicForm,
MdExpandMore,
MdFastfood,
MdFence,
MdFlightTakeoff,
MdFolderOpen,
MdFolderZip,
MdHomeWork,
MdInventory2,
MdMoreHoriz,
MdOutlineAccountBalanceWallet,
MdOutlineCategory,
MdOutlineDescription,
Expand All @@ -25,9 +31,11 @@ import {
MdPayments,
MdPeople,
MdPerson,
MdPictureAsPdf,
MdRefresh,
MdSave,
MdSensors,
MdTopic,
MdTrendingDown,
MdTrendingUp,
} from "react-icons/md";
Expand Down Expand Up @@ -316,4 +324,12 @@ export const Icons = {
Apartment: MdApartment,
Sensors: MdSensors,
DynamicForm: MdDynamicForm,
MoreHoriz: MdMoreHoriz,
Pdf: MdPictureAsPdf,
DriveFileMove: MdDriveFileMove,
FolderOpen: MdFolderOpen,
Topic: MdTopic,
BrokenImage: MdBrokenImage,
Description: MdDescription,
FolderZip: MdFolderZip,
};

0 comments on commit 6602b85

Please sign in to comment.