feat(mobile): touch up new-invoice + scan-receipt forms
- new invoice: push "New Invoice" to mobile topbar, hide the
redundant inline back+title row on mobile.
- scan receipt: dedicated "Take photo" primary button on mobile
(uses input capture="environment" to open the camera directly)
plus "Choose from library" secondary. Drop-zone framing kept on
desktop. Push "Scan Receipt" title to mobile topbar.
Both forms now take their entity title from the topbar and free up
real-estate at the top for actual content.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useRef } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
import { useMutation } from '@tanstack/react-query';
|
import { useMutation } from '@tanstack/react-query';
|
||||||
import { Upload, Loader2, ScanLine } from 'lucide-react';
|
import { Camera, Loader2, ScanLine, Upload } from 'lucide-react';
|
||||||
|
|
||||||
|
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
@@ -33,9 +35,16 @@ export default function ScanReceiptPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const cameraInputRef = useRef<HTMLInputElement>(null);
|
||||||
const [scanResult, setScanResult] = useState<ScanResult | null>(null);
|
const [scanResult, setScanResult] = useState<ScanResult | null>(null);
|
||||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const { setChrome } = useMobileChrome();
|
||||||
|
useEffect(() => {
|
||||||
|
setChrome({ title: 'Scan Receipt', showBackButton: true });
|
||||||
|
return () => setChrome({ title: null, showBackButton: false });
|
||||||
|
}, [setChrome]);
|
||||||
|
|
||||||
// Editable fields from scan
|
// Editable fields from scan
|
||||||
const [establishment, setEstablishment] = useState('');
|
const [establishment, setEstablishment] = useState('');
|
||||||
const [amount, setAmount] = useState('');
|
const [amount, setAmount] = useState('');
|
||||||
@@ -94,7 +103,7 @@ export default function ScanReceiptPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-2xl mx-auto space-y-6">
|
<div className="max-w-2xl mx-auto space-y-6">
|
||||||
<div>
|
<div className="hidden sm:block">
|
||||||
<h1 className="text-2xl font-bold">Scan Receipt</h1>
|
<h1 className="text-2xl font-bold">Scan Receipt</h1>
|
||||||
<p className="text-muted-foreground mt-1">
|
<p className="text-muted-foreground mt-1">
|
||||||
Upload a receipt image and we will extract the expense details automatically.
|
Upload a receipt image and we will extract the expense details automatically.
|
||||||
@@ -109,28 +118,44 @@ export default function ScanReceiptPage() {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div
|
{previewUrl ? (
|
||||||
className="border-2 border-dashed rounded-lg p-8 text-center cursor-pointer hover:bg-muted/50 transition-colors"
|
<div
|
||||||
onClick={() => fileInputRef.current?.click()}
|
className="border-2 border-dashed rounded-lg p-4 text-center cursor-pointer hover:bg-muted/50 transition-colors"
|
||||||
>
|
onClick={() => fileInputRef.current?.click()}
|
||||||
{previewUrl ? (
|
>
|
||||||
<img
|
<img
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
alt="Receipt preview"
|
alt="Receipt preview"
|
||||||
className="max-h-64 mx-auto rounded object-contain"
|
className="max-h-64 mx-auto rounded object-contain"
|
||||||
/>
|
/>
|
||||||
) : (
|
</div>
|
||||||
<div className="space-y-2">
|
) : (
|
||||||
<Upload className="h-8 w-8 mx-auto text-muted-foreground" />
|
<div className="grid gap-2 sm:grid-cols-2">
|
||||||
<p className="text-sm text-muted-foreground">
|
<Button
|
||||||
Click to upload or drag and drop
|
type="button"
|
||||||
</p>
|
size="lg"
|
||||||
<p className="text-xs text-muted-foreground">
|
className="w-full h-14 sm:hidden"
|
||||||
JPEG, PNG, WebP up to 10MB
|
onClick={() => cameraInputRef.current?.click()}
|
||||||
</p>
|
>
|
||||||
</div>
|
<Camera className="mr-2 h-5 w-5" />
|
||||||
)}
|
Take photo
|
||||||
</div>
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="lg"
|
||||||
|
className="w-full h-14"
|
||||||
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
>
|
||||||
|
<Upload className="mr-2 h-5 w-5" />
|
||||||
|
<span className="sm:hidden">Choose from library</span>
|
||||||
|
<span className="hidden sm:inline">Click to upload or drag and drop</span>
|
||||||
|
</Button>
|
||||||
|
<p className="text-xs text-muted-foreground sm:col-span-2 text-center">
|
||||||
|
JPEG, PNG, WebP up to 10MB
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<input
|
<input
|
||||||
ref={fileInputRef}
|
ref={fileInputRef}
|
||||||
type="file"
|
type="file"
|
||||||
@@ -138,6 +163,14 @@ export default function ScanReceiptPage() {
|
|||||||
className="hidden"
|
className="hidden"
|
||||||
onChange={handleFileChange}
|
onChange={handleFileChange}
|
||||||
/>
|
/>
|
||||||
|
<input
|
||||||
|
ref={cameraInputRef}
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
capture="environment"
|
||||||
|
className="hidden"
|
||||||
|
onChange={handleFileChange}
|
||||||
|
/>
|
||||||
|
|
||||||
{scanMutation.isPending && (
|
{scanMutation.isPending && (
|
||||||
<div className="flex items-center justify-center gap-2 mt-4 text-muted-foreground">
|
<div className="flex items-center justify-center gap-2 mt-4 text-muted-foreground">
|
||||||
@@ -222,25 +255,18 @@ export default function ScanReceiptPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{saveMutation.isError && (
|
{saveMutation.isError && (
|
||||||
<p className="text-sm text-destructive">
|
<p className="text-sm text-destructive">{(saveMutation.error as Error).message}</p>
|
||||||
{(saveMutation.error as Error).message}
|
|
||||||
</p>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex gap-2 pt-2">
|
<div className="flex gap-2 pt-2">
|
||||||
<Button
|
<Button variant="outline" onClick={() => router.push(`/${params.portSlug}/expenses`)}>
|
||||||
variant="outline"
|
|
||||||
onClick={() => router.push(`/${params.portSlug}/expenses`)}
|
|
||||||
>
|
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => saveMutation.mutate()}
|
onClick={() => saveMutation.mutate()}
|
||||||
disabled={saveMutation.isPending || !amount}
|
disabled={saveMutation.isPending || !amount}
|
||||||
>
|
>
|
||||||
{saveMutation.isPending && (
|
{saveMutation.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
||||||
)}
|
|
||||||
Save as Expense
|
Save as Expense
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
import { useForm, FormProvider } from 'react-hook-form';
|
import { useForm, FormProvider } from 'react-hook-form';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useMutation } from '@tanstack/react-query';
|
import { useMutation } from '@tanstack/react-query';
|
||||||
import { ChevronLeft, ChevronRight, Check, Loader2 } from 'lucide-react';
|
import { ChevronLeft, ChevronRight, Check, Loader2 } from 'lucide-react';
|
||||||
|
|
||||||
|
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -46,6 +48,12 @@ export default function NewInvoicePage() {
|
|||||||
|
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(1);
|
||||||
|
|
||||||
|
const { setChrome } = useMobileChrome();
|
||||||
|
useEffect(() => {
|
||||||
|
setChrome({ title: 'New Invoice', showBackButton: true });
|
||||||
|
return () => setChrome({ title: null, showBackButton: false });
|
||||||
|
}, [setChrome]);
|
||||||
|
|
||||||
const methods = useForm<CreateInvoiceInput>({
|
const methods = useForm<CreateInvoiceInput>({
|
||||||
resolver: zodResolver(createInvoiceSchema),
|
resolver: zodResolver(createInvoiceSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -117,8 +125,8 @@ export default function NewInvoicePage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-2xl mx-auto space-y-6">
|
<div className="max-w-2xl mx-auto space-y-6">
|
||||||
{/* Header */}
|
{/* Header — desktop only; mobile gets the title from the topbar */}
|
||||||
<div className="flex items-center gap-3">
|
<div className="hidden sm:flex items-center gap-3">
|
||||||
<Button variant="ghost" size="sm" onClick={() => router.push(`/${portSlug}/invoices`)}>
|
<Button variant="ghost" size="sm" onClick={() => router.push(`/${portSlug}/invoices`)}>
|
||||||
<ChevronLeft className="h-4 w-4" />
|
<ChevronLeft className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user