Skip to content

Commit

Permalink
feat(budget-app): refactor all numbro consume into globla lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 4, 2024
1 parent 10b94b4 commit 78b87a3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 33 deletions.
3 changes: 2 additions & 1 deletion budget-app/src/app/budget/components/AvailableChip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use client";
import { formatNumberThousand } from "@/global/formatNumberThousand";
import { Chip } from "@mui/material";
import numbro from "numbro";

Expand All @@ -17,7 +18,7 @@ export function AvailableChip(props: AvailableChipProps) {
}
return (
<Chip
label={numbro(props.available).format("0,0")}
label={formatNumberThousand(props.available)}
size="small"
sx={{
"&.MuiChip-root": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ExpandLess from "@mui/icons-material/ExpandLess";
import ExpandMore from "@mui/icons-material/ExpandMore";
import { BudgetGroupItem } from "./types";
import numbro from "numbro";
import { formatNumberThousand } from "@/global/formatNumberThousand";

export interface CategoryGroupDropDownListProps {
onClick?: () => void;
Expand Down Expand Up @@ -63,7 +64,7 @@ export function CategoryGroupDropDownList(
padding: 0,
}}
>
{numbro(props.header.totalAssigned).format("0,0")}
{formatNumberThousand(props.header.totalAssigned)}
</ListTableColumn>
<ListTableColumn
ratio={20}
Expand All @@ -77,7 +78,7 @@ export function CategoryGroupDropDownList(
>
{props.header.countOverspent > 0 ? (
<Chip
label={numbro(props.header.totalAvailable).format("0,0")}
label={formatNumberThousand(props.header.totalAvailable)}
size="small"
sx={{
"&.MuiChip-root": {
Expand All @@ -90,7 +91,7 @@ export function CategoryGroupDropDownList(
}}
/>
) : (
numbro(props.header.totalAvailable).format("0,0")
formatNumberThousand(props.header.totalAvailable)
)}
</ListTableColumn>
</ListTableRow>
Expand Down
21 changes: 0 additions & 21 deletions budget-app/src/app/budget/components/ListRow/BudgetProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,4 @@ export function BudgetProgress({ items, value }: BudgetProgressProps) {
} else {
return <BudgetLinearProgress variant="determinate" value={value} />;
}

// if (activity > 0 && activity <= available) {
// return (
// <Box>
// <SpendingLinearProgress variant="determinate" value={value} />
// <Box
// sx={{
// fontSize: "0.85rem",
// color: theme.palette.text.secondary,
// paddingTop: "10px",
// }}
// >
// {Math.abs(activity - available) < 1
// ? "Fully Spent"
// : `Spent ${numbro(activity).format("0,0")} of
// ${numbro(available).format("0,0")}`}
// </Box>
// </Box>
// );
// }
// return <BudgetLinearProgress variant="determinate" value={value} />;
}
3 changes: 2 additions & 1 deletion budget-app/src/app/budget/components/ListRow/ListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AutoSelectTextField } from "../AutoSelectNumberTextField";
import { ListTableColumn, ListTableRow } from "../layouts";
import numbro from "numbro";
import { BudgetProgress } from "./BudgetProgress";
import { formatNumberThousand } from "@/global/formatNumberThousand";

const ListContainer = styled(Box)(() => ({
display: "flex",
Expand Down Expand Up @@ -83,7 +84,7 @@ export function ListRow(props: ListRowProps) {
fontSize: theme.budget.amount.fontSize,
}}
>
{numbro(items.assigned).format("0,0")}
{formatNumberThousand(items.assigned)}
</Box>
) : null}
</ListTableColumn>
Expand Down
3 changes: 2 additions & 1 deletion budget-app/src/app/budget/components/StickerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useTheme } from "@mui/material/styles";
import { Box, Typography } from "@mui/material";
import numbro from "numbro";
import { formatNumberThousand } from "@/global/formatNumberThousand";

export interface StickyHeaderProps {
summary: {
Expand Down Expand Up @@ -53,7 +54,7 @@ export function StickyHeader({ summary, height }: StickyHeaderProps) {
// textAlign: "right",
}}
>
{numbro(readyToAssign).format("0,0")}
{formatNumberThousand(readyToAssign)}
<br />
{errorMessage}
</Box>
Expand Down
3 changes: 2 additions & 1 deletion budget-app/src/app/budget/components/layouts.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatNumberThousand } from "@/global/formatNumberThousand";
import { Box, styled, Typography, useTheme } from "@mui/material";
import numbro from "numbro";

Expand Down Expand Up @@ -39,7 +40,7 @@ export function MoneyColumn(
...(props.sx ?? {}),
}}
>
{numbro(props.value).format("0,0")}
{formatNumberThousand(props.value)}
</Box>
);
}
Expand Down
3 changes: 2 additions & 1 deletion budget-app/src/app/components/TransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dayjs from "dayjs";
import { ListItemButton } from "@mui/material";
import numbro from "numbro";
import { useRouter } from "next/navigation";
import { formatNumberThousand } from "@/global/formatNumberThousand";

/**
* Hotfix for uuid gen
Expand Down Expand Up @@ -100,7 +101,7 @@ export function TransactionList(props: TransactionListProps) {
> */}
{item.payee}
{/* </Typography> */}
{` — ${numbro(item.amount).format("0,0")} on ${dayjs(
{` — ${formatNumberThousand(item.amount)} on ${dayjs(
item.date
).format("MMM DD")}`}
{dayjs().year().toString() !==
Expand Down
16 changes: 12 additions & 4 deletions budget-app/src/global/formatNumberThousand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import numbro from "numbro";

export type NumbroFormatOption = Parameters<ReturnType<typeof numbro>["format"]>[0];
export type NumbroFormatOption = Parameters<
ReturnType<typeof numbro>["format"]
>[0];

/**
* Format number to thousand using numbro
*/
export function formatNumberThousand(num: number, formatOptions?: NumbroFormatOption) {
return numbro(num).format(formatOptions ?? "0,0")
}
export function formatNumberThousand(
num: number | undefined,
formatOptions?: NumbroFormatOption
) {
if (num === undefined) {
return "";
}
return numbro(num).format(formatOptions ?? "0,0");
}

0 comments on commit 78b87a3

Please sign in to comment.