admin page
This commit is contained in:
@@ -5,6 +5,7 @@ import type {
|
||||
CreateOrganizationRequest,
|
||||
Organization,
|
||||
OrganizationListResponse,
|
||||
UpdateOrganizationRequest,
|
||||
} from '../model/types'
|
||||
|
||||
const ADMIN_API_URL = 'https://app.admin.elcsa.ru'
|
||||
@@ -101,3 +102,18 @@ export function createOrganization(payload: CreateOrganizationRequest): Promise<
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
export function getOrganization(id: string): Promise<Organization> {
|
||||
return doAdminRequest<Organization>(`/v1/organizations/${id}`, {}, true)
|
||||
}
|
||||
|
||||
export function updateOrganization(
|
||||
id: string,
|
||||
payload: UpdateOrganizationRequest,
|
||||
): Promise<Organization> {
|
||||
return doAdminRequest<Organization>(
|
||||
`/v1/organizations/${id}`,
|
||||
{ method: 'PATCH', body: JSON.stringify(payload) },
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
12
src/features/admin/hooks/useOrganization.ts
Normal file
12
src/features/admin/hooks/useOrganization.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getOrganization } from '../api/adminApi'
|
||||
|
||||
export const ORGANIZATION_QUERY_KEY = (id: string) => ['admin-organization', id]
|
||||
|
||||
export function useOrganization(id: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ORGANIZATION_QUERY_KEY(id ?? ''),
|
||||
queryFn: () => getOrganization(id as string),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
16
src/features/admin/hooks/useUpdateOrganization.ts
Normal file
16
src/features/admin/hooks/useUpdateOrganization.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { updateOrganization } from '../api/adminApi'
|
||||
import type { UpdateOrganizationRequest } from '../model/types'
|
||||
import { ORGANIZATIONS_QUERY_KEY } from './useOrganizations'
|
||||
import { ORGANIZATION_QUERY_KEY } from './useOrganization'
|
||||
|
||||
export function useUpdateOrganization(id: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (payload: UpdateOrganizationRequest) => updateOrganization(id, payload),
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(ORGANIZATION_QUERY_KEY(id), data)
|
||||
queryClient.invalidateQueries({ queryKey: ORGANIZATIONS_QUERY_KEY })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -3,7 +3,9 @@ export {
|
||||
adminLogout,
|
||||
getAdminMe,
|
||||
getOrganizations,
|
||||
getOrganization,
|
||||
createOrganization,
|
||||
updateOrganization,
|
||||
refreshAdminToken,
|
||||
adminTokenStore,
|
||||
} from './api/adminApi'
|
||||
@@ -14,10 +16,13 @@ export type {
|
||||
Organization,
|
||||
OrganizationListResponse,
|
||||
CreateOrganizationRequest,
|
||||
UpdateOrganizationRequest,
|
||||
BankDetails,
|
||||
} from './model/types'
|
||||
export { useAdminAuth, ADMIN_AUTH_QUERY_KEY } from './hooks/useAdminAuth'
|
||||
export { useAdminLogin } from './hooks/useAdminLogin'
|
||||
export { useAdminLogout } from './hooks/useAdminLogout'
|
||||
export { useOrganizations, ORGANIZATIONS_QUERY_KEY } from './hooks/useOrganizations'
|
||||
export { useOrganization, ORGANIZATION_QUERY_KEY } from './hooks/useOrganization'
|
||||
export { useCreateOrganization } from './hooks/useCreateOrganization'
|
||||
export { useUpdateOrganization } from './hooks/useUpdateOrganization'
|
||||
|
||||
@@ -50,6 +50,19 @@ export interface OrganizationListResponse {
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface UpdateOrganizationRequest {
|
||||
name?: string | null
|
||||
short_name?: string | null
|
||||
ogrn?: string | null
|
||||
kpp?: string | null
|
||||
legal_address?: string | null
|
||||
actual_address?: string | null
|
||||
bank_details?: BankDetails | null
|
||||
contact_person?: string | null
|
||||
contact_phone?: string | null
|
||||
status?: string | null
|
||||
}
|
||||
|
||||
export interface CreateOrganizationRequest {
|
||||
email: string
|
||||
password: string
|
||||
|
||||
Reference in New Issue
Block a user