Files
star-erp/resources/js/Components/Vendor/VendorFormDialog.tsx
2025-12-30 15:03:19 +08:00

141 lines
5.0 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 { useEffect, useState } from "react";
import { Button } from "@/Components/ui/button";
import { Input } from "@/Components/ui/input";
import { Label } from "@/Components/ui/label";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
} from "@/Components/ui/dialog";
import type { Supplier, SupplierFormData } from "@/types/vendor";
interface VendorFormDialogProps {
open: boolean;
supplier: Supplier | null;
onClose: () => void;
onSave: (data: SupplierFormData) => void;
}
const initialFormData: SupplierFormData = {
name: "",
contact: "",
phone: "",
email: "",
};
export default function VendorFormDialog({
open,
supplier,
onClose,
onSave,
}: VendorFormDialogProps) {
const [formData, setFormData] = useState<SupplierFormData>(initialFormData);
const isEditing = !!supplier;
useEffect(() => {
if (supplier) {
setFormData({
name: supplier.name,
contact: supplier.contact || "",
phone: supplier.phone || "",
email: supplier.email || "",
});
} else {
setFormData(initialFormData);
}
}, [supplier, open]);
const handleSave = () => {
onSave(formData);
setFormData(initialFormData);
};
const handleCancel = () => {
onClose();
setFormData(initialFormData);
};
return (
<Dialog open={open} onOpenChange={onClose}>
<DialogContent className="max-w-2xl">
<DialogHeader>
<DialogTitle>{isEditing ? "編輯廠商" : "新增廠商"}</DialogTitle>
<DialogDescription>
{isEditing ? "編輯供應商的詳細資料。" : "新增供應商的詳細資料。"}
</DialogDescription>
</DialogHeader>
<div className="space-y-6">
<div>
<h3 className="mb-4"></h3>
<div className="space-y-4">
<div>
<Label className="text-muted-foreground text-xs"></Label>
<Input
placeholder="輸入廠商名稱"
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
className="mt-1"
/>
</div>
<div>
<Label className="text-muted-foreground text-xs"></Label>
<Input
placeholder="輸入聯絡人姓名"
value={formData.contact}
onChange={(e) => setFormData({ ...formData, contact: e.target.value })}
className="mt-1"
/>
</div>
<div>
<Label className="text-muted-foreground text-xs"></Label>
<Input
placeholder="例02-1234-5678"
value={formData.phone}
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
className="mt-1"
/>
</div>
<div>
<Label className="text-muted-foreground text-xs">Email</Label>
<Input
type="email"
placeholder="例vendor@example.com"
value={formData.email}
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
className="mt-1"
/>
</div>
</div>
</div>
</div>
<DialogFooter>
<Button
variant="outline"
size="sm"
onClick={handleCancel}
className="gap-2 button-outlined-primary"
>
</Button>
<Button
size="sm"
onClick={handleSave}
className="gap-2 button-filled-primary"
>
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}