Skip to content

Commit

Permalink
added transaction details in view
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienR1 committed Nov 30, 2023
1 parent da5cb8a commit c9bc0e7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions web/src/modules/categories/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const Color = z
);

export const CategorySchema = z.object({
id: z.number(),
label: z
.string({ invalid_type_error: "Format invalide" })
.min(1, "Saisir un nom"),
Expand Down
9 changes: 2 additions & 7 deletions web/src/modules/dashboards/panels/history/history-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { useDashboard } from "@modules/dashboards/dashboard-provider";
import { dateFormatter, moneyFormatter } from "@/resources/formatters";
import { useDashboard } from "@modules/dashboards";
import { fetchTransactions } from "@modules/transactions";
import { useLocation } from "@solidjs/router";
import { Card, Icon, NoContent, Skeleton, Table, TableRow } from "@ui";
import { Component, For, Show, Suspense, createResource } from "solid-js";

type HistoryPanelProps = {};

const dateFormatter = new Intl.DateTimeFormat("fr-CA", {});
const moneyFormatter = new Intl.NumberFormat("fr-CA", {
style: "currency",
currency: "CAD",
});

export const HistoryPanel: Component<HistoryPanelProps> = (props) => {
const location = useLocation();
const dashboard = useDashboard();
Expand Down
50 changes: 47 additions & 3 deletions web/src/modules/transactions/detailed-transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { dateFormatter, moneyFormatter } from "@/resources/formatters";
import { A, useLocation, useParams } from "@solidjs/router";
import { Accordion, Card, Icon, NoContent, Skeleton, useAccordion } from "@ui";
import {
Accordion,
Card,
Details,
Icon,
NoContent,
Skeleton,
useAccordion,
} from "@ui";
import {
Component,
Show,
Expand Down Expand Up @@ -51,7 +60,42 @@ export const DetailedTransaction: Component<DetailedTransactionProps> = (
}
});

const dashboardLocation = location.pathname.replace(/transactions\/\d+/, "");
const dashboardLocation = location.pathname
.replace(/transactions\/\d+/, "")
.replace(/\/$/, "");

const transactionDetails = () => {
const t = transaction();
if (!t) {
return {};
}

return {
Montant: moneyFormatter.format(t.amount),
Catégorie: () => (
<span class="flex items-center gap-1">
{t.category.label}
<span style={{ color: t.category.color }}>
<Icon name={t.category.icon} size="base" />
</span>
</span>
),
Date: dateFormatter.format(t.timestamp),
Coupable: t.user.firstname + " " + t.user.lastname,
};
};

const transactionLinks = () => {
const t = transaction();
if (!t) {
return {};
}

return {
Catégorie: `${dashboardLocation}/categories/${t.category.id}`,
Coupable: `${dashboardLocation}/profiles/${t.user.id}`,
};
};

return (
<Suspense
Expand All @@ -75,7 +119,7 @@ export const DetailedTransaction: Component<DetailedTransactionProps> = (
controls={generalAccordionControls}
>
<div class="max-w-[430px] overflow-hidden lg:max-w-[800px]">
<pre class="text-xs">{JSON.stringify(transaction(), null, 2)}</pre>
<Details data={transactionDetails()} links={transactionLinks()} />
</div>
</Accordion>

Expand Down

0 comments on commit c9bc0e7

Please sign in to comment.