Add accounts UI with list, create, edit, detail tabs for all sub-entities
Accounts list with paginated table, search, sort. Account detail page with tabs for members, payment methods, tax exemptions, and processor links. All sub-entities have create/edit dialogs and delete actions. Forms use shared Zod schemas via react-hook-form.
This commit is contained in:
37
packages/admin/src/api/accounts.ts
Normal file
37
packages/admin/src/api/accounts.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { api } from '@/lib/api-client'
|
||||
import type { Account } from '@/types/account'
|
||||
import type { PaginatedResponse, PaginationInput } from '@forte/shared/schemas'
|
||||
|
||||
export const accountKeys = {
|
||||
all: ['accounts'] as const,
|
||||
lists: () => [...accountKeys.all, 'list'] as const,
|
||||
list: (params: PaginationInput) => [...accountKeys.all, 'list', params] as const,
|
||||
details: () => [...accountKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...accountKeys.all, 'detail', id] as const,
|
||||
}
|
||||
|
||||
export function accountListOptions(params: PaginationInput) {
|
||||
return queryOptions({
|
||||
queryKey: accountKeys.list(params),
|
||||
queryFn: () => api.get<PaginatedResponse<Account>>('/v1/accounts', params),
|
||||
})
|
||||
}
|
||||
|
||||
export function accountDetailOptions(id: string) {
|
||||
return queryOptions({
|
||||
queryKey: accountKeys.detail(id),
|
||||
queryFn: () => api.get<Account>(`/v1/accounts/${id}`),
|
||||
})
|
||||
}
|
||||
|
||||
export const accountMutations = {
|
||||
create: (data: Record<string, unknown>) =>
|
||||
api.post<Account>('/v1/accounts', data),
|
||||
|
||||
update: (id: string, data: Record<string, unknown>) =>
|
||||
api.patch<Account>(`/v1/accounts/${id}`, data),
|
||||
|
||||
delete: (id: string) =>
|
||||
api.del<Account>(`/v1/accounts/${id}`),
|
||||
}
|
||||
27
packages/admin/src/api/members.ts
Normal file
27
packages/admin/src/api/members.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { api } from '@/lib/api-client'
|
||||
import type { Member } from '@/types/account'
|
||||
import type { PaginatedResponse, PaginationInput } from '@forte/shared/schemas'
|
||||
|
||||
export const memberKeys = {
|
||||
all: (accountId: string) => ['accounts', accountId, 'members'] as const,
|
||||
list: (accountId: string, params: PaginationInput) => [...memberKeys.all(accountId), params] as const,
|
||||
}
|
||||
|
||||
export function memberListOptions(accountId: string, params: PaginationInput) {
|
||||
return queryOptions({
|
||||
queryKey: memberKeys.list(accountId, params),
|
||||
queryFn: () => api.get<PaginatedResponse<Member>>(`/v1/accounts/${accountId}/members`, params),
|
||||
})
|
||||
}
|
||||
|
||||
export const memberMutations = {
|
||||
create: (accountId: string, data: Record<string, unknown>) =>
|
||||
api.post<Member>(`/v1/accounts/${accountId}/members`, data),
|
||||
|
||||
update: (id: string, data: Record<string, unknown>) =>
|
||||
api.patch<Member>(`/v1/members/${id}`, data),
|
||||
|
||||
delete: (id: string) =>
|
||||
api.del<Member>(`/v1/members/${id}`),
|
||||
}
|
||||
25
packages/admin/src/api/payment-methods.ts
Normal file
25
packages/admin/src/api/payment-methods.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { api } from '@/lib/api-client'
|
||||
import type { PaymentMethod } from '@/types/account'
|
||||
|
||||
export const paymentMethodKeys = {
|
||||
all: (accountId: string) => ['accounts', accountId, 'payment-methods'] as const,
|
||||
}
|
||||
|
||||
export function paymentMethodListOptions(accountId: string) {
|
||||
return queryOptions({
|
||||
queryKey: paymentMethodKeys.all(accountId),
|
||||
queryFn: () => api.get<{ data: PaymentMethod[] }>(`/v1/accounts/${accountId}/payment-methods`),
|
||||
})
|
||||
}
|
||||
|
||||
export const paymentMethodMutations = {
|
||||
create: (accountId: string, data: Record<string, unknown>) =>
|
||||
api.post<PaymentMethod>(`/v1/accounts/${accountId}/payment-methods`, data),
|
||||
|
||||
update: (id: string, data: Record<string, unknown>) =>
|
||||
api.patch<PaymentMethod>(`/v1/payment-methods/${id}`, data),
|
||||
|
||||
delete: (id: string) =>
|
||||
api.del<PaymentMethod>(`/v1/payment-methods/${id}`),
|
||||
}
|
||||
25
packages/admin/src/api/processor-links.ts
Normal file
25
packages/admin/src/api/processor-links.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { api } from '@/lib/api-client'
|
||||
import type { ProcessorLink } from '@/types/account'
|
||||
|
||||
export const processorLinkKeys = {
|
||||
all: (accountId: string) => ['accounts', accountId, 'processor-links'] as const,
|
||||
}
|
||||
|
||||
export function processorLinkListOptions(accountId: string) {
|
||||
return queryOptions({
|
||||
queryKey: processorLinkKeys.all(accountId),
|
||||
queryFn: () => api.get<{ data: ProcessorLink[] }>(`/v1/accounts/${accountId}/processor-links`),
|
||||
})
|
||||
}
|
||||
|
||||
export const processorLinkMutations = {
|
||||
create: (accountId: string, data: Record<string, unknown>) =>
|
||||
api.post<ProcessorLink>(`/v1/accounts/${accountId}/processor-links`, data),
|
||||
|
||||
update: (id: string, data: Record<string, unknown>) =>
|
||||
api.patch<ProcessorLink>(`/v1/processor-links/${id}`, data),
|
||||
|
||||
delete: (id: string) =>
|
||||
api.del<ProcessorLink>(`/v1/processor-links/${id}`),
|
||||
}
|
||||
28
packages/admin/src/api/tax-exemptions.ts
Normal file
28
packages/admin/src/api/tax-exemptions.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { api } from '@/lib/api-client'
|
||||
import type { TaxExemption } from '@/types/account'
|
||||
|
||||
export const taxExemptionKeys = {
|
||||
all: (accountId: string) => ['accounts', accountId, 'tax-exemptions'] as const,
|
||||
}
|
||||
|
||||
export function taxExemptionListOptions(accountId: string) {
|
||||
return queryOptions({
|
||||
queryKey: taxExemptionKeys.all(accountId),
|
||||
queryFn: () => api.get<{ data: TaxExemption[] }>(`/v1/accounts/${accountId}/tax-exemptions`),
|
||||
})
|
||||
}
|
||||
|
||||
export const taxExemptionMutations = {
|
||||
create: (accountId: string, data: Record<string, unknown>) =>
|
||||
api.post<TaxExemption>(`/v1/accounts/${accountId}/tax-exemptions`, data),
|
||||
|
||||
update: (id: string, data: Record<string, unknown>) =>
|
||||
api.patch<TaxExemption>(`/v1/tax-exemptions/${id}`, data),
|
||||
|
||||
approve: (id: string) =>
|
||||
api.post<TaxExemption>(`/v1/tax-exemptions/${id}/approve`, {}),
|
||||
|
||||
revoke: (id: string, reason: string) =>
|
||||
api.post<TaxExemption>(`/v1/tax-exemptions/${id}/revoke`, { reason }),
|
||||
}
|
||||
Reference in New Issue
Block a user