Files
dpage-editor/src/pages/editor/components/sidebar/instructions/DocumentUpload.tsx
T
2025-11-26 14:16:52 +03:30

54 lines
2.1 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 { DocumentUpload } from "iconsax-react";
import { useEditorStore, type ToolType } from "@/pages/editor/store/editorStore";
import Button from "@/components/Button";
const DocumentUploadComponent = () => {
return (
<div className="space-y-4">
<div>
<label className="block text-sm mb-2">آپلود سند</label>
<input
type="file"
accept=".pdf,.doc,.docx"
onChange={(e) => {
const file = e.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onload = (event) => {
const fileUrl = event.target?.result as string;
const newDocument = {
id: `document-${Date.now()}`,
type: "document" as ToolType,
x: 100,
y: 100,
width: 200,
height: 250,
imageUrl: fileUrl,
};
const { addObject, setSelectedObjectId, setTool } = useEditorStore.getState();
addObject(newDocument);
setSelectedObjectId(newDocument.id);
setTool("select");
};
reader.readAsDataURL(file);
}
}}
className="hidden"
id="document-upload"
/>
<Button
variant="outline"
onClick={() => document.getElementById("document-upload")?.click()}
className="w-full"
>
<DocumentUpload size={20} />
انتخاب سند
</Button>
</div>
</div>
);
};
export default DocumentUploadComponent;