Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions client/src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Input } from "@/components/ui/input";
import { useUser } from "@/hooks/useUser";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Trash2 } from "lucide-react";
import { useFiles } from "@/hooks/useFiles";
//import { sendContactNotification } from "@/lib/mail"; // Removed as it's not relevant to items

export default function Dashboard() {
Expand All @@ -23,6 +24,8 @@ export default function Dashboard() {
const [isNewItemOpen, setIsNewItemOpen] = useState(false);
const [newItem, setNewItem] = useState("");
const [showUpgradeDialog, setShowUpgradeDialog] = useState(false);
const [file, setFile] = useState<File | null>(null);
const { uploadFile } = useFiles();

// Handle checkout success from URL params
useEffect(() => {
Expand Down Expand Up @@ -67,15 +70,21 @@ export default function Dashboard() {
});

const addItemMutation = useMutation({
mutationFn: async (item: string) => {
await apiRequest('POST', '/api/items', {
mutationFn: async ({ item, file }: { item: string; file?: File }) => {
const res = await apiRequest('POST', '/api/items', {
userId: firebaseUser?.uid,
item: item.trim()
});
const created = await res.json();
if (file) {
const uploaded = await uploadFile(file);
await apiRequest('POST', `/api/items/${created.id}/files`, { fileId: uploaded.id });
}
},
onSuccess: () => {
refetch();
setNewItem('');
setFile(null);
setIsNewItemOpen(false);
toast({
title: "Success",
Expand Down Expand Up @@ -124,7 +133,7 @@ export default function Dashboard() {
if (!firebaseUser?.uid || !newItem.trim()) return;

try {
await addItemMutation.mutateAsync(newItem);
await addItemMutation.mutateAsync({ item: newItem, file: file || undefined });
} catch (error) {
toast({
title: "Error",
Expand Down Expand Up @@ -154,6 +163,7 @@ export default function Dashboard() {
value={newItem}
onChange={(e) => setNewItem(e.target.value)}
/>
<Input type="file" onChange={(e) => setFile(e.target.files?.[0] || null)} />
<div className="flex justify-end">
<Button type="submit">Add Item</Button>
</div>
Expand Down
3 changes: 3 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ jest.mock('./server/storage/index', () => ({
createUser: jest.fn(),
updateUser: jest.fn(),
getItemsByUserId: jest.fn().mockResolvedValue([]),
getItemsWithFilesByUserId: jest.fn().mockResolvedValue([]),
createItem: jest.fn(),
deleteItem: jest.fn(),
addFileToItem: jest.fn(),
getFilesByItemId: jest.fn().mockResolvedValue([]),
getFilesByUserId: jest.fn().mockResolvedValue([]),
getFileById: jest.fn(),
getFileByIdAndUserId: jest.fn(),
Expand Down
8 changes: 8 additions & 0 deletions migrations/0002_melted_blink.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE "item_files" (
"id" serial PRIMARY KEY NOT NULL,
"item_id" integer NOT NULL,
"file_id" integer NOT NULL
);
--> statement-breakpoint
ALTER TABLE "item_files" ADD CONSTRAINT "item_files_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "item_files" ADD CONSTRAINT "item_files_file_id_files_id_fk" FOREIGN KEY ("file_id") REFERENCES "public"."files"("id") ON DELETE cascade ON UPDATE no action;
Loading
Loading