admin page
This commit is contained in:
@@ -1,16 +1,40 @@
|
||||
import { useState } from 'react'
|
||||
import { useAdminAuth, useAdminLogout } from '@features/admin'
|
||||
import { useAdminAuth, useAdminLogout, useCreateOrganizationWallets } from '@features/admin'
|
||||
import type { Organization } from '@features/admin'
|
||||
import { Notification } from '@shared/ui'
|
||||
import { AdminLoginForm } from '@widgets/admin-login-form'
|
||||
import { LegalEntitiesTable } from '@widgets/legal-entities-table'
|
||||
import { AddLegalEntityModal } from '@widgets/add-legal-entity-modal'
|
||||
import styles from './AdminPage.module.css'
|
||||
|
||||
type NotificationState = { message: string; status: 'success' | 'error' | 'warning' }
|
||||
|
||||
export function AdminPage() {
|
||||
const { isAuthenticated, isLoading } = useAdminAuth()
|
||||
const logout = useAdminLogout()
|
||||
const createWallets = useCreateOrganizationWallets()
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
const [notification, setNotification] = useState<{ message: string; status: 'success' | 'error' } | null>(null)
|
||||
const [notification, setNotification] = useState<NotificationState | null>(null)
|
||||
|
||||
// After a legal entity is created we immediately provision its wallets.
|
||||
// The page stays mounted (unlike the modal), so these mutate callbacks fire reliably.
|
||||
function handleCreated(organization: Organization) {
|
||||
setNotification({ status: 'success', message: 'Юридическое лицо добавлено' })
|
||||
createWallets.mutate(organization.id, {
|
||||
onSuccess: (wallets) => {
|
||||
setNotification({
|
||||
status: 'success',
|
||||
message: `Кошельки созданы (${wallets.length})`,
|
||||
})
|
||||
},
|
||||
onError: () => {
|
||||
setNotification({
|
||||
status: 'warning',
|
||||
message: 'Юридическое лицо создано, но кошельки создать не удалось',
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoading) return null
|
||||
if (!isAuthenticated) return <AdminLoginForm />
|
||||
@@ -38,7 +62,7 @@ export function AdminPage() {
|
||||
<AddLegalEntityModal
|
||||
open={modalOpen}
|
||||
onClose={() => setModalOpen(false)}
|
||||
onCreated={() => setNotification({ status: 'success', message: 'Юридическое лицо добавлено' })}
|
||||
onCreated={handleCreated}
|
||||
/>
|
||||
|
||||
{notification && (
|
||||
|
||||
Reference in New Issue
Block a user