Use admin-prefixed API endpoints throughout the panel
This commit is contained in:
parent
dfd8ec50c0
commit
3106c85e50
|
|
@ -14,6 +14,8 @@ Web admin console for **Rezina Academy**. Team members manage LMS content (Learn
|
|||
| **Remote** | `https://gitea.yaltopia.com/Yimaru/Yimaru-Admin.git` |
|
||||
| **Branches** | `main`, `production` (keep both in sync for releases) |
|
||||
|
||||
API calls now use `/api/v1/admin`. `VITE_API_BASE_URL` may point to `/api/v1` or the already scoped `/api/v1/admin` base; the shared API helper handles both. Staff login, refresh, CSV exports, and WebSockets all use the admin base. Customer APIs retain their existing `/api/v1` base without an added prefix.
|
||||
|
||||
Companion backend docs: see Backend `README.md` and `docs/*-admin-panel-integration.md`.
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ function mutationResult(res: { data: unknown; status?: number }) {
|
|||
export const adminApplySubscription = (userId: number, body: AdminApplySubscriptionBody) =>
|
||||
http
|
||||
.post<AdminSubscriptionMutationResponse>(
|
||||
`/admin/users/${userId}/subscriptions/extend`,
|
||||
`/users/${userId}/subscriptions/extend`,
|
||||
body,
|
||||
)
|
||||
.then(mutationResult)
|
||||
|
|
@ -72,5 +72,5 @@ export const adminGrantSubscription = adminApplySubscription
|
|||
/** POST /admin/subscriptions/:id/cancel — admin cancel (not learner self-cancel). */
|
||||
export const adminCancelSubscription = (subscriptionId: number) =>
|
||||
http
|
||||
.post<AdminSubscriptionMutationResponse>(`/admin/subscriptions/${subscriptionId}/cancel`)
|
||||
.post<AdminSubscriptionMutationResponse>(`/subscriptions/${subscriptionId}/cancel`)
|
||||
.then(mutationResult)
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ export const getAppVersions = (params: GetAppVersionsParams = {}) => {
|
|||
const limit = params.limit ?? DEFAULT_TABLE_PAGE_SIZE
|
||||
const offset = params.offset ?? 0
|
||||
return http
|
||||
.get<AppVersionsListResponse>("/admin/app-versions", { params: { limit, offset } })
|
||||
.get<AppVersionsListResponse>("/app-versions", { params: { limit, offset } })
|
||||
.then((res) => {
|
||||
const parsed = parseAppVersionsList(res.data)
|
||||
return {
|
||||
|
|
@ -103,16 +103,16 @@ function mutationResult(res: { data: unknown }) {
|
|||
|
||||
export const createAppVersion = (payload: CreateAppVersionPayload) =>
|
||||
http
|
||||
.post<AppVersionMutationResponse>("/admin/app-versions", payload)
|
||||
.post<AppVersionMutationResponse>("/app-versions", payload)
|
||||
.then(mutationResult)
|
||||
|
||||
export const updateAppVersion = (id: number, payload: UpdateAppVersionPayload) =>
|
||||
http
|
||||
.put<AppVersionMutationResponse>(`/admin/app-versions/${id}`, payload)
|
||||
.put<AppVersionMutationResponse>(`/app-versions/${id}`, payload)
|
||||
.then(mutationResult)
|
||||
|
||||
export const deleteAppVersion = (id: number) =>
|
||||
http.delete<{ message?: string }>(`/admin/app-versions/${id}`).then((res) => ({
|
||||
http.delete<{ message?: string }>(`/app-versions/${id}`).then((res) => ({
|
||||
...res,
|
||||
message: isRecord(res.data) ? String(res.data.message ?? "") : undefined,
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ export interface GetEmailTemplatesParams {
|
|||
|
||||
/** GET /admin/email-templates — list email templates (paginated). */
|
||||
export const getEmailTemplates = (params?: GetEmailTemplatesParams) =>
|
||||
http.get<GetEmailTemplatesResponse>("/admin/email-templates", { params })
|
||||
http.get<GetEmailTemplatesResponse>("/email-templates", { params })
|
||||
|
||||
/** GET /admin/email-templates/slug/:slug — single template by slug. */
|
||||
export const getEmailTemplateBySlug = (slug: string) =>
|
||||
http.get<GetEmailTemplateBySlugResponse>(
|
||||
`/admin/email-templates/slug/${encodeURIComponent(slug)}`,
|
||||
`/email-templates/slug/${encodeURIComponent(slug)}`,
|
||||
)
|
||||
|
||||
function normalizeEmailTemplate(row: unknown): EmailTemplate | null {
|
||||
|
|
@ -85,15 +85,15 @@ export function parseEmailTemplatesResponse(
|
|||
export const updateEmailTemplate = (
|
||||
id: number,
|
||||
data: UpdateEmailTemplateRequest,
|
||||
) => http.put<UpdateEmailTemplateResponse>(`/admin/email-templates/${id}`, data)
|
||||
) => http.put<UpdateEmailTemplateResponse>(`/email-templates/${id}`, data)
|
||||
|
||||
/** POST /admin/email-templates — create a custom template. */
|
||||
export const createEmailTemplate = (data: CreateEmailTemplateRequest) =>
|
||||
http.post<CreateEmailTemplateResponse>("/admin/email-templates", data)
|
||||
http.post<CreateEmailTemplateResponse>("/email-templates", data)
|
||||
|
||||
/** DELETE /admin/email-templates/:id — delete a custom template. */
|
||||
export const deleteEmailTemplate = (id: number) =>
|
||||
http.delete<DeleteEmailTemplateResponse>(`/admin/email-templates/${id}`)
|
||||
http.delete<DeleteEmailTemplateResponse>(`/email-templates/${id}`)
|
||||
|
||||
/** POST /admin/email-templates/slug/:slug/preview — render without sending. */
|
||||
export const previewEmailTemplate = (
|
||||
|
|
@ -101,7 +101,7 @@ export const previewEmailTemplate = (
|
|||
variables: Record<string, string>,
|
||||
) =>
|
||||
http.post<PreviewEmailTemplateResponse>(
|
||||
`/admin/email-templates/slug/${encodeURIComponent(slug)}/preview`,
|
||||
`/email-templates/slug/${encodeURIComponent(slug)}/preview`,
|
||||
{ variables },
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { ADMIN_API_BASE_URL } from "../lib/apiBase";
|
||||
import axios, { type AxiosInstance, type AxiosError, type InternalAxiosRequestConfig } from "axios";
|
||||
import { toast } from "sonner";
|
||||
import { teamRefresh } from "./teamRefresh.api";
|
||||
|
|
@ -11,7 +12,7 @@ import {
|
|||
import { markApiErrorNotified, readApiResponseMessage } from "../lib/apiErrors";
|
||||
|
||||
const http: AxiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||
baseURL: ADMIN_API_BASE_URL,
|
||||
headers: {},
|
||||
});
|
||||
|
||||
|
|
@ -85,7 +86,7 @@ const safeOrigin = (url?: string): string | null => {
|
|||
}
|
||||
};
|
||||
|
||||
const API_BASE_ORIGIN = safeOrigin(import.meta.env.VITE_API_BASE_URL);
|
||||
const API_BASE_ORIGIN = safeOrigin(ADMIN_API_BASE_URL);
|
||||
|
||||
const shouldAttachApiAuth = (url?: string): boolean => {
|
||||
if (!url) return true;
|
||||
|
|
|
|||
|
|
@ -190,14 +190,14 @@ export function parseLevelThresholds(body: unknown): InitialAssessmentLevelThres
|
|||
}
|
||||
|
||||
export async function getInitialAssessmentLevelThresholds(): Promise<InitialAssessmentLevelThreshold[]> {
|
||||
const res = await http.get("/admin/assessment/level-thresholds")
|
||||
const res = await http.get("/assessment/level-thresholds")
|
||||
return parseLevelThresholds(res.data)
|
||||
}
|
||||
|
||||
export async function updateInitialAssessmentLevelThresholds(
|
||||
thresholds: InitialAssessmentLevelThreshold[],
|
||||
): Promise<InitialAssessmentLevelThreshold[]> {
|
||||
const res = await http.put("/admin/assessment/level-thresholds", { thresholds })
|
||||
const res = await http.put("/assessment/level-thresholds", { thresholds })
|
||||
return parseLevelThresholds(res.data)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ export async function getAllPayments(
|
|||
}
|
||||
|
||||
export const getPayments = (params: GetPaymentsParams = {}) =>
|
||||
http.get<PaymentsListResponse>("/admin/payments", { params: buildQueryParams(params) }).then((res) => {
|
||||
http.get<PaymentsListResponse>("/payments", { params: buildQueryParams(params) }).then((res) => {
|
||||
const parsed = parsePaymentsList(res.data)
|
||||
return {
|
||||
...res,
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import type {
|
|||
} from "../types/progress.types"
|
||||
|
||||
export const getAdminLearnerCourseProgress = (userId: number, courseId: number) =>
|
||||
http.get<LearnerCourseProgressResponse>(`/admin/users/${userId}/progress/courses/${courseId}`)
|
||||
http.get<LearnerCourseProgressResponse>(`/users/${userId}/progress/courses/${courseId}`)
|
||||
|
||||
export const getAdminLearnerCourseProgressSummary = (userId: number, courseId: number) =>
|
||||
http.get<LearnerCourseProgressSummaryResponse>(
|
||||
`/admin/users/${userId}/progress/courses/${courseId}/summary`,
|
||||
`/users/${userId}/progress/courses/${courseId}/summary`,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ export const deleteRole = (roleId: number) =>
|
|||
|
||||
/** Deactivate all users and team members tied to this role (admin). */
|
||||
export const bulkDeactivateRole = (roleId: number) =>
|
||||
http.post<BulkRoleDeactivateResponse>(`/admin/roles/${roleId}/bulk-deactivate`, {})
|
||||
http.post<BulkRoleDeactivateResponse>(`/roles/${roleId}/bulk-deactivate`, {})
|
||||
|
||||
/** Reactivate users and team members tied to this role (admin). */
|
||||
export const bulkReactivateRole = (roleId: number) =>
|
||||
http.post<BulkRoleReactivateResponse>(`/admin/roles/${roleId}/bulk-reactivate`, {})
|
||||
http.post<BulkRoleReactivateResponse>(`/roles/${roleId}/bulk-reactivate`, {})
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ export interface ReferralSettings {
|
|||
interface ReferralSettingsResponse { data: ReferralSettings }
|
||||
|
||||
export async function getReferralSettings(): Promise<ReferralSettings> {
|
||||
const response = await http.get<ReferralSettingsResponse>("/admin/referrals/settings")
|
||||
const response = await http.get<ReferralSettingsResponse>("/referrals/settings")
|
||||
return response.data.data
|
||||
}
|
||||
export async function updateReferralSettings(commissionPercent: number): Promise<ReferralSettings> {
|
||||
const response = await http.put<ReferralSettingsResponse>("/admin/referrals/settings", {
|
||||
const response = await http.put<ReferralSettingsResponse>("/referrals/settings", {
|
||||
commission_percent: commissionPercent,
|
||||
})
|
||||
return response.data.data
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { ADMIN_API_BASE_URL } from "../lib/apiBase"
|
||||
import axios from "axios"
|
||||
import type {
|
||||
ApiErrorResponse,
|
||||
|
|
@ -28,7 +29,7 @@ export async function teamRefresh(refreshToken: string): Promise<TeamMemberSessi
|
|||
const payload: TeamMemberRefreshRequest = { refresh_token: refreshToken }
|
||||
try {
|
||||
const res = await axios.post<LoginResponse>(
|
||||
`${import.meta.env.VITE_API_BASE_URL}/team/refresh`,
|
||||
`${ADMIN_API_BASE_URL}/team/refresh`,
|
||||
payload,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -469,7 +469,7 @@ export const getUserById = (id: number) =>
|
|||
});
|
||||
|
||||
export const getUserRecentActivity = (userId: number) =>
|
||||
http.get<UserRecentActivityResponse>(`/admin/users/${userId}/recent-activity`).then((res) => {
|
||||
http.get<UserRecentActivityResponse>(`/users/${userId}/recent-activity`).then((res) => {
|
||||
const body = res.data;
|
||||
const activity = normalizeUserRecentActivity(body?.data);
|
||||
if (!activity) {
|
||||
|
|
@ -485,7 +485,7 @@ export const getUserRecentActivity = (userId: number) =>
|
|||
});
|
||||
|
||||
export const getUserLearningActivity = (userId: number) =>
|
||||
http.get<UserLearningActivityResponse>(`/admin/users/${userId}/learning-activity`).then((res) => {
|
||||
http.get<UserLearningActivityResponse>(`/users/${userId}/learning-activity`).then((res) => {
|
||||
const body = res.data;
|
||||
const activity = normalizeUserLearningActivity(body?.data);
|
||||
if (!activity) {
|
||||
|
|
@ -501,7 +501,7 @@ export const getUserLearningActivity = (userId: number) =>
|
|||
});
|
||||
|
||||
export const getUserSubscriptions = (userId: number) =>
|
||||
http.get<UserSubscriptionsResponse>(`/admin/users/${userId}/subscriptions`).then((res) => {
|
||||
http.get<UserSubscriptionsResponse>(`/users/${userId}/subscriptions`).then((res) => {
|
||||
const body = res.data;
|
||||
const subscriptions = normalizeUserSubscriptions(body?.data);
|
||||
if (!subscriptions) {
|
||||
|
|
@ -534,13 +534,13 @@ export const createUser = (payload: CreateUserRequest) =>
|
|||
http.post("/users", payload);
|
||||
|
||||
export const updateProfile = (data: UpdateProfileRequest) =>
|
||||
http.put<UserProfileResponse>("/user", data);
|
||||
http.put<GetTeamMeResponse>("/team/me", data);
|
||||
|
||||
export const getUserSummary = () =>
|
||||
http.get<UserSummaryResponse>("/users/summary");
|
||||
|
||||
export const getDeletionRequests = (params: GetDeletionRequestsParams) =>
|
||||
http.get<GetDeletionRequestsResponse>("/admin/users/deletion-requests", { params });
|
||||
http.get<GetDeletionRequestsResponse>("/users/deletion-requests", { params });
|
||||
|
||||
export const updateUserProfilePicture = (id: number, profilePictureUrl: string) =>
|
||||
http.post(`/user/${id}/profile-picture`, {
|
||||
|
|
|
|||
7
src/lib/apiBase.ts
Normal file
7
src/lib/apiBase.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/** Accept the deployment API root or an already scoped admin URL. */
|
||||
export function adminApiBase(base: string): string {
|
||||
const root = base.replace(/\/+$/, "")
|
||||
return root.endsWith("/admin") ? root : `${root}/admin`
|
||||
}
|
||||
|
||||
export const ADMIN_API_BASE_URL = adminApiBase(import.meta.env.VITE_API_BASE_URL ?? "/api/v1")
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
import { ADMIN_API_BASE_URL } from "./apiBase"
|
||||
import { getAccessToken } from "./teamAuthStorage"
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE_URL as string
|
||||
const API_BASE = ADMIN_API_BASE_URL
|
||||
|
||||
export const EXPORT_MAX_ROWS = 50_000
|
||||
|
||||
export type QueryParams = Record<string, string | number | boolean | null | undefined>
|
||||
|
||||
export const EXPORT_ROUTES = {
|
||||
payments: "/admin/payments/export",
|
||||
payments: "/payments/export",
|
||||
users: "/users/export",
|
||||
subscriptions: "/admin/subscriptions/export",
|
||||
subscriptions: "/subscriptions/export",
|
||||
activityLogs: "/activity-logs/export",
|
||||
teamMembers: "/team/members/export",
|
||||
} as const
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { ADMIN_API_BASE_URL } from "./apiBase"
|
||||
import { parseRealtimeNotification } from "../api/notifications.api"
|
||||
import type { Notification } from "../types/notification.types"
|
||||
import { getAccessToken, TEAM_SESSION_UPDATED_EVENT } from "./teamAuthStorage"
|
||||
|
|
@ -7,7 +8,7 @@ const RECONNECT_MS = 5000
|
|||
export const NOTIFICATION_REALTIME_EVENT = "rezina:notification-realtime"
|
||||
|
||||
function getWsUrl() {
|
||||
const base = import.meta.env.VITE_API_BASE_URL as string
|
||||
const base = ADMIN_API_BASE_URL
|
||||
const wsBase = base.replace(/^https/, "wss").replace(/^http/, "ws")
|
||||
const token = getAccessToken() ?? ""
|
||||
return `${wsBase}/ws/connect?token=${encodeURIComponent(token)}`
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user