fix
This commit is contained in:
@@ -3,12 +3,13 @@ import type {
|
||||
AdminLoginResponse,
|
||||
AdminMeResponse,
|
||||
CreateOrganizationRequest,
|
||||
CreateWalletsResponse,
|
||||
WalletResponse,
|
||||
DocumentResponse,
|
||||
Organization,
|
||||
OrganizationListResponse,
|
||||
PurchaseRequestListResponse,
|
||||
UpdateOrganizationRequest,
|
||||
WalletResponse,
|
||||
} from '../model/types'
|
||||
|
||||
const ADMIN_API_URL = 'https://app.admin.elcsa.ru'
|
||||
@@ -113,10 +114,18 @@ export function getOrganization(id: string): Promise<Organization> {
|
||||
return doAdminRequest<Organization>(`/v1/organizations/${id}`, {}, true)
|
||||
}
|
||||
|
||||
export function createOrganizationWallets(id: string): Promise<WalletResponse[]> {
|
||||
return doAdminRequest<WalletResponse[]>(
|
||||
export function createOrganizationWallets(id: string): Promise<CreateWalletsResponse> {
|
||||
return doAdminRequest<CreateWalletsResponse>(
|
||||
`/v1/organizations/${id}/wallets/create`,
|
||||
{ method: 'POST' },
|
||||
{ method: 'POST', body: JSON.stringify({ id }) },
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
export function getOrganizationWallets(id: string): Promise<WalletResponse[]> {
|
||||
return doAdminRequest<WalletResponse[]>(
|
||||
`/v1/organizations/${id}/wallets`,
|
||||
{},
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,15 +2,17 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { createOrganizationWallets } from '../api/adminApi'
|
||||
import { ORGANIZATIONS_QUERY_KEY } from './useOrganizations'
|
||||
import { ORGANIZATION_QUERY_KEY } from './useOrganization'
|
||||
import { WALLETS_QUERY_KEY } from './useOrganizationWallets'
|
||||
|
||||
export function useCreateOrganizationWallets() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (organizationId: string) => createOrganizationWallets(organizationId),
|
||||
onSuccess: (_wallets, organizationId) => {
|
||||
onSuccess: (_result, organizationId) => {
|
||||
// `has_wallets` flips to true server-side — refresh list and detail view.
|
||||
queryClient.invalidateQueries({ queryKey: ORGANIZATIONS_QUERY_KEY })
|
||||
queryClient.invalidateQueries({ queryKey: ORGANIZATION_QUERY_KEY(organizationId) })
|
||||
queryClient.invalidateQueries({ queryKey: WALLETS_QUERY_KEY(organizationId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
12
src/features/admin/hooks/useOrganizationWallets.ts
Normal file
12
src/features/admin/hooks/useOrganizationWallets.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getOrganizationWallets } from '../api/adminApi'
|
||||
|
||||
export const WALLETS_QUERY_KEY = (orgId: string) => ['admin-wallets', orgId]
|
||||
|
||||
export function useOrganizationWallets(orgId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: WALLETS_QUERY_KEY(orgId ?? ''),
|
||||
queryFn: () => getOrganizationWallets(orgId as string),
|
||||
enabled: !!orgId,
|
||||
})
|
||||
}
|
||||
@@ -6,6 +6,7 @@ export {
|
||||
getOrganization,
|
||||
createOrganization,
|
||||
createOrganizationWallets,
|
||||
getOrganizationWallets,
|
||||
updateOrganization,
|
||||
getDocuments,
|
||||
uploadDocument,
|
||||
@@ -35,6 +36,7 @@ export { useOrganization, ORGANIZATION_QUERY_KEY } from './hooks/useOrganization
|
||||
export { useCreateOrganization } from './hooks/useCreateOrganization'
|
||||
export { useCreateOrganizationWallets } from './hooks/useCreateOrganizationWallets'
|
||||
export { useUpdateOrganization } from './hooks/useUpdateOrganization'
|
||||
export { useOrganizationWallets, WALLETS_QUERY_KEY } from './hooks/useOrganizationWallets'
|
||||
export { useDocuments, DOCUMENTS_QUERY_KEY } from './hooks/useDocuments'
|
||||
export { useUploadDocument } from './hooks/useUploadDocument'
|
||||
export { usePurchaseRequests, PURCHASE_REQUESTS_QUERY_KEY } from './hooks/usePurchaseRequests'
|
||||
|
||||
@@ -58,6 +58,15 @@ export interface WalletResponse {
|
||||
created_at: string | null
|
||||
}
|
||||
|
||||
export interface CreateWalletsRequest {
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface CreateWalletsResponse {
|
||||
wallets: WalletResponse[]
|
||||
mnemonic: string
|
||||
}
|
||||
|
||||
export interface DocumentResponse {
|
||||
id: string
|
||||
organization_id: string
|
||||
|
||||
Reference in New Issue
Block a user