diff --git a/prisma/migrations/20260107100000_make_expense_document_dimensions_optional/migration.sql b/prisma/migrations/20260107100000_make_expense_document_dimensions_optional/migration.sql new file mode 100644 index 000000000..c205339e0 --- /dev/null +++ b/prisma/migrations/20260107100000_make_expense_document_dimensions_optional/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "ExpenseDocument" ALTER COLUMN "width" DROP NOT NULL; +ALTER TABLE "ExpenseDocument" ALTER COLUMN "height" DROP NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b20aa0e24..0626907e8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -68,8 +68,8 @@ model Expense { model ExpenseDocument { id String @id url String - width Int - height Int + width Int? + height Int? Expense Expense? @relation(fields: [expenseId], references: [id]) expenseId String? } diff --git a/src/components/expense-documents-input.tsx b/src/components/expense-documents-input.tsx index 8c76261f9..bb72f3603 100644 --- a/src/components/expense-documents-input.tsx +++ b/src/components/expense-documents-input.tsx @@ -20,7 +20,7 @@ import { useToast } from '@/components/ui/use-toast' import { randomId } from '@/lib/api' import { ExpenseFormValues } from '@/lib/schemas' import { formatFileSize } from '@/lib/utils' -import { Loader2, Plus, Trash, X } from 'lucide-react' +import { FileText, Loader2, Plus, Trash, X } from 'lucide-react' import { useLocale, useTranslations } from 'next-intl' import { getImageData, usePresignedUpload } from 'next-s3-upload' import Image from 'next/image' @@ -56,8 +56,16 @@ export function ExpenseDocumentsInput({ documents, updateDocuments }: Props) { const upload = async () => { try { setPending(true) - const { width, height } = await getImageData(file) - if (!width || !height) throw new Error('Cannot get image dimensions') + let width = null + let height = null + + if (file.type.startsWith('image/')) { + const dims = await getImageData(file) + width = dims.width + height = dims.height + if (!width || !height) throw new Error('Cannot get image dimensions') + } + const { url } = await uploadToS3(file) updateDocuments([...documents, { id: randomId(), url, width, height }]) } catch (err) { @@ -84,7 +92,10 @@ export function ExpenseDocumentsInput({ documents, updateDocuments }: Props) { return (