This commit is contained in:
2026-06-09 20:38:58 +03:00
parent 80c7c5e8f8
commit 6ab0f8c137
13 changed files with 8037 additions and 369 deletions

View File

@@ -6,6 +6,7 @@ import type {
CreateWalletsResponse,
WalletResponse,
DocumentResponse,
DocumentTypeSlug,
Organization,
OrganizationListResponse,
PurchaseRequestListResponse,
@@ -138,18 +139,19 @@ export function getDocuments(orgId: string): Promise<DocumentResponse[]> {
)
}
// Upload/replace a single typed document. The type is part of the path and
// the body carries only the file — PUT acts as an upsert for that slot.
export function uploadDocument(
orgId: string,
documentType: string,
type: DocumentTypeSlug,
file: File,
): Promise<DocumentResponse> {
const body = new FormData()
body.append('document_type', documentType)
body.append('file', file)
return doAdminRequest<DocumentResponse>(
`/v1/organizations/${orgId}/documents`,
{ method: 'POST', body },
`/v1/organizations/${orgId}/documents/${type}`,
{ method: 'PUT', body },
true,
)
}

View File

@@ -1,17 +1,18 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { uploadDocument } from '../api/adminApi'
import type { DocumentTypeSlug } from '../model/types'
import { DOCUMENTS_QUERY_KEY } from './useDocuments'
interface UploadArgs {
documentType: string
type: DocumentTypeSlug
file: File
}
export function useUploadDocument(orgId: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: ({ documentType, file }: UploadArgs) =>
uploadDocument(orgId, documentType, file),
mutationFn: ({ type, file }: UploadArgs) =>
uploadDocument(orgId, type, file),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: DOCUMENTS_QUERY_KEY(orgId) })
},

View File

@@ -24,6 +24,7 @@ export type {
UpdateOrganizationRequest,
WalletResponse,
DocumentResponse,
DocumentTypeSlug,
PurchaseRequestResponse,
PurchaseRequestListResponse,
BankDetails,

View File

@@ -67,15 +67,25 @@ export interface CreateWalletsResponse {
mnemonic: string
}
// Fixed document type slugs — match the path segments of the per-type
// PUT/GET endpoints (`/documents/{slug}`). The API no longer accepts a
// free-text document type.
export type DocumentTypeSlug =
| 'charter'
| 'inn-certificate'
| 'ogrn-certificate'
| 'bank-details'
| 'kyc-representative'
| 'power-of-attorney'
| 'other'
export interface DocumentResponse {
id: string
organization_id: string
document_type: string
file_name: string
content_type: string
file_size_bytes: number
uploaded_by: string | null
created_at: string | null
s3_key: string | null
file_name: string | null
content_type: string | null
file_size_bytes: number | null
download_url: string | null
}