Fix attachment previews and comment permissions
This commit is contained in:
parent
1cccb852a5
commit
e491becbc4
4 changed files with 62 additions and 11 deletions
30
src/components/tickets/new-ticket-dialog.client.tsx
Normal file
30
src/components/tickets/new-ticket-dialog.client.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
import { NewTicketDialog } from "./new-ticket-dialog"
|
||||
|
||||
export function NewTicketDialogDeferred() {
|
||||
const [mounted, setMounted] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
|
||||
if (!mounted) {
|
||||
return (
|
||||
<Button
|
||||
size="sm"
|
||||
className="rounded-lg border border-black bg-black px-3 py-1.5 text-sm font-semibold text-white transition hover:bg-[#18181b]/85 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#18181b]/30"
|
||||
disabled
|
||||
aria-disabled
|
||||
>
|
||||
Novo ticket
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
return <NewTicketDialog />
|
||||
}
|
||||
|
|
@ -31,18 +31,19 @@ export function Dropzone({
|
|||
|
||||
const startUpload = useCallback(async (files: FileList | File[]) => {
|
||||
const list = Array.from(files).slice(0, maxFiles);
|
||||
const url = await generateUrl({});
|
||||
const uploaded: Uploaded[] = [];
|
||||
for (const file of list) {
|
||||
if (file.size > maxSize) continue;
|
||||
const url = await generateUrl({});
|
||||
const id = `${file.name}-${file.size}-${Date.now()}`;
|
||||
const localPreview = file.type.startsWith("image/") ? URL.createObjectURL(file) : undefined;
|
||||
setItems((prev) => [...prev, { id, name: file.name, progress: 0, status: "uploading" }]);
|
||||
await new Promise<void>((resolve) => {
|
||||
const form = new FormData();
|
||||
form.append("file", file);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", url);
|
||||
if (file.type) {
|
||||
xhr.setRequestHeader("Content-Type", file.type);
|
||||
}
|
||||
xhr.upload.onprogress = (e) => {
|
||||
if (!e.lengthComputable) return;
|
||||
const progress = Math.round((e.loaded / e.total) * 100);
|
||||
|
|
@ -66,7 +67,7 @@ export function Dropzone({
|
|||
setItems((prev) => prev.map((it) => (it.id === id ? { ...it, status: "error" } : it)));
|
||||
resolve();
|
||||
};
|
||||
xhr.send(form);
|
||||
xhr.send(file);
|
||||
});
|
||||
}
|
||||
if (uploaded.length) onUploaded?.(uploaded);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue