Add user authentication with JWT login and registration
This commit is contained in:
@@ -14,6 +14,10 @@ import {
|
||||
} from "lucide-react";
|
||||
import {
|
||||
getTransactions,
|
||||
getDeals,
|
||||
updateDeal,
|
||||
clearDeals,
|
||||
getNeedsClassify,
|
||||
runReconciliation,
|
||||
classifyTransactions,
|
||||
formatAmount,
|
||||
@@ -150,8 +154,7 @@ export default function Transactions() {
|
||||
setClassifyProgress(task.progress || 0);
|
||||
const poll = setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch("/api/transactions/needs-classify");
|
||||
const { total } = await res.json();
|
||||
const { total } = await getNeedsClassify();
|
||||
const p =
|
||||
task.total > 0
|
||||
? Math.round(((task.total - total) / task.total) * 100)
|
||||
@@ -192,12 +195,10 @@ export default function Transactions() {
|
||||
async function loadDeals(f) {
|
||||
setDealLoading(true);
|
||||
try {
|
||||
const p = new URLSearchParams();
|
||||
Object.entries(f).forEach(([k, v]) => {
|
||||
if (v !== "" && v !== undefined) p.set(k, v);
|
||||
});
|
||||
const r = await fetch("/api/deals?" + p);
|
||||
setDeals(await r.json());
|
||||
const params = {};
|
||||
for (const [k, v] of Object.entries(f))
|
||||
if (v !== "" && v !== undefined) params[k] = v;
|
||||
setDeals(await getDeals(params));
|
||||
} catch (e) {}
|
||||
setDealLoading(false);
|
||||
}
|
||||
@@ -234,13 +235,9 @@ export default function Transactions() {
|
||||
async function handleUpdateDeal() {
|
||||
if (!editingDeal) return;
|
||||
try {
|
||||
await fetch("/api/deals/" + editingDeal.id, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
category: editingDeal.category,
|
||||
ai_description: editingDeal.ai_description,
|
||||
}),
|
||||
await updateDeal(editingDeal.id, {
|
||||
category: editingDeal.category,
|
||||
ai_description: editingDeal.ai_description,
|
||||
});
|
||||
setEditingDeal(null);
|
||||
loadDeals(dealFilters);
|
||||
@@ -252,8 +249,15 @@ export default function Transactions() {
|
||||
|
||||
async function handleClearDeals() {
|
||||
try {
|
||||
await fetch("/api/deals/clear", { method: "POST" });
|
||||
setDeals({ deals: [], total: 0, page: 1, totalPages: 0 });
|
||||
await clearDeals();
|
||||
setDeals({
|
||||
deals: [],
|
||||
total: 0,
|
||||
page: 1,
|
||||
totalPages: 0,
|
||||
totalIncome: 0,
|
||||
totalExpense: 0,
|
||||
});
|
||||
setClearConfirm(false);
|
||||
} catch (e) {}
|
||||
}
|
||||
@@ -280,8 +284,7 @@ export default function Transactions() {
|
||||
JSON.stringify({ total: 0, progress: 0, ts: Date.now() }),
|
||||
);
|
||||
try {
|
||||
const res = await fetch("/api/transactions/needs-classify");
|
||||
const { ids, total } = await res.json();
|
||||
const { ids, total } = await getNeedsClassify();
|
||||
if (!ids.length) {
|
||||
showToast("所有交易分类均有效!", "info");
|
||||
setClassifying(false);
|
||||
|
||||
Reference in New Issue
Block a user