-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
474 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
## Dashboard | ||
## | ||
## Dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use server"; | ||
|
||
// import { LogEvents } from "@midday/events/events"; | ||
// import { setupLogSnag } from "@midday/events/server"; | ||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { nanoid } from "nanoid"; | ||
import { revalidateTag } from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { createBankAccountSchema } from "./schema"; | ||
|
||
export const createBankAccountAction = action( | ||
createBankAccountSchema, | ||
async ({ name, currency }) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
const teamId = user?.data?.team_id; | ||
|
||
const { data, error } = await supabase | ||
.from("decrypted_bank_accounts") | ||
.insert({ | ||
name, | ||
currency, | ||
team_id: teamId, | ||
created_by: user?.data?.id, | ||
enabled: true, | ||
account_id: nanoid(), | ||
manual: true, | ||
}) | ||
.select("id, name:decrypted_name") | ||
.single(); | ||
|
||
if (error) { | ||
throw Error(error.message); | ||
} | ||
|
||
revalidateTag(`bank_accounts_${teamId}`); | ||
revalidateTag(`bank_accounts_currencies_${teamId}`); | ||
|
||
// const logsnag = await setupLogSnag({ | ||
// userId: user.data.id, | ||
// fullName: user.data.full_name, | ||
// }); | ||
|
||
// logsnag.track({ | ||
// event: LogEvents.CategoryCreate.name, | ||
// icon: LogEvents.CategoryCreate.icon, | ||
// channel: LogEvents.CategoryCreate.channel, | ||
// }); | ||
|
||
return data; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
apps/dashboard/src/components/forms/import-transactions-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
"use client"; | ||
|
||
import { | ||
type CreateTransactionsFormValues, | ||
createTransactionsSchema, | ||
} from "@/actions/schema"; | ||
import { FormatAmount } from "@/components/format-amount"; | ||
import { SelectAccount } from "@/components/select-account"; | ||
import { SelectCurrency } from "@/components/select-currency"; | ||
import { formatTransactionDate } from "@/utils/format"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { Button } from "@midday/ui/button"; | ||
import { cn } from "@midday/ui/cn"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormMessage, | ||
} from "@midday/ui/form"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@midday/ui/table"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
type Props = { | ||
defaultCurrency: string; | ||
}; | ||
|
||
export function ImportTransactionsForm({ | ||
currencies, | ||
defaultCurrency, | ||
transactions, | ||
}: Props) { | ||
const form = useForm<CreateTransactionsFormValues>({ | ||
resolver: zodResolver(createTransactionsSchema), | ||
defaultValues: { | ||
accountId: undefined, | ||
currency: defaultCurrency, | ||
}, | ||
}); | ||
|
||
const onSubmit = form.handleSubmit((data) => {}); | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={onSubmit}> | ||
<div className="flex space-x-2"> | ||
<FormField | ||
control={form.control} | ||
name="accountId" | ||
render={({ field }) => ( | ||
<FormItem className="w-full"> | ||
<FormControl> | ||
<SelectAccount | ||
className="w-full" | ||
placeholder="Select account" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormDescription> | ||
Select or create a new account. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<FormField | ||
control={form.control} | ||
name="currency" | ||
render={({ field }) => ( | ||
<FormItem className="w-full"> | ||
<FormControl> | ||
<SelectCurrency | ||
className="w-full" | ||
{...field} | ||
currencies={Object.values(currencies)?.map( | ||
(currency) => currency | ||
)} | ||
/> | ||
</FormControl> | ||
<FormDescription> | ||
Select the currency for your transactions. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
|
||
<div className="h-[480px] overflow-auto mt-8 mb-4"> | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead className="w-[80px]">Date</TableHead> | ||
<TableHead>Description</TableHead> | ||
<TableHead className="text-right">Amount</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{transactions?.map((transaction) => ( | ||
<TableRow key={transaction.internal_id} className="h-[45px]"> | ||
<TableCell> | ||
{transaction?.date && | ||
formatTransactionDate(transaction.date)} | ||
</TableCell> | ||
<TableCell | ||
className={transaction.amount > 0 && "text-[#00C969]"} | ||
> | ||
{transaction.name} | ||
</TableCell> | ||
<TableCell | ||
className={cn( | ||
"text-right", | ||
transaction.amount > 0 && "text-[#00C969]" | ||
)} | ||
> | ||
<FormatAmount | ||
amount={transaction.amount} | ||
currency={form.watch("currency")} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</div> | ||
|
||
<div className="w-full absolute bottom-0 left-0 h-[150px] flex flex-col justify-end pointer-events-none bg-gradient-to-b from-transparent via-background to-background"> | ||
<Button className="w-full">Save</Button> | ||
</div> | ||
</form> | ||
</Form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.