-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.tsx
More file actions
62 lines (57 loc) · 1.76 KB
/
Copy pathpage.tsx
File metadata and controls
62 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use client";
import { createIdFromString, sqliteTrue } from "@evolu/common";
import { useAtomValue } from "jotai";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { accountAtom } from "@/atoms/account";
import { BackButton } from "@/components/back-button";
import { ResponsiveCard } from "@/components/responsive-card";
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useEvolu } from "@/hooks/use-evolu";
import { createQuery } from "@/lib/evolu";
import type { Currency } from "@/lib/shared/types";
import { ItemForm } from "../../../item-form";
export default function Home() {
const { t } = useTranslation();
const router = useRouter();
const evolu = useEvolu();
const account = useAtomValue(accountAtom);
const [billingSettings, setBillingSettings] = useState<
{ defaultCurrency?: Currency | null } | undefined
>(undefined);
useEffect(() => {
const query = createQuery((db) =>
db
.selectFrom("billingSettings")
.selectAll()
.where("isDeleted", "is not", sqliteTrue)
.where("id", "=", createIdFromString("")),
);
evolu.loadQuery(query).then((rows) => {
setBillingSettings(rows[0]);
});
}, [evolu]);
return (
<div className={"max-w-xl w-full"}>
<div className={"mb-6"}>
<BackButton />
</div>
<ResponsiveCard>
<CardHeader>
<CardTitle>{t("items:page.newItem")}</CardTitle>
</CardHeader>
<CardContent>
<ItemForm
key={[billingSettings ? "true" : false].join(",")}
onSuccess={() => router.back()}
defaultValues={{
deviceId: account.device.id,
currency: billingSettings?.defaultCurrency,
}}
/>
</CardContent>
</ResponsiveCard>
</div>
);
}