- Add pricing API functions to admin.ts - Create admin pricing page with form and validation - Add MANAGE_PRICING permission to auth context - Add pricing to admin navigation - Add translations for pricing page (en, ca, es) - Update PageLayout and Header types for new page
172 lines
4.7 KiB
TypeScript
172 lines
4.7 KiB
TypeScript
import { client } from "./client";
|
|
import { components } from "../generated/api";
|
|
|
|
type AdminUserResponse = components["schemas"]["AdminUserResponse"];
|
|
type PaginatedInvites = components["schemas"]["PaginatedResponse_InviteResponse_"];
|
|
type AdminExchangeResponse = components["schemas"]["AdminExchangeResponse"];
|
|
type AvailabilityResponse = components["schemas"]["AvailabilityResponse"];
|
|
type PriceHistoryRecord = components["schemas"]["PriceHistoryResponse"];
|
|
type PricingConfigResponse = components["schemas"]["PricingConfigResponse"];
|
|
type PricingConfigUpdate = components["schemas"]["PricingConfigUpdate"];
|
|
|
|
interface CreateInviteRequest {
|
|
godfather_id: number;
|
|
}
|
|
|
|
interface UpdateAvailabilityRequest {
|
|
date: string;
|
|
slots: Array<{ start_time: string; end_time: string }>;
|
|
}
|
|
|
|
interface CopyAvailabilityRequest {
|
|
source_date: string;
|
|
target_dates: string[];
|
|
}
|
|
|
|
interface GetPastTradesParams {
|
|
status?: string;
|
|
user_search?: string;
|
|
}
|
|
|
|
/**
|
|
* Admin API endpoints
|
|
*/
|
|
export const adminApi = {
|
|
/**
|
|
* Get all users (for dropdowns, etc.)
|
|
*/
|
|
getUsers(): Promise<AdminUserResponse[]> {
|
|
return client.get<AdminUserResponse[]>("/api/admin/users");
|
|
},
|
|
|
|
/**
|
|
* Get paginated invites
|
|
*/
|
|
getInvites(page: number, perPage: number = 10, status?: string): Promise<PaginatedInvites> {
|
|
const params = new URLSearchParams();
|
|
params.append("page", page.toString());
|
|
params.append("per_page", perPage.toString());
|
|
if (status) {
|
|
params.append("status", status);
|
|
}
|
|
return client.get<PaginatedInvites>(`/api/admin/invites?${params.toString()}`);
|
|
},
|
|
|
|
/**
|
|
* Create a new invite
|
|
*/
|
|
createInvite(request: CreateInviteRequest): Promise<void> {
|
|
return client.post<void>("/api/admin/invites", request);
|
|
},
|
|
|
|
/**
|
|
* Revoke an invite
|
|
*/
|
|
revokeInvite(inviteId: number): Promise<void> {
|
|
return client.post<void>(`/api/admin/invites/${inviteId}/revoke`);
|
|
},
|
|
|
|
/**
|
|
* Get upcoming trades
|
|
*/
|
|
getUpcomingTrades(): Promise<AdminExchangeResponse[]> {
|
|
return client.get<AdminExchangeResponse[]>("/api/admin/trades/upcoming");
|
|
},
|
|
|
|
/**
|
|
* Get past trades with optional filters
|
|
*/
|
|
getPastTrades(params?: GetPastTradesParams): Promise<AdminExchangeResponse[]> {
|
|
const searchParams = new URLSearchParams();
|
|
if (params?.status) {
|
|
searchParams.append("status", params.status);
|
|
}
|
|
if (params?.user_search) {
|
|
searchParams.append("user_search", params.user_search);
|
|
}
|
|
const queryString = searchParams.toString();
|
|
const url = queryString ? `/api/admin/trades/past?${queryString}` : "/api/admin/trades/past";
|
|
return client.get<AdminExchangeResponse[]>(url);
|
|
},
|
|
|
|
/**
|
|
* Complete a trade
|
|
*/
|
|
completeTrade(publicId: string): Promise<AdminExchangeResponse> {
|
|
return client.post<AdminExchangeResponse>(
|
|
`/api/admin/trades/${encodeURIComponent(publicId)}/complete`,
|
|
{}
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Mark a trade as no-show
|
|
*/
|
|
noShowTrade(publicId: string): Promise<AdminExchangeResponse> {
|
|
return client.post<AdminExchangeResponse>(
|
|
`/api/admin/trades/${encodeURIComponent(publicId)}/no-show`,
|
|
{}
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Cancel a trade (admin)
|
|
*/
|
|
cancelTrade(publicId: string): Promise<AdminExchangeResponse> {
|
|
return client.post<AdminExchangeResponse>(
|
|
`/api/admin/trades/${encodeURIComponent(publicId)}/cancel`,
|
|
{}
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Get availability for a date range
|
|
*/
|
|
getAvailability(fromDate: string, toDate: string): Promise<AvailabilityResponse> {
|
|
return client.get<AvailabilityResponse>(
|
|
`/api/admin/availability?from=${encodeURIComponent(fromDate)}&to=${encodeURIComponent(toDate)}`
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Update availability for a specific date
|
|
*/
|
|
updateAvailability(request: UpdateAvailabilityRequest): Promise<void> {
|
|
return client.put<void>("/api/admin/availability", request);
|
|
},
|
|
|
|
/**
|
|
* Copy availability from one date to multiple dates
|
|
*/
|
|
copyAvailability(request: CopyAvailabilityRequest): Promise<void> {
|
|
return client.post<void>("/api/admin/availability/copy", request);
|
|
},
|
|
|
|
/**
|
|
* Get price history records
|
|
*/
|
|
getPriceHistory(): Promise<PriceHistoryRecord[]> {
|
|
return client.get<PriceHistoryRecord[]>("/api/audit/price-history");
|
|
},
|
|
|
|
/**
|
|
* Trigger a price fetch
|
|
*/
|
|
fetchPrice(): Promise<PriceHistoryRecord> {
|
|
return client.post<PriceHistoryRecord>("/api/audit/price-history/fetch", {});
|
|
},
|
|
|
|
/**
|
|
* Get current pricing configuration
|
|
*/
|
|
getPricingConfig(): Promise<PricingConfigResponse> {
|
|
return client.get<PricingConfigResponse>("/api/admin/pricing");
|
|
},
|
|
|
|
/**
|
|
* Update pricing configuration
|
|
*/
|
|
updatePricingConfig(request: PricingConfigUpdate): Promise<PricingConfigResponse> {
|
|
return client.put<PricingConfigResponse>("/api/admin/pricing", request);
|
|
},
|
|
};
|