fix(documents): Упрощение формы загрузки - удалены document_type и tags
- Убраны поля document_type и tags из DocumentUploadForm - Обновлен API клиент: createDocument и updateDocument без этих полей - Обновлены TypeScript типы в api.ts - Убраны document_type и tags из отображения в documents/page.tsx - Форма теперь принимает только: title, description, file
This commit is contained in:
parent
0b88d05094
commit
1a86e61341
@ -67,11 +67,10 @@ export default function DocumentsPage() {
|
||||
return sorted.filter((doc) => {
|
||||
const title = doc.title.toLowerCase();
|
||||
const description = (doc.description || "").toLowerCase();
|
||||
const type = (doc.document_type || "").toLowerCase();
|
||||
const author = doc.created_by
|
||||
? `${doc.created_by.last_name} ${doc.created_by.first_name}`.toLowerCase()
|
||||
: "";
|
||||
return title.includes(q) || description.includes(q) || type.includes(q) || author.includes(q);
|
||||
return title.includes(q) || description.includes(q) || author.includes(q);
|
||||
});
|
||||
}, [documents, search]);
|
||||
|
||||
@ -155,7 +154,6 @@ export default function DocumentsPage() {
|
||||
statusCode={doc.status_code}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">Тип: {doc.document_type || "—"}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex shrink-0 gap-2">
|
||||
@ -187,20 +185,7 @@ export default function DocumentsPage() {
|
||||
</p>
|
||||
|
||||
{doc.tags && doc.tags.length > 0 && (
|
||||
<div className="mt-3 flex flex-wrap gap-1.5">
|
||||
{doc.tags.map((tag) => (
|
||||
<span
|
||||
key={`${doc.id}-${tag}`}
|
||||
className="rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-600"
|
||||
>
|
||||
#{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Workflow Buttons */}
|
||||
<div className="mt-3">
|
||||
div className="mt-3">
|
||||
<DocumentWorkflowButtons
|
||||
documentId={doc.id}
|
||||
currentStatus={doc.status_code}
|
||||
@ -288,11 +273,6 @@ export default function DocumentsPage() {
|
||||
url: selectedDocument.file_url!,
|
||||
name: selectedDocument.file_name || selectedDocument.title,
|
||||
})
|
||||
}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-sky-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-sky-700"
|
||||
>
|
||||
<Eye size={16} />
|
||||
Открыть файл
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@ -14,9 +14,7 @@ interface DocumentUploadFormProps {
|
||||
export function DocumentUploadForm({ onSuccess, onCancel }: DocumentUploadFormProps) {
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [documentType, setDocumentType] = useState("");
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [tags, setTags] = useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@ -48,7 +46,7 @@ export function DocumentUploadForm({ onSuccess, onCancel }: DocumentUploadFormPr
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
|
||||
if (!title || !documentType || !file) {
|
||||
if (!title || !file) {
|
||||
setError("Заполните все обязательные поля");
|
||||
return;
|
||||
}
|
||||
@ -56,17 +54,10 @@ export function DocumentUploadForm({ onSuccess, onCancel }: DocumentUploadFormPr
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
const tagsList = tags
|
||||
.split(',')
|
||||
.map(t => t.trim())
|
||||
.filter(t => t.length > 0);
|
||||
|
||||
await apiClient.createDocument({
|
||||
title,
|
||||
description,
|
||||
document_type: documentType,
|
||||
file,
|
||||
tags: tagsList.length > 0 ? tagsList : undefined,
|
||||
});
|
||||
|
||||
toast.success("Документ успешно загружен");
|
||||
@ -74,9 +65,7 @@ export function DocumentUploadForm({ onSuccess, onCancel }: DocumentUploadFormPr
|
||||
// Сброс формы
|
||||
setTitle("");
|
||||
setDescription("");
|
||||
setDocumentType("");
|
||||
setFile(null);
|
||||
setTags("");
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
@ -159,29 +148,6 @@ export function DocumentUploadForm({ onSuccess, onCancel }: DocumentUploadFormPr
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Document Type */}
|
||||
<div>
|
||||
<label htmlFor="type" className="mb-1.5 block text-sm font-medium text-gray-700">
|
||||
Тип документа <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<select
|
||||
id="type"
|
||||
value={documentType}
|
||||
onChange={(e) => setDocumentType(e.target.value)}
|
||||
required
|
||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-sky-500 focus:outline-none focus:ring-2 focus:ring-sky-100"
|
||||
>
|
||||
<option value="">Выберите тип</option>
|
||||
<option value="policy">Политика</option>
|
||||
<option value="procedure">Процедура</option>
|
||||
<option value="instruction">Инструкция</option>
|
||||
<option value="form">Форма</option>
|
||||
<option value="report">Отчет</option>
|
||||
<option value="contract">Договор</option>
|
||||
<option value="other">Другое</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label htmlFor="description" className="mb-1.5 block text-sm font-medium text-gray-700">
|
||||
@ -197,27 +163,11 @@ export function DocumentUploadForm({ onSuccess, onCancel }: DocumentUploadFormPr
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Tags */}
|
||||
<div>
|
||||
<label htmlFor="tags" className="mb-1.5 block text-sm font-medium text-gray-700">
|
||||
Теги
|
||||
</label>
|
||||
<input
|
||||
id="tags"
|
||||
type="text"
|
||||
value={tags}
|
||||
onChange={(e) => setTags(e.target.value)}
|
||||
placeholder="Введите теги через запятую"
|
||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-sky-500 focus:outline-none focus:ring-2 focus:ring-sky-100"
|
||||
/>
|
||||
<p className="mt-1 text-xs text-gray-500">Например: hr, политика, обязательно</p>
|
||||
</div>
|
||||
|
||||
{/* Buttons */}
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting || !title || !documentType || !file}
|
||||
disabled={isSubmitting || !title || !file}
|
||||
className="flex-1 rounded-lg bg-sky-600 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-sky-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? "Загрузка..." : "Загрузить документ"}
|
||||
|
||||
@ -302,18 +302,12 @@ class ApiClient {
|
||||
async createDocument(data: {
|
||||
title: string;
|
||||
description?: string;
|
||||
document_type: string;
|
||||
file: File;
|
||||
tags?: string[];
|
||||
}): Promise<any> {
|
||||
const formData = new FormData();
|
||||
formData.append('title', data.title);
|
||||
if (data.description) formData.append('description', data.description);
|
||||
formData.append('document_type', data.document_type);
|
||||
formData.append('file', data.file);
|
||||
if (data.tags && data.tags.length > 0) {
|
||||
formData.append('tags', JSON.stringify(data.tags));
|
||||
}
|
||||
|
||||
return this.request('/api/v1/documents/', {
|
||||
method: 'POST',
|
||||
@ -325,16 +319,12 @@ class ApiClient {
|
||||
async updateDocument(id: number, data: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
document_type?: string;
|
||||
file?: File;
|
||||
tags?: string[];
|
||||
}): Promise<any> {
|
||||
const formData = new FormData();
|
||||
if (data.title) formData.append('title', data.title);
|
||||
if (data.description) formData.append('description', data.description);
|
||||
if (data.document_type) formData.append('document_type', data.document_type);
|
||||
if (data.file) formData.append('file', data.file);
|
||||
if (data.tags) formData.append('tags', JSON.stringify(data.tags));
|
||||
|
||||
return this.request(`/api/v1/documents/${id}/`, {
|
||||
method: 'PATCH',
|
||||
|
||||
@ -121,13 +121,11 @@ export interface Document {
|
||||
file_url?: string;
|
||||
file_name?: string;
|
||||
file_size?: number;
|
||||
document_type: string;
|
||||
status: string; // human-readable: "Черновик", "На рассмотрении", etc.
|
||||
status_code: DocumentStatus; // machine-readable: "draft", "in_review", etc.
|
||||
created_by: User;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
tags?: string[];
|
||||
acknowledgements?: DocumentAcknowledgement[];
|
||||
acknowledgement_required?: boolean;
|
||||
is_acknowledged?: boolean;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user