chore: file formatting
This commit is contained in:
@@ -1,26 +1,15 @@
|
||||
import { useState, useRef } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { User, X, Loader2 } from "lucide-react";
|
||||
import axios from "axios";
|
||||
import { useState, useRef } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { User, X, Loader2 } from 'lucide-react';
|
||||
import axios from 'axios';
|
||||
|
||||
interface BytescaleUploaderProps {
|
||||
value: string;
|
||||
onChange: (url: string) => void;
|
||||
folderPath:
|
||||
| "/health-packages"
|
||||
| "/seo"
|
||||
| "/doctors"
|
||||
| "/departments"
|
||||
| "/news"
|
||||
| "/blog"
|
||||
| "/doctor-og";
|
||||
folderPath: '/health-packages' | '/seo' | '/doctors' | '/departments' | '/news' | '/blog' | '/doctor-og';
|
||||
}
|
||||
|
||||
export function BytescaleUploader({
|
||||
value,
|
||||
onChange,
|
||||
folderPath,
|
||||
}: BytescaleUploaderProps) {
|
||||
export function BytescaleUploader({ value, onChange, folderPath }: BytescaleUploaderProps) {
|
||||
const baseURL = import.meta.env.VITE_API_URL;
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -30,33 +19,32 @@ export function BytescaleUploader({
|
||||
if (!file) return;
|
||||
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
alert("File is too large (Max 5MB)");
|
||||
alert('File is too large (Max 5MB)');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsUploading(true);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("folderPath", folderPath);
|
||||
formData.append('file', file);
|
||||
formData.append('folderPath', folderPath);
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${baseURL}/upload`, formData, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
|
||||
const { fileUrl } = response.data;
|
||||
onChange(fileUrl);
|
||||
} catch (e: any) {
|
||||
console.error("Upload Error:", e);
|
||||
const errorMessage =
|
||||
e.response?.data?.error || e.message || "Upload failed";
|
||||
console.error('Upload Error:', e);
|
||||
const errorMessage = e.response?.data?.error || e.message || 'Upload failed';
|
||||
alert(`Upload Error: ${errorMessage}`);
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +61,7 @@ export function BytescaleUploader({
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange("")}
|
||||
onClick={() => onChange('')}
|
||||
className="absolute -top-1 -right-1 bg-destructive text-white rounded-full p-0.5 shadow-sm hover:scale-110 transition-transform"
|
||||
>
|
||||
<X className="w-3 h-3" />
|
||||
@@ -111,17 +99,16 @@ export function BytescaleUploader({
|
||||
Uploading...
|
||||
</>
|
||||
) : value ? (
|
||||
"Change Photo"
|
||||
'Change Photo'
|
||||
) : (
|
||||
"Upload Photo"
|
||||
'Upload Photo'
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{value && (
|
||||
<p className="text-xs text-amber-600 pl-[72px]">
|
||||
⚠️ Make sure to save the changes by clicking the "Save Changes"
|
||||
button.
|
||||
⚠️ Make sure to save the changes by clicking the "Save Changes" button.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user