Skip to content

Commit

Permalink
Vault
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 17, 2023
1 parent e4d5ad0 commit 0851395
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 180 deletions.
2 changes: 2 additions & 0 deletions apps/dashboard/src/actions/share-file-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ export const shareFileAction = action(shareFileSchema, async (value) => {
},
});

console.log(response);

return response?.data?.signedUrl;
});
122 changes: 57 additions & 65 deletions apps/dashboard/src/components/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,69 @@ import { useI18n } from "@/locales/client";
import { Icons } from "@midday/ui/icons";
import { cn } from "@midday/ui/utils";

export const categories = {
travel: "travel",
office_supplies: "office_supplies",
meals: "meals",
software: "software",
rent: "rent",
income: "income",
equipment: "equipment",
transfer: "transfer",
internet_and_telephone: "internet_and_telephone",
facilities_expenses: "facilities_expenses",
activity: "activity",
uncategorized: "uncategorized",
taxes: "taxes",
other: "other",
};

export const mapCategoryColor = (name: string) => {
switch (name) {
case "travel":
return "#ABDD1D";
case "office_supplies":
return "#BB4647";
case "meals":
return "#1ADBDB";
case "software":
return "#0064D9";
case "rent":
return "#A843CB";
case "income":
return "#00C969";
case "equipment":
return "#E9BE26";
case "transfer":
return "#FF902B";
case "internet_and_telephone":
return "#FF8976";
case "facilities_expenses":
return "#A8AABC";
case "activity":
return "#E5E926";
case "uncategorized":
return "#606060";
case "taxes":
return "#B39CD0";
case "other":
return "#F5F5F3";
default:
return;
}
return {
[categories.travel]: "#ABDD1D",
[categories.office_supplies]: "#BB4647",
[categories.meals]: "#1ADBDB",
[categories.software]: "#0064D9",
[categories.rent]: "#A843CB",
[categories.income]: "#00C969",
[categories.equipment]: "#E9BE26",
[categories.transfer]: "#FF902B",
[categories.internet_and_telephone]: "#FF8976",
[categories.facilities_expenses]: "#A8AABC",
[categories.activity]: "#E5E926",
[categories.uncategorized]: "#606060",
[categories.taxes]: "#B39CD0",
[categories.other]: "#F5F5F3",
}[name];
};

export function CategoryIcon({ name, size = 18 }) {
const color = mapCategoryColor(name);

switch (name) {
case "travel":
return <Icons.FlightTakeoff style={{ color }} size={size} />;
case "office_supplies":
return <Icons.Desk style={{ color }} size={size} />;
case "meals":
return <Icons.FastFood style={{ color }} size={size} />;
case "software":
return <Icons.Save style={{ color }} size={size} />;
case "rent":
return <Icons.HomeWork style={{ color }} size={size} />;
case "income":
return <Icons.Payments style={{ color }} size={size} />;
case "equipment":
return <Icons.Devices style={{ color }} size={size} />;
case "transfer":
return <Icons.AccountBalance style={{ color }} size={size} />;
case "other": {
return <Icons.Category style={{ color }} size={size} />;
}
case "activity":
return <Icons.Celebration style={{ color }} size={size} />;
case "uncategorized":
return <Icons.Difference style={{ color }} size={size} />;
case "taxes":
return <Icons.Apartment style={{ color }} size={size} />;
case "internet_and_telephone":
return <Icons.Sensors style={{ color }} size={size} />;
case "facilities_expenses":
return <Icons.DynamicForm style={{ color }} size={size} />;
default:
return null;
}
return {
[categories.travel]: <Icons.FlightTakeoff style={{ color }} size={size} />,
[categories.office_supplies]: <Icons.Desk style={{ color }} size={size} />,
[categories.meals]: <Icons.FastFood style={{ color }} size={size} />,
[categories.software]: <Icons.Save style={{ color }} size={size} />,
[categories.rent]: <Icons.HomeWork style={{ color }} size={size} />,
[categories.income]: <Icons.Payments style={{ color }} size={size} />,
[categories.equipment]: <Icons.Devices style={{ color }} size={size} />,
[categories.transfer]: (
<Icons.AccountBalance style={{ color }} size={size} />
),
[categories.other]: <Icons.Category style={{ color }} size={size} />,
[categories.activity]: <Icons.Celebration style={{ color }} size={size} />,
[categories.uncategorized]: (
<Icons.Difference style={{ color }} size={size} />
),
[categories.taxes]: <Icons.Apartment style={{ color }} size={size} />,
[categories.internet_and_telephone]: (
<Icons.Sensors style={{ color }} size={size} />
),
[categories.facilities_expenses]: (
<Icons.DynamicForm style={{ color }} size={size} />
),
}[name];
}

export function Category({ name, className }) {
Expand Down
6 changes: 5 additions & 1 deletion apps/dashboard/src/components/charts/spending-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ function SpendingCategoryList({ categories }) {
<ul className="absolute z-10 left-8 bottom-8 space-y-2">
{categories.map(({ category }) => (
<li key={category}>
<Link href={`/transactions?filter=${JSON.stringify({ category })}`}>
<Link
href={`/transactions?filter=${JSON.stringify({
categories: [category],
})}`}
>
<Category
key={category}
name={category}
Expand Down
47 changes: 25 additions & 22 deletions apps/dashboard/src/components/export-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { useEffect, useState } from "react";
const options = [
{
label: "Expire in 1 week",
expireIn: ms("1 week"),
expireIn: ms("7d"),
},
{
label: "Expire in 1 month",
expireIn: ms("1 month"),
expireIn: ms("30d"),
},
{
label: "Expire in 1 year",
expireIn: ms("1 year"),
expireIn: ms("1y"),
},
];

Expand All @@ -39,31 +39,30 @@ export function ExportStatus() {
const status = statuses?.at(0);

const shareFile = useAction(shareFileAction, {
onError: () => {
toast({
duration: 2500,
variant: "error",
title: "Something went wrong pleaase try again.",
});
},
onSuccess: async (url) => {
try {
await navigator.clipboard.writeText(url);
await navigator.clipboard.writeText(url);

toast({
duration: 2500,
title: "Copied URL to clipboard.",
variant: "success",
});
} catch {
toast({
duration: 2500,
variant: "error",
title: "Something went wrong pleaase try again.",
});
}
toast({
duration: 2500,
title: "Copied URL to clipboard.",
variant: "success",
});
},
});

const handleOnDownload = (id: string) => {
dismiss(id);
};

const handleOnShare = ({ id, expireIn }) => {
shareFile.execute({ expireIn, filepath: "exports/export-123.zip" });
const handleOnShare = ({ id, expireIn, filename }) => {
shareFile.execute({ expireIn, filepath: `exports/${filename}` });
dismiss(id);
};

Expand Down Expand Up @@ -103,11 +102,15 @@ export function ExportStatus() {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="z-[100]">
{options.map((option) => (
{options.map((option, idx) => (
<DropdownMenuItem
key={option.expireIn}
key={idx.toString()}
onClick={() =>
handleOnShare({ id, expireIn: option.expireIn })
handleOnShare({
id,
expireIn: option.expireIn,
filename: status?.data?.fileName,
})
}
>
{option.label}
Expand Down
Loading

0 comments on commit 0851395

Please sign in to comment.