Files
star-erp/resources/js/Components/Sales/SalesImportDialog.tsx
sky121113 08e360464e
Some checks failed
Koori-ERP-Deploy-System / deploy-production (push) Has been cancelled
Koori-ERP-Deploy-System / deploy-demo (push) Has been cancelled
refactor(sales): remove import template download and update dialog instructions
2026-02-09 17:21:35 +08:00

127 lines
6.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from "@/Components/ui/dialog";
import { Button } from "@/Components/ui/button";
import { Input } from "@/Components/ui/input";
import { Label } from "@/Components/ui/label";
import { Upload, AlertCircle, Info } from "lucide-react";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/Components/ui/accordion";
import { useForm } from "@inertiajs/react";
import { Alert, AlertDescription } from "@/Components/ui/alert";
import React from "react";
interface SalesImportDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}
export default function SalesImportDialog({ open, onOpenChange }: SalesImportDialogProps) {
const { data, setData, post, processing, errors, reset, clearErrors } = useForm<{
file: File | null;
}>({
file: null,
});
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
setData("file", e.target.files[0]);
clearErrors("file");
}
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
post(route("sales-imports.store"), {
onSuccess: () => {
reset();
onOpenChange(false);
},
});
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
Excel
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-6">
{/* 上傳檔案區域 */}
<div className="space-y-2">
<Label className="font-medium flex items-center gap-2">
<Upload className="w-4 h-4 text-blue-600" />
</Label>
<div className="grid w-full max-w-sm items-center gap-1.5">
<Input
id="file"
type="file"
accept=".xlsx, .xls, .csv"
onChange={handleFileChange}
className="cursor-pointer"
/>
</div>
{errors.file && (
<Alert variant="destructive" className="mt-2">
<AlertCircle className="h-4 w-4" />
<AlertDescription className="whitespace-pre-wrap">
{errors.file}
</AlertDescription>
</Alert>
)}
<p className="text-xs text-gray-500">.xlsx, .xls, .csv</p>
</div>
{/* 匯入說明 - 使用 Accordion 收合 */}
<Accordion type="single" collapsible className="w-full border rounded-lg px-2" defaultValue="item-1">
<AccordionItem value="item-1" className="border-b-0">
<AccordionTrigger className="text-sm text-gray-500 hover:no-underline py-3">
<div className="flex items-center gap-2">
<Info className="h-4 w-4" />
()
</div>
</AccordionTrigger>
<AccordionContent>
<div className="text-sm text-gray-600 space-y-2 pb-2 pl-6">
<p className="mb-2"> Excel </p>
<ul className="list-disc space-y-1 text-xs">
<li><span className="font-medium text-gray-700">A (0)</span> (Serial)</li>
<li><span className="font-medium text-gray-700">B (1)</span> (Machine ID)</li>
<li><span className="font-medium text-gray-700">E (4)</span> (Status)</li>
<li><span className="font-medium text-gray-700">H (7)</span> (Product Code)</li>
<li><span className="font-medium text-gray-700">J (9)</span> (Transaction Date)</li>
<li><span className="font-medium text-gray-700">L (11)</span> (Amount)</li>
<li><span className="font-medium text-gray-700">T (19)</span> (Slot)</li>
</ul>
<div className="mt-2 pt-2 border-t text-xs text-gray-500">
4
</div>
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
disabled={processing}
className="button-outlined-primary"
>
</Button>
<Button type="submit" disabled={!data.file || processing} className="button-filled-primary">
{processing ? "匯入中..." : "開始匯入"}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}