Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 24, 2023
1 parent 6aa1b4c commit db9dadb
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 94 deletions.
14 changes: 14 additions & 0 deletions apps/dashboard/src/actions/connect-bank-account-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use server";

import { getUser } from "@midday/supabase/cached-queries";
import { action } from "./safe-action";
import { connectBankAccountSchema } from "./schema";

export const connectBankAccountAction = action(
connectBankAccountSchema,
async (value) => {
const user = await getUser();

return value;
}
);
3 changes: 3 additions & 0 deletions apps/dashboard/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export async function createBankAccountsAction(accounts) {
const { data } = await createBankAccounts(supabase, accounts);
const teamId = data.at(0).team_id;

// TODO: Send event to trigger.dev
// Kick off initial fetch and setup scheduler

revalidateTag(`bank_connections_${teamId}`);

return data;
Expand Down
78 changes: 30 additions & 48 deletions apps/dashboard/src/components/charts/chart-period.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
"use client";

import { changeChartPeriodAction } from "@/actions/change-chart-period-action";
import { DateRangePicker } from "@midday/ui/date-range-picker";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@midday/ui/select";
import { Button } from "@midday/ui/button";
import { Icons } from "@midday/ui/icons";
import { MonthRangePicker } from "@midday/ui/month-range-picker";
import { Popover, PopoverContent, PopoverTrigger } from "@midday/ui/popover";
import { format } from "date-fns";
import { useAction } from "next-safe-action/hook";
import { parseAsString, useQueryStates } from "next-usequerystate";
Expand All @@ -19,18 +14,10 @@ export function ChartPeriod({ initialValue, defaultValue, disabled }) {

const { execute } = useAction(changeChartPeriodAction);

const handleChangePeriod = (params) => {
setState(params);
execute(params);
};

const [state, setState] = useQueryStates(
{
to: parseAsString.withDefault(initialValue?.to ?? undefined),
from: parseAsString.withDefault(initialValue?.from ?? undefined),
period: parseAsString.withDefault(
initialValue?.period ?? defaultValue.period
),
to: parseAsString.withDefault(initialValue?.to ?? undefined),
},
{
shallow: false,
Expand All @@ -52,38 +39,33 @@ export function ChartPeriod({ initialValue, defaultValue, disabled }) {
)} `;
}

const handleChangePeriod = (params) => {
const range = {
...state,
...(params.from && { from: params.from }),
...(params.to && { to: params.to }),
};

execute(range);
setState(range);
};

return (
<div className="flex space-x-4">
<DateRangePicker
disabled={disabled}
placeholder={placeholder}
range={{
from: state?.from && new Date(state.from),
to: state?.to && new Date(state.to),
}}
onSelect={(range) => {
handleChangePeriod({
from: range?.from ? new Date(range.from).toISOString() : null,
to: range?.to ? new Date(range.to).toISOString() : null,
});
}}
/>

<Select
disabled={disabled}
defaultValue={state.period}
onValueChange={(period) => handleChangePeriod({ period })}
>
<SelectTrigger className="w-[130px] font-medium">
<SelectValue placeholder="Monthly" />
</SelectTrigger>
<SelectContent className="mt-1">
<SelectGroup>
<SelectItem value="monthly">Monthly</SelectItem>
<SelectItem value="weekly">Weekly</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<Popover>
<PopoverTrigger asChild disabled={disabled}>
<Button
variant="outline"
className="justify-start text-left font-medium space-x-2"
>
<span>{placeholder}</span>
<Icons.ChevronDown />
</Button>
</PopoverTrigger>
<PopoverContent className="w-[450px] mt-2 pt-1" align="end">
<MonthRangePicker setDate={handleChangePeriod} date={state} />
</PopoverContent>
</Popover>
</div>
);
}
3 changes: 2 additions & 1 deletion apps/dashboard/src/components/charts/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export async function Chart({ value, defaultValue, disabled }) {
? chartData
: await getMetrics({ ...defaultValue, ...value, type });

const lastPeriodAmount = data.result[data.result.length - 1]?.current?.value;
const lastPeriodAmount =
data?.result[data.result?.length - 1]?.current?.value;

return (
<div className="relative mt-28">
Expand Down
10 changes: 7 additions & 3 deletions apps/dashboard/src/components/counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const InnerCounter = ({ currency, pad, value, locale }) => {
})
.format(paddedValue)
.split("")
.map((character, index) => {
.map((character) => {
if (!Number.isNaN(parseInt(character, 10)) && i < padCount) {
i++;
return "0";
Expand Down Expand Up @@ -100,8 +100,12 @@ export function Counter({

return (
<>
<InnerCounter value={value} currency={currency} locale={locale} />
<InnerCounter value={value} currency={currency} locale={locale} />
{value > 0 && (
<InnerCounter value={value} currency={currency} locale={locale} />
)}
{value > 0 && (
<InnerCounter value={value} currency={currency} locale={locale} />
)}
</>
);
}
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export function Filter({ sections }: Props) {

return (
<div className="flex items-center">
<Popover open={isOpen} onOpenChange={setOpen} size>
<Popover open={isOpen} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button variant="outline" className="space-x-2">
<span>Add filter</span>
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/main-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function MainMenu() {
];

return (
<nav className="mt-6 ml-1">
<nav className="mt-6">
<ul className="flex flex-col gap-0.5">
{items.map((item) => {
const { path, icon: Icon, name } = item;
Expand All @@ -69,7 +69,7 @@ export function MainMenu() {
>
<li
className={cn(
"rounded-lg border border-transparent w-[55px] h-[45px] flex items-center justify-center",
"rounded-lg border border-transparent w-[45px] h-[45px] flex items-center justify-center",
"hover:bg-secondary hover:border-[#DCDAD2] hover:dark:border-[#2C2C2C]",
isActive &&
"bg-secondary border-[#DCDAD2] dark:border-[#2C2C2C]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ export function SelectAccountModal({ countryCode }) {
},
}));

// Change to use safe-action and listen to loading and disable modal close and button
await createBankAccountsAction(accountsWithDetails);

router.push(`${pathname}?step=desktop`);
}

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function Sidebar() {
return (
<aside className="h-screen flex-shrink-0 flex-col justify-between flex sticky top-0 ml-4 pb-4 items-center">
<div className="flex flex-col items-center justify-center xl:items-start xl:justify-start">
<div className="mt-6 xl:ml-4">
<div className="mt-6">
<Link href="/">
<Icons.LogoSmall />
</Link>
Expand Down
1 change: 0 additions & 1 deletion packages/jobs/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const Jobs = {
BANK_ACCOUNT_CREATED: "bank-account-created",
TRANSACTIONS_ENCRICHMENT: "transactions-encrichment",
TRANSACTIONS_EXPORT: "transactions-export",
TRANSACTIONS_INITIAL_SYNC: "transactions-initial-sync",
Expand Down
32 changes: 0 additions & 32 deletions packages/jobs/src/transactions/created.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/jobs/src/transactions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./created";
export * from "./encrichment";
export * from "./export";
export * from "./initial";
Expand Down
2 changes: 0 additions & 2 deletions packages/jobs/src/transactions/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ client.defineJob({

if (emailEvents?.length) {
triggerBulk(emailEvents);
await io.logger.log(`Sending emails: ${emailEvents.length}`);
await io.logger.log(`Emails: ${JSON.stringify(emailEvents, null, 2)}`);
}
},
});

0 comments on commit db9dadb

Please sign in to comment.