Improve admin UX for practices, personas, navigation, and team management.
Add edit-practice dirty-state save gating, back navigation helpers, realistic persona avatars with circular cropping, global API error toasts, team invite role fixes, user/team block-unblock on detail pages, and related content-management polish. Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
@ -1,4 +1,5 @@
|
||||||
import axios, { type AxiosInstance, type AxiosError, type InternalAxiosRequestConfig } from "axios";
|
import axios, { type AxiosInstance, type AxiosError, type InternalAxiosRequestConfig } from "axios";
|
||||||
|
import { toast } from "sonner";
|
||||||
import { teamRefresh } from "./teamRefresh.api";
|
import { teamRefresh } from "./teamRefresh.api";
|
||||||
import { TeamAuthError } from "../types/auth.types";
|
import { TeamAuthError } from "../types/auth.types";
|
||||||
import {
|
import {
|
||||||
|
|
@ -7,6 +8,7 @@ import {
|
||||||
getRefreshToken,
|
getRefreshToken,
|
||||||
saveTeamSession,
|
saveTeamSession,
|
||||||
} from "../lib/teamAuthStorage";
|
} from "../lib/teamAuthStorage";
|
||||||
|
import { markApiErrorNotified, readApiResponseMessage } from "../lib/apiErrors";
|
||||||
|
|
||||||
const http: AxiosInstance = axios.create({
|
const http: AxiosInstance = axios.create({
|
||||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||||
|
|
@ -90,19 +92,9 @@ const shouldAttachApiAuth = (url?: string): boolean => {
|
||||||
return requestOrigin === API_BASE_ORIGIN;
|
return requestOrigin === API_BASE_ORIGIN;
|
||||||
};
|
};
|
||||||
|
|
||||||
function readErrorMessage(data: unknown): string {
|
|
||||||
if (typeof data === "string") return data;
|
|
||||||
if (data && typeof data === "object") {
|
|
||||||
const record = data as Record<string, unknown>;
|
|
||||||
if (typeof record.error === "string") return record.error;
|
|
||||||
if (typeof record.message === "string") return record.message;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRefreshableAccessTokenError(error: AxiosError): boolean {
|
function isRefreshableAccessTokenError(error: AxiosError): boolean {
|
||||||
if (error.response?.status !== 401) return false;
|
if (error.response?.status !== 401) return false;
|
||||||
const message = readErrorMessage(error.response.data).toLowerCase();
|
const message = readApiResponseMessage(error.response.data).toLowerCase();
|
||||||
return (
|
return (
|
||||||
message.includes("access token expired") ||
|
message.includes("access token expired") ||
|
||||||
message.includes("invalid access token")
|
message.includes("invalid access token")
|
||||||
|
|
@ -202,6 +194,16 @@ http.interceptors.response.use(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const skipErrorToast =
|
||||||
|
originalRequest.skipErrorToast || isAuthEndpointRequest(originalRequest.url);
|
||||||
|
if (!skipErrorToast && error.response) {
|
||||||
|
const message = readApiResponseMessage(error.response.data);
|
||||||
|
if (message) {
|
||||||
|
toast.error(message);
|
||||||
|
markApiErrorNotified(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,30 @@ import type {
|
||||||
GetPermissionsResponse,
|
GetPermissionsResponse,
|
||||||
BulkRoleDeactivateResponse,
|
BulkRoleDeactivateResponse,
|
||||||
BulkRoleReactivateResponse,
|
BulkRoleReactivateResponse,
|
||||||
|
Role,
|
||||||
} from "../types/rbac.types"
|
} from "../types/rbac.types"
|
||||||
|
|
||||||
export const getRoles = (params?: GetRolesParams) =>
|
export const getRoles = (params?: GetRolesParams) =>
|
||||||
http.get<GetRolesResponse>("/rbac/roles", { params })
|
http.get<GetRolesResponse>("/rbac/roles", { params })
|
||||||
|
|
||||||
|
/** Fetch every RBAC role across paginated list responses. */
|
||||||
|
export async function fetchAllRoles(): Promise<Role[]> {
|
||||||
|
const pageSize = 50
|
||||||
|
const firstRes = await getRoles({ page: 1, page_size: pageSize })
|
||||||
|
const firstBatch = firstRes.data?.data?.roles ?? []
|
||||||
|
const total = firstRes.data?.data?.total ?? firstBatch.length
|
||||||
|
const totalPages = Math.max(1, Math.ceil(total / pageSize))
|
||||||
|
|
||||||
|
if (totalPages === 1) return firstBatch
|
||||||
|
|
||||||
|
const remaining = await Promise.all(
|
||||||
|
Array.from({ length: totalPages - 1 }, (_, idx) =>
|
||||||
|
getRoles({ page: idx + 2, page_size: pageSize }),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return [...firstBatch, ...remaining.flatMap((res) => res.data?.data?.roles ?? [])]
|
||||||
|
}
|
||||||
|
|
||||||
export const getRoleDetail = (roleId: number) =>
|
export const getRoleDetail = (roleId: number) =>
|
||||||
http.get<GetRoleDetailResponse>(`/rbac/roles/${roleId}`)
|
http.get<GetRoleDetailResponse>(`/rbac/roles/${roleId}`)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,9 @@ export const changeTeamMemberPassword = (id: number, data: ChangeTeamMemberPassw
|
||||||
|
|
||||||
/** POST /team/members/invite — send invitation email (permission: team.members.invite). */
|
/** POST /team/members/invite — send invitation email (permission: team.members.invite). */
|
||||||
export const inviteTeamMember = (data: InviteTeamMemberRequest) =>
|
export const inviteTeamMember = (data: InviteTeamMemberRequest) =>
|
||||||
http.post<InviteTeamMemberResponse>("/team/members/invite", data)
|
http.post<InviteTeamMemberResponse>("/team/members/invite", data, {
|
||||||
|
skipErrorToast: true,
|
||||||
|
})
|
||||||
|
|
||||||
/** GET /team/invitations/verify?token= — public (accept-invite page). */
|
/** GET /team/invitations/verify?token= — public (accept-invite page). */
|
||||||
export const verifyTeamInvitation = (token: string) =>
|
export const verifyTeamInvitation = (token: string) =>
|
||||||
|
|
|
||||||
BIN
src/assets/personas/amanuel.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
src/assets/personas/aseffa.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
src/assets/personas/bethel.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
src/assets/personas/dawit.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
src/assets/personas/hana.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
src/assets/personas/liya.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
src/assets/personas/mahlet.png
Normal file
|
After Width: | Height: | Size: 59 KiB |
BIN
src/assets/personas/nahom.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
|
@ -199,7 +200,7 @@ function DynamicImageSlot({
|
||||||
toast.success("Image uploaded")
|
toast.success("Image uploaded")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to upload image")
|
notifyApiError(e, "Failed to upload image")
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +221,7 @@ function DynamicImageSlot({
|
||||||
toast.success("Image URL imported to storage")
|
toast.success("Image URL imported to storage")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Could not import image from URL")
|
notifyApiError(e, "Could not import image from URL")
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -454,7 +455,7 @@ function DynamicAudioSlot({
|
||||||
toast.success("Audio uploaded")
|
toast.success("Audio uploaded")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to upload audio")
|
notifyApiError(e, "Failed to upload audio")
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -477,7 +478,7 @@ function DynamicAudioSlot({
|
||||||
toast.success("Audio URL imported to storage")
|
toast.success("Audio URL imported to storage")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Could not import audio from URL")
|
notifyApiError(e, "Could not import audio from URL")
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -783,7 +784,7 @@ function DynamicPdfSlot({
|
||||||
toast.success("PDF uploaded")
|
toast.success("PDF uploaded")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to upload PDF")
|
notifyApiError(e, "Failed to upload PDF")
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
|
@ -330,7 +331,7 @@ export function PracticeQuestionEditorFields({
|
||||||
toast.success("Audio uploaded successfully")
|
toast.success("Audio uploaded successfully")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload audio:", error)
|
console.error("Failed to upload audio:", error)
|
||||||
toast.error("Failed to upload audio file")
|
notifyApiError(error, "Failed to upload audio file")
|
||||||
} finally {
|
} finally {
|
||||||
if (field === "voice_prompt") setUploadingVoice(false)
|
if (field === "voice_prompt") setUploadingVoice(false)
|
||||||
else setUploadingSample(false)
|
else setUploadingSample(false)
|
||||||
|
|
@ -387,7 +388,7 @@ export function PracticeQuestionEditorFields({
|
||||||
else setSamplePreviewUrl(url)
|
else setSamplePreviewUrl(url)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to resolve audio:", error)
|
console.error("Failed to resolve audio:", error)
|
||||||
toast.error("Could not import/resolve audio URL")
|
notifyApiError(error, "Could not import/resolve audio URL")
|
||||||
} finally {
|
} finally {
|
||||||
if (field === "voice_prompt") setUploadingVoice(false)
|
if (field === "voice_prompt") setUploadingVoice(false)
|
||||||
else setUploadingSample(false)
|
else setUploadingSample(false)
|
||||||
|
|
@ -419,7 +420,7 @@ export function PracticeQuestionEditorFields({
|
||||||
toast.success("Image uploaded successfully")
|
toast.success("Image uploaded successfully")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload image:", error)
|
console.error("Failed to upload image:", error)
|
||||||
toast.error("Failed to upload image")
|
notifyApiError(error, "Failed to upload image")
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingImage(false)
|
setUploadingImage(false)
|
||||||
}
|
}
|
||||||
|
|
@ -435,7 +436,7 @@ export function PracticeQuestionEditorFields({
|
||||||
setImagePreviewUrl(resolved)
|
setImagePreviewUrl(resolved)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to resolve image preview URL:", error)
|
console.error("Failed to resolve image preview URL:", error)
|
||||||
toast.error("Could not resolve image preview URL")
|
notifyApiError(error, "Could not resolve image preview URL")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -704,7 +705,7 @@ export function PracticeQuestionEditorFields({
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load definition details")
|
notifyApiError(e, "Failed to load definition details")
|
||||||
} finally {
|
} finally {
|
||||||
setDefinitionDetailLoading(false)
|
setDefinitionDetailLoading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { Download } from "lucide-react"
|
import { Download } from "lucide-react"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
@ -43,7 +44,7 @@ export function ExportCsvButton({
|
||||||
const filename = await downloadCsvExport(exportPath, params, { resourceName })
|
const filename = await downloadCsvExport(exportPath, params, { resourceName })
|
||||||
toast.success(`Downloaded ${filename}`)
|
toast.success(`Downloaded ${filename}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(e instanceof Error ? e.message : "Export failed")
|
notifyApiError(e, "Export failed")
|
||||||
} finally {
|
} finally {
|
||||||
setExporting(false)
|
setExporting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
src/components/navigation/PageBackLink.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { ArrowLeft } from "lucide-react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { navigateBack } from "../../lib/navigateBack";
|
||||||
|
import { cn } from "../../lib/utils";
|
||||||
|
|
||||||
|
type PageBackLinkProps = {
|
||||||
|
fallbackTo: string;
|
||||||
|
label?: string;
|
||||||
|
className?: string;
|
||||||
|
iconClassName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function PageBackLink({
|
||||||
|
fallbackTo,
|
||||||
|
label = "Back",
|
||||||
|
className,
|
||||||
|
iconClassName,
|
||||||
|
}: PageBackLinkProps) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => navigateBack(navigate, fallbackTo)}
|
||||||
|
className={cn(
|
||||||
|
"group flex w-fit items-center gap-2 text-[15px] font-medium text-grayScale-600 transition-colors hover:text-brand-500",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ArrowLeft
|
||||||
|
className={cn(
|
||||||
|
"h-4 w-4 transition-transform group-hover:-translate-x-0.5",
|
||||||
|
iconClassName,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import { Eye, ExternalLink, RefreshCw } from "lucide-react"
|
import { Eye, ExternalLink, RefreshCw } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
parseEmailTemplatePreviewResponse,
|
parseEmailTemplatePreviewResponse,
|
||||||
previewEmailTemplate,
|
previewEmailTemplate,
|
||||||
|
|
@ -123,10 +124,7 @@ export function EmailComposeFields({
|
||||||
if (!result) throw new Error("Empty preview response")
|
if (!result) throw new Error("Empty preview response")
|
||||||
setPreview(result)
|
setPreview(result)
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const msg =
|
notifyApiError(err, "Failed to preview email template")
|
||||||
(err as { response?: { data?: { message?: string } } })?.response?.data?.message ??
|
|
||||||
"Failed to preview email template"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setPreviewLoading(false)
|
setPreviewLoading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Trash2 } from "lucide-react"
|
import { Trash2 } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { deleteNotification } from "../../api/notifications.api"
|
import { deleteNotification } from "../../api/notifications.api"
|
||||||
import { Button } from "../ui/button"
|
import { Button } from "../ui/button"
|
||||||
import {
|
import {
|
||||||
|
|
@ -43,12 +44,7 @@ export function NotificationDeleteDialog({
|
||||||
onDeleted?.(notification.id)
|
onDeleted?.(notification.id)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg =
|
notifyApiError(e, "Failed to delete notification")
|
||||||
(e as { response?: { data?: { message?: string; error?: string } } })?.response
|
|
||||||
?.data?.error ??
|
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data?.message ??
|
|
||||||
"Failed to delete notification"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
src/components/personas/PersonaAvatar.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { cn } from "../../lib/utils"
|
||||||
|
|
||||||
|
const SIZE_CLASSES = {
|
||||||
|
sm: "size-10",
|
||||||
|
md: "size-12",
|
||||||
|
lg: "size-16",
|
||||||
|
xl: "size-24",
|
||||||
|
} as const
|
||||||
|
|
||||||
|
type PersonaAvatarProps = {
|
||||||
|
src: string
|
||||||
|
alt?: string
|
||||||
|
size?: keyof typeof SIZE_CLASSES
|
||||||
|
selected?: boolean
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PersonaAvatar({
|
||||||
|
src,
|
||||||
|
alt = "",
|
||||||
|
size = "md",
|
||||||
|
selected = false,
|
||||||
|
className,
|
||||||
|
}: PersonaAvatarProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"inline-flex shrink-0 overflow-hidden rounded-full bg-grayScale-100",
|
||||||
|
"aspect-square",
|
||||||
|
SIZE_CLASSES[size],
|
||||||
|
selected && "ring-[3px] ring-brand-500 ring-offset-2 ring-offset-white",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={src}
|
||||||
|
alt={alt}
|
||||||
|
className="h-full w-full object-cover object-center"
|
||||||
|
draggable={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useCallback, useRef, useState, type ChangeEvent } from "react"
|
import { useCallback, useRef, useState, type ChangeEvent } from "react"
|
||||||
import { Camera } from "lucide-react"
|
import { Camera } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { uploadImageFile } from "../../api/files.api"
|
import { uploadImageFile } from "../../api/files.api"
|
||||||
import { updateTeamMe } from "../../api/team.api"
|
import { updateTeamMe } from "../../api/team.api"
|
||||||
import { SpinnerIcon } from "../ui/spinner-icon"
|
import { SpinnerIcon } from "../ui/spinner-icon"
|
||||||
|
|
@ -53,10 +54,7 @@ export function ProfileAvatarUpload({
|
||||||
toast.success(updateRes.data.message || "Profile picture updated")
|
toast.success(updateRes.data.message || "Profile picture updated")
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
const uploadMsg =
|
notifyApiError(err, "Failed to update profile picture")
|
||||||
(err as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message
|
|
||||||
toast.error(uploadMsg ?? "Failed to update profile picture")
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { Bell, BellOff, CheckCheck, Mail, MailOpen, Trash2 } from "lucide-react"
|
import { Bell, BellOff, CheckCheck, Mail, MailOpen, Trash2 } from "lucide-react"
|
||||||
|
|
@ -207,7 +208,7 @@ export function NotificationDropdown() {
|
||||||
next.delete(pending.notification.id)
|
next.delete(pending.notification.id)
|
||||||
return next
|
return next
|
||||||
})
|
})
|
||||||
toast.error("Failed to delete notification")
|
notifyApiError(err, "Failed to delete notification")
|
||||||
}
|
}
|
||||||
}, [commitDeleteNotification, selectedNotificationId])
|
}, [commitDeleteNotification, selectedNotificationId])
|
||||||
|
|
||||||
|
|
@ -282,7 +283,7 @@ export function NotificationDropdown() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setDetailError(true)
|
setDetailError(true)
|
||||||
toast.error("Failed to load notification details")
|
notifyApiError(err, "Failed to load notification details")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setDetailLoading(false)
|
setDetailLoading(false)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,11 @@ export const AvatarImage = React.forwardRef<
|
||||||
React.ElementRef<typeof AvatarPrimitive.Image>,
|
React.ElementRef<typeof AvatarPrimitive.Image>,
|
||||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<AvatarPrimitive.Image ref={ref} className={cn("aspect-square h-full w-full", className)} {...props} />
|
<AvatarPrimitive.Image
|
||||||
|
ref={ref}
|
||||||
|
className={cn("aspect-square h-full w-full object-cover object-center", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { listActivePersonasForPicker } from "../api/personas.api"
|
import { getPersonaById, listActivePersonasForPicker } from "../api/personas.api"
|
||||||
import { mapPersonaToCard, type PersonaCardModel } from "../lib/personaDisplay"
|
import { mapPersonaToCard, type PersonaCardModel } from "../lib/personaDisplay"
|
||||||
|
|
||||||
type UseActivePersonasOptions = {
|
type UseActivePersonasOptions = {
|
||||||
limit?: number
|
limit?: number
|
||||||
|
/** Include this persona in the picker even when inactive or missing from the active list. */
|
||||||
|
ensurePersonaId?: number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useActivePersonas(options: UseActivePersonasOptions = {}) {
|
export function useActivePersonas(options: UseActivePersonasOptions = {}) {
|
||||||
const { limit = 200 } = options
|
const { limit = 200, ensurePersonaId = null } = options
|
||||||
const [personas, setPersonas] = useState<PersonaCardModel[]>([])
|
const [personas, setPersonas] = useState<PersonaCardModel[]>([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
@ -16,7 +18,23 @@ export function useActivePersonas(options: UseActivePersonasOptions = {}) {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setError(null)
|
setError(null)
|
||||||
try {
|
try {
|
||||||
const list = await listActivePersonasForPicker(limit)
|
let list = await listActivePersonasForPicker(limit)
|
||||||
|
const ensureId =
|
||||||
|
ensurePersonaId != null &&
|
||||||
|
Number.isFinite(ensurePersonaId) &&
|
||||||
|
ensurePersonaId > 0
|
||||||
|
? ensurePersonaId
|
||||||
|
: null
|
||||||
|
if (ensureId != null && !list.some((persona) => persona.id === ensureId)) {
|
||||||
|
try {
|
||||||
|
const res = await getPersonaById(ensureId)
|
||||||
|
if (res.data) {
|
||||||
|
list = [res.data, ...list]
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Keep active list only if the saved persona cannot be loaded.
|
||||||
|
}
|
||||||
|
}
|
||||||
setPersonas(list.map(mapPersonaToCard))
|
setPersonas(list.map(mapPersonaToCard))
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
const msg =
|
||||||
|
|
@ -27,7 +45,7 @@ export function useActivePersonas(options: UseActivePersonasOptions = {}) {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}, [limit])
|
}, [limit, ensurePersonaId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void load()
|
void load()
|
||||||
|
|
|
||||||
45
src/lib/apiErrors.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import axios from "axios"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
const API_ERROR_NOTIFIED = "__apiErrorNotified"
|
||||||
|
|
||||||
|
export function readApiResponseMessage(data: unknown): string {
|
||||||
|
if (typeof data === "string") return data.trim()
|
||||||
|
if (data && typeof data === "object") {
|
||||||
|
const record = data as Record<string, unknown>
|
||||||
|
if (typeof record.message === "string" && record.message.trim()) {
|
||||||
|
return record.message.trim()
|
||||||
|
}
|
||||||
|
if (typeof record.error === "string" && record.error.trim()) {
|
||||||
|
return record.error.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getApiErrorMessage(error: unknown, fallback: string): string {
|
||||||
|
if (axios.isAxiosError(error)) {
|
||||||
|
const message = readApiResponseMessage(error.response?.data)
|
||||||
|
if (message) return message
|
||||||
|
}
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
export function markApiErrorNotified(error: unknown): void {
|
||||||
|
if (error && typeof error === "object") {
|
||||||
|
;(error as Record<string, unknown>)[API_ERROR_NOTIFIED] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function wasApiErrorNotified(error: unknown): boolean {
|
||||||
|
return Boolean(
|
||||||
|
error && typeof error === "object" && (error as Record<string, unknown>)[API_ERROR_NOTIFIED],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Show API `message`/`error` from failed requests, or a fallback when absent. */
|
||||||
|
export function notifyApiError(error: unknown, fallback: string): void {
|
||||||
|
if (wasApiErrorNotified(error)) return
|
||||||
|
toast.error(getApiErrorMessage(error, fallback))
|
||||||
|
markApiErrorNotified(error)
|
||||||
|
}
|
||||||
14
src/lib/navigateBack.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import type { NavigateFunction } from "react-router-dom";
|
||||||
|
|
||||||
|
export function canNavigateBack(): boolean {
|
||||||
|
const idx = (window.history.state as { idx?: number } | null)?.idx;
|
||||||
|
return typeof idx === "number" && idx > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function navigateBack(navigate: NavigateFunction, fallbackTo: string): void {
|
||||||
|
if (canNavigateBack()) {
|
||||||
|
navigate(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigate(fallbackTo);
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,14 @@ import type {
|
||||||
GetPersonasResponse,
|
GetPersonasResponse,
|
||||||
PersonaListItem,
|
PersonaListItem,
|
||||||
} from "../types/persona.types"
|
} from "../types/persona.types"
|
||||||
|
import amanuelAvatar from "../assets/personas/amanuel.png"
|
||||||
|
import aseffaAvatar from "../assets/personas/aseffa.png"
|
||||||
|
import bethelAvatar from "../assets/personas/bethel.png"
|
||||||
|
import dawitAvatar from "../assets/personas/dawit.png"
|
||||||
|
import hanaAvatar from "../assets/personas/hana.png"
|
||||||
|
import liyaAvatar from "../assets/personas/liya.png"
|
||||||
|
import mahletAvatar from "../assets/personas/mahlet.png"
|
||||||
|
import nahomAvatar from "../assets/personas/nahom.png"
|
||||||
|
|
||||||
export type PersonaCardModel = {
|
export type PersonaCardModel = {
|
||||||
id: string
|
id: string
|
||||||
|
|
@ -10,12 +18,57 @@ export type PersonaCardModel = {
|
||||||
avatar: string
|
avatar: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Soft, professional palette aligned with the admin brand (slate, indigo, violet). */
|
/** Realistic default portraits bundled with the admin app (see src/assets/personas). */
|
||||||
const PERSONA_FALLBACK_BACKGROUNDS = "f1f5f9,e0e7ff,ede9fe,fdf4ff,ecfeff"
|
const DEFAULT_PERSONA_AVATARS = [
|
||||||
|
dawitAvatar,
|
||||||
|
mahletAvatar,
|
||||||
|
amanuelAvatar,
|
||||||
|
bethelAvatar,
|
||||||
|
liyaAvatar,
|
||||||
|
aseffaAvatar,
|
||||||
|
hanaAvatar,
|
||||||
|
nahomAvatar,
|
||||||
|
] as const
|
||||||
|
|
||||||
|
const PERSONA_NAME_AVATARS: Record<string, string> = {
|
||||||
|
dawit: dawitAvatar,
|
||||||
|
mahlet: mahletAvatar,
|
||||||
|
amanuel: amanuelAvatar,
|
||||||
|
bethel: bethelAvatar,
|
||||||
|
liya: liyaAvatar,
|
||||||
|
aseffa: aseffaAvatar,
|
||||||
|
hana: hanaAvatar,
|
||||||
|
nahom: nahomAvatar,
|
||||||
|
}
|
||||||
|
|
||||||
|
function hashString(value: string): number {
|
||||||
|
let hash = 0
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
hash = (hash * 31 + value.charCodeAt(i)) >>> 0
|
||||||
|
}
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultPersonaAvatarUrl(
|
||||||
|
name: string,
|
||||||
|
personaId?: number | string,
|
||||||
|
): string {
|
||||||
|
const normalizedName = name.trim().toLowerCase()
|
||||||
|
const byName = PERSONA_NAME_AVATARS[normalizedName]
|
||||||
|
if (byName) return byName
|
||||||
|
|
||||||
|
const numericId = personaId != null ? Number(personaId) : NaN
|
||||||
|
const index =
|
||||||
|
Number.isFinite(numericId) && numericId > 0
|
||||||
|
? (numericId - 1) % DEFAULT_PERSONA_AVATARS.length
|
||||||
|
: hashString(normalizedName || "persona") % DEFAULT_PERSONA_AVATARS.length
|
||||||
|
|
||||||
|
return DEFAULT_PERSONA_AVATARS[index]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default avatar when `profile_picture` is null: professional illustrated portrait
|
* Default avatar when `profile_picture` is null: realistic bundled portrait,
|
||||||
* (DiceBear personas), not casual cartoon avataaars.
|
* matched by persona name when possible.
|
||||||
*/
|
*/
|
||||||
export function personaAvatarUrl(
|
export function personaAvatarUrl(
|
||||||
profilePicture: string | null | undefined,
|
profilePicture: string | null | undefined,
|
||||||
|
|
@ -24,12 +77,7 @@ export function personaAvatarUrl(
|
||||||
): string {
|
): string {
|
||||||
const url = profilePicture?.trim()
|
const url = profilePicture?.trim()
|
||||||
if (url) return url
|
if (url) return url
|
||||||
const params = new URLSearchParams({
|
return defaultPersonaAvatarUrl(name, personaId)
|
||||||
seed: personaId != null ? `yimaru-persona-${personaId}` : `yimaru-persona-${name}`,
|
|
||||||
backgroundColor: PERSONA_FALLBACK_BACKGROUNDS,
|
|
||||||
radius: "50",
|
|
||||||
})
|
|
||||||
return `https://api.dicebear.com/7.x/personas/svg?${params.toString()}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapPersonaToCard(persona: PersonaListItem): PersonaCardModel {
|
export function mapPersonaToCard(persona: PersonaListItem): PersonaCardModel {
|
||||||
|
|
|
||||||
66
src/lib/practiceEditDirty.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import type {
|
||||||
|
PracticeFormState,
|
||||||
|
PreservedQuestionSetFields,
|
||||||
|
} from "./practiceFullMapper"
|
||||||
|
import { dedupeParents } from "./practiceParents"
|
||||||
|
|
||||||
|
export type PracticeEditDirtyInput = {
|
||||||
|
formData: PracticeFormState
|
||||||
|
selectedPersona: string | null
|
||||||
|
preservedQuestionSet: PreservedQuestionSetFields
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeQuestionRow(question: PracticeFormState["questions"][number]) {
|
||||||
|
return {
|
||||||
|
serverQuestionId: question.serverQuestionId ?? null,
|
||||||
|
displayOrder: question.displayOrder,
|
||||||
|
associatedQuestionId: question.associatedQuestionId ?? null,
|
||||||
|
associatedAnchorRowId: question.associatedAnchorRowId ?? null,
|
||||||
|
prerequisiteQuestionIds: question.prerequisiteQuestionIds ?? [],
|
||||||
|
stimulusBlockKey: question.stimulusBlockKey ?? null,
|
||||||
|
questionTypeDefinitionId: question.questionTypeDefinitionId ?? null,
|
||||||
|
text: String(question.text ?? "").trim(),
|
||||||
|
difficultyLevel: question.difficultyLevel,
|
||||||
|
points: Number(question.points),
|
||||||
|
dynamicFieldValues: question.dynamicFieldValues ?? {},
|
||||||
|
mcqOptions: (question.mcqOptions ?? []).map((option) => ({
|
||||||
|
text: String(option.text ?? "").trim(),
|
||||||
|
isCorrect: Boolean(option.isCorrect),
|
||||||
|
})),
|
||||||
|
trueFalseCorrect: question.trueFalseCorrect !== false,
|
||||||
|
shortAnswers: (question.shortAnswers ?? []).map((answer) => String(answer).trim()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildPracticeEditSnapshot(input: PracticeEditDirtyInput): string {
|
||||||
|
const { formData, selectedPersona, preservedQuestionSet } = input
|
||||||
|
|
||||||
|
return JSON.stringify({
|
||||||
|
title: formData.title.trim(),
|
||||||
|
description: formData.description.trim(),
|
||||||
|
storyImageUrl: formData.storyImageUrl.trim(),
|
||||||
|
shuffleQuestions: Boolean(formData.shuffleQuestions),
|
||||||
|
tips: formData.tips.trim(),
|
||||||
|
authoringProfile: formData.authoringProfile,
|
||||||
|
stimulusBlocks: formData.stimulusBlocks,
|
||||||
|
parents: dedupeParents(formData.parents),
|
||||||
|
questions: [...formData.questions]
|
||||||
|
.map(normalizeQuestionRow)
|
||||||
|
.sort((a, b) => a.displayOrder - b.displayOrder),
|
||||||
|
selectedPersona: selectedPersona?.trim() || null,
|
||||||
|
preservedQuestionSet: {
|
||||||
|
timeLimitMinutes: preservedQuestionSet.timeLimitMinutes,
|
||||||
|
passingScore: preservedQuestionSet.passingScore,
|
||||||
|
introVideoUrl: preservedQuestionSet.introVideoUrl.trim(),
|
||||||
|
status: preservedQuestionSet.status,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasPracticeEditChanges(
|
||||||
|
initialSnapshot: string | null,
|
||||||
|
current: PracticeEditDirtyInput,
|
||||||
|
): boolean {
|
||||||
|
if (!initialSnapshot) return false
|
||||||
|
return buildPracticeEditSnapshot(current) !== initialSnapshot
|
||||||
|
}
|
||||||
|
|
@ -308,6 +308,7 @@ function normalizePracticeFullQuestionSet(raw: unknown): PracticeFullQuestionSet
|
||||||
owner_type: pickStr(record, "owner_type", "OwnerType", "ownerType") || undefined,
|
owner_type: pickStr(record, "owner_type", "OwnerType", "ownerType") || undefined,
|
||||||
owner_id: pickNum(record, "owner_id", "OwnerId", "ownerId") ?? undefined,
|
owner_id: pickNum(record, "owner_id", "OwnerId", "ownerId") ?? undefined,
|
||||||
persona: pickStr(record, "persona", "Persona") || null,
|
persona: pickStr(record, "persona", "Persona") || null,
|
||||||
|
persona_id: pickNum(record, "persona_id", "PersonaId", "personaId"),
|
||||||
shuffle_questions: Boolean(
|
shuffle_questions: Boolean(
|
||||||
record.shuffle_questions ?? record.ShuffleQuestions ?? false,
|
record.shuffle_questions ?? record.ShuffleQuestions ?? false,
|
||||||
),
|
),
|
||||||
|
|
@ -565,6 +566,25 @@ function mapFullQuestionToFormRow(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parsePersonaIdValue(value: unknown): number | null {
|
||||||
|
if (value == null) return null
|
||||||
|
const n = Number(value)
|
||||||
|
return Number.isFinite(n) && n > 0 ? n : null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolvePracticePersonaId(
|
||||||
|
practice: PracticeFullPractice,
|
||||||
|
questionSet: PracticeFullQuestionSet,
|
||||||
|
): number | null {
|
||||||
|
const fromPractice = parsePersonaIdValue(practice.persona_id)
|
||||||
|
if (fromPractice != null) return fromPractice
|
||||||
|
|
||||||
|
const fromQuestionSet = parsePersonaIdValue(questionSet.persona_id)
|
||||||
|
if (fromQuestionSet != null) return fromQuestionSet
|
||||||
|
|
||||||
|
return parsePersonaIdValue(questionSet.persona)
|
||||||
|
}
|
||||||
|
|
||||||
export function mapPracticeFullToFormState(
|
export function mapPracticeFullToFormState(
|
||||||
data: PracticeFullData,
|
data: PracticeFullData,
|
||||||
typeDefinitions: QuestionTypeDefinition[],
|
typeDefinitions: QuestionTypeDefinition[],
|
||||||
|
|
@ -618,10 +638,7 @@ export function mapPracticeFullToFormState(
|
||||||
parents: parentsFromPractice(practice),
|
parents: parentsFromPractice(practice),
|
||||||
questions: formQuestions,
|
questions: formQuestions,
|
||||||
},
|
},
|
||||||
personaId:
|
personaId: resolvePracticePersonaId(practice, question_set),
|
||||||
practice.persona_id != null && Number.isFinite(practice.persona_id)
|
|
||||||
? practice.persona_id
|
|
||||||
: null,
|
|
||||||
preservedQuestionSet: {
|
preservedQuestionSet: {
|
||||||
timeLimitMinutes: question_set.time_limit_minutes ?? null,
|
timeLimitMinutes: question_set.time_limit_minutes ?? null,
|
||||||
passingScore: question_set.passing_score ?? null,
|
passingScore: question_set.passing_score ?? null,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ export function practiceParentKey(parent: PracticeParent): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function kindLabel(kind: PracticeParentKind): string {
|
function kindLabel(kind: PracticeParentKind): string {
|
||||||
|
if (kind === "CATALOG_COURSE") return "Catalog course"
|
||||||
|
if (kind === "UNIT") return "Unit"
|
||||||
if (kind === "COURSE") return "Course"
|
if (kind === "COURSE") return "Course"
|
||||||
if (kind === "MODULE") return "Module"
|
if (kind === "MODULE") return "Module"
|
||||||
return "Lesson"
|
return "Lesson"
|
||||||
|
|
@ -98,12 +100,32 @@ async function resolveExamPrepCourseTitles(
|
||||||
const res = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
const res = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
||||||
for (const course of res.data?.data?.catalog_courses ?? []) {
|
for (const course of res.data?.data?.catalog_courses ?? []) {
|
||||||
if (ids.has(course.id)) {
|
if (ids.has(course.id)) {
|
||||||
map.set(`COURSE:${course.id}`, course.name?.trim() || `Course #${course.id}`)
|
const title = course.name?.trim() || `Course #${course.id}`
|
||||||
|
map.set(`CATALOG_COURSE:${course.id}`, title)
|
||||||
|
map.set(`COURSE:${course.id}`, title)
|
||||||
ids.delete(course.id)
|
ids.delete(course.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveExamPrepUnitTitles(
|
||||||
|
ids: Set<number>,
|
||||||
|
map: PracticeParentTitleMap,
|
||||||
|
): Promise<void> {
|
||||||
|
if (ids.size === 0) return
|
||||||
|
const coursesRes = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
||||||
|
for (const course of coursesRes.data?.data?.catalog_courses ?? []) {
|
||||||
|
if (ids.size === 0) break
|
||||||
|
const unitsRes = await getExamPrepCatalogUnits(course.id, { limit: LIST_LIMIT, offset: 0 })
|
||||||
|
for (const unit of unitsRes.data?.data?.units ?? []) {
|
||||||
|
if (ids.has(unit.id)) {
|
||||||
|
map.set(`UNIT:${unit.id}`, unit.name?.trim() || `Unit #${unit.id}`)
|
||||||
|
ids.delete(unit.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function resolveLearnEnglishModuleTitles(
|
async function resolveLearnEnglishModuleTitles(
|
||||||
ids: Set<number>,
|
ids: Set<number>,
|
||||||
map: PracticeParentTitleMap,
|
map: PracticeParentTitleMap,
|
||||||
|
|
@ -230,18 +252,23 @@ export async function resolvePracticeParentTitles(
|
||||||
|
|
||||||
const normalized = dedupeParents(parents)
|
const normalized = dedupeParents(parents)
|
||||||
const unresolvedCourses = new Set<number>()
|
const unresolvedCourses = new Set<number>()
|
||||||
|
const unresolvedCatalogCourses = new Set<number>()
|
||||||
|
const unresolvedUnits = new Set<number>()
|
||||||
const unresolvedModules = new Set<number>()
|
const unresolvedModules = new Set<number>()
|
||||||
const unresolvedLessons = new Set<number>()
|
const unresolvedLessons = new Set<number>()
|
||||||
|
|
||||||
for (const parent of normalized) {
|
for (const parent of normalized) {
|
||||||
if (map.has(practiceParentKey(parent))) continue
|
if (map.has(practiceParentKey(parent))) continue
|
||||||
if (parent.parent_kind === "COURSE") unresolvedCourses.add(parent.parent_id)
|
if (parent.parent_kind === "COURSE") unresolvedCourses.add(parent.parent_id)
|
||||||
|
if (parent.parent_kind === "CATALOG_COURSE") unresolvedCatalogCourses.add(parent.parent_id)
|
||||||
|
if (parent.parent_kind === "UNIT") unresolvedUnits.add(parent.parent_id)
|
||||||
if (parent.parent_kind === "MODULE") unresolvedModules.add(parent.parent_id)
|
if (parent.parent_kind === "MODULE") unresolvedModules.add(parent.parent_id)
|
||||||
if (parent.parent_kind === "LESSON") unresolvedLessons.add(parent.parent_id)
|
if (parent.parent_kind === "LESSON") unresolvedLessons.add(parent.parent_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
await resolveLearnEnglishCourseTitles(unresolvedCourses, map)
|
await resolveLearnEnglishCourseTitles(unresolvedCourses, map)
|
||||||
await resolveExamPrepCourseTitles(unresolvedCourses, map)
|
await resolveExamPrepCourseTitles(unresolvedCatalogCourses, map)
|
||||||
|
await resolveExamPrepUnitTitles(unresolvedUnits, map)
|
||||||
await resolveLearnEnglishModuleTitles(unresolvedModules, map)
|
await resolveLearnEnglishModuleTitles(unresolvedModules, map)
|
||||||
await resolveExamPrepModuleTitles(unresolvedModules, map)
|
await resolveExamPrepModuleTitles(unresolvedModules, map)
|
||||||
await resolveLearnEnglishLessonTitles(unresolvedLessons, map)
|
await resolveLearnEnglishLessonTitles(unresolvedLessons, map)
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,26 @@ export function formatTeamRoleLabel(teamRole: string): string {
|
||||||
if (found) return found.label
|
if (found) return found.label
|
||||||
return teamRole.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())
|
return teamRole.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Role name sent to POST /team/members/invite (used in invitation emails). */
|
||||||
|
export function teamRoleNameForInvite(teamRole: string, explicitName?: string): string {
|
||||||
|
const named = explicitName?.trim()
|
||||||
|
if (named) return named
|
||||||
|
|
||||||
|
const fromOptions = TEAM_ROLE_OPTIONS.find(
|
||||||
|
(o) => o.value === teamRole || o.value === teamRole.toUpperCase(),
|
||||||
|
)
|
||||||
|
if (fromOptions) return fromOptions.label
|
||||||
|
|
||||||
|
return teamRole.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TeamRoleOption = { value: string; label: string }
|
||||||
|
|
||||||
|
export function rbacRolesToTeamRoleOptions(roles: Role[]): TeamRoleOption[] {
|
||||||
|
const names = Array.from(
|
||||||
|
new Set(roles.map((role) => role.name.trim()).filter(Boolean)),
|
||||||
|
).sort((a, b) => a.localeCompare(b))
|
||||||
|
|
||||||
|
return names.map((name) => ({ value: name, label: name }))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import {
|
||||||
User,
|
User,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../lib/apiErrors"
|
||||||
import { getTeamMe, updateTeamMe } from "../api/team.api"
|
import { getTeamMe, updateTeamMe } from "../api/team.api"
|
||||||
import { Badge } from "../components/ui/badge"
|
import { Badge } from "../components/ui/badge"
|
||||||
import { Button } from "../components/ui/button"
|
import { Button } from "../components/ui/button"
|
||||||
|
|
@ -193,10 +194,7 @@ export function ProfilePage() {
|
||||||
toast.success(res.data.message || "Profile updated successfully")
|
toast.success(res.data.message || "Profile updated successfully")
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to update profile", err)
|
console.error("Failed to update profile", err)
|
||||||
const message =
|
notifyApiError(err, "Failed to update profile")
|
||||||
(err as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update profile"
|
|
||||||
toast.error(message)
|
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../lib/apiErrors"
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Eye,
|
Eye,
|
||||||
|
|
@ -81,10 +82,7 @@ function SecurityTab({ memberId }: { memberId: number }) {
|
||||||
logoutToLogin({ passwordChanged: true });
|
logoutToLogin({ passwordChanged: true });
|
||||||
return;
|
return;
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to update password.");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update password.";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
User,
|
User,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
acceptTeamInvitation,
|
acceptTeamInvitation,
|
||||||
parseVerifyInvitation,
|
parseVerifyInvitation,
|
||||||
|
|
@ -129,10 +130,7 @@ export function AcceptInvitePage() {
|
||||||
toast.success(res.data?.message ?? "Account setup complete. You can sign in now.")
|
toast.success(res.data?.message ?? "Account setup complete. You can sign in now.")
|
||||||
navigate("/login", { replace: true })
|
navigate("/login", { replace: true })
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to complete setup")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to complete setup"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useMemo, useState, type ChangeEvent } from "react"
|
import { useMemo, useState, type ChangeEvent } from "react"
|
||||||
import { ArrowLeft, ArrowRight, Check, GripVertical, Plus, Rocket, Trash2, Upload } from "lucide-react"
|
import { ArrowLeft, ArrowRight, Check, GripVertical, Plus, Rocket, Trash2, Upload } from "lucide-react"
|
||||||
import { Link, useLocation, useNavigate, useParams } from "react-router-dom"
|
import { Link, useLocation, useNavigate, useParams } from "react-router-dom"
|
||||||
|
|
@ -161,7 +162,7 @@ export function AddNewLessonPage() {
|
||||||
toast.success("Intro video uploaded")
|
toast.success("Intro video uploaded")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload lesson intro video:", error)
|
console.error("Failed to upload lesson intro video:", error)
|
||||||
toast.error("Failed to upload intro video")
|
notifyApiError(error, "Failed to upload intro video")
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingIntroVideo(false)
|
setUploadingIntroVideo(false)
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +194,7 @@ export function AddNewLessonPage() {
|
||||||
toast.success("Intro video URL imported")
|
toast.success("Intro video URL imported")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to import intro video URL:", error)
|
console.error("Failed to import intro video URL:", error)
|
||||||
toast.error("Failed to import intro video URL")
|
notifyApiError(error, "Failed to import intro video URL")
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingIntroVideo(false)
|
setUploadingIntroVideo(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useMemo, useRef, useState, type ChangeEvent } from "react";
|
import { useMemo, useRef, useState, type ChangeEvent } from "react";
|
||||||
import { Link, useLocation, useParams, useNavigate } from "react-router-dom";
|
import { Link, useLocation, useParams, useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
|
|
@ -228,7 +229,7 @@ export function AddNewPracticePage() {
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload intro video:", error);
|
console.error("Failed to upload intro video:", error);
|
||||||
toast.error("Failed to upload intro video");
|
notifyApiError(error, "Failed to upload intro video");
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingIntroVideo(false);
|
setUploadingIntroVideo(false);
|
||||||
}
|
}
|
||||||
|
|
@ -259,7 +260,7 @@ export function AddNewPracticePage() {
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to import intro video URL:", error);
|
console.error("Failed to import intro video URL:", error);
|
||||||
toast.error("Failed to import intro video URL");
|
notifyApiError(error, "Failed to import intro video URL");
|
||||||
} finally {
|
} finally {
|
||||||
setImportingIntroVideoUrl(false);
|
setImportingIntroVideoUrl(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
|
import { getApiErrorMessage, notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import {
|
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
||||||
Link,
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
useNavigate,
|
import { navigateBack } from "../../lib/navigateBack";
|
||||||
useParams,
|
|
||||||
useSearchParams,
|
|
||||||
} from "react-router-dom";
|
|
||||||
import { ArrowLeft } from "lucide-react";
|
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { Stepper } from "../../components/ui/stepper";
|
import { Stepper } from "../../components/ui/stepper";
|
||||||
|
|
@ -15,7 +12,6 @@ import type { QuestionTypeDefinition } from "../../types/questionTypeDefinition.
|
||||||
import { getQuestionTypeDefinitions } from "../../api/questionTypeDefinitions.api";
|
import { getQuestionTypeDefinitions } from "../../api/questionTypeDefinitions.api";
|
||||||
import { emptyDynamicFieldValuesForDefinition } from "../../lib/learnEnglishDefinitionQuestion";
|
import { emptyDynamicFieldValuesForDefinition } from "../../lib/learnEnglishDefinitionQuestion";
|
||||||
import {
|
import {
|
||||||
learnEnglishPracticeApiErrorMessage,
|
|
||||||
validateLearnEnglishQuestionsWithDefinitions,
|
validateLearnEnglishQuestionsWithDefinitions,
|
||||||
} from "../../lib/learnEnglishPracticePublish";
|
} from "../../lib/learnEnglishPracticePublish";
|
||||||
import { executePracticeCreation } from "../../lib/practiceCreationOrchestrator";
|
import { executePracticeCreation } from "../../lib/practiceCreationOrchestrator";
|
||||||
|
|
@ -213,6 +209,8 @@ export function AddPracticeFlow() {
|
||||||
isFromQuestionType,
|
isFromQuestionType,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const goBack = () => navigateBack(navigate, backPath);
|
||||||
|
|
||||||
const [currentStep, setCurrentStep] = useState(1);
|
const [currentStep, setCurrentStep] = useState(1);
|
||||||
const [isPublished, setIsPublished] = useState(false);
|
const [isPublished, setIsPublished] = useState(false);
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
@ -279,7 +277,7 @@ export function AddPracticeFlow() {
|
||||||
if (!cancelled) setTypeDefinitions(list);
|
if (!cancelled) setTypeDefinitions(list);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
setDefinitionsError(learnEnglishPracticeApiErrorMessage(e));
|
setDefinitionsError(getApiErrorMessage(e, "Failed to load question type definitions"));
|
||||||
setTypeDefinitions([]);
|
setTypeDefinitions([]);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -506,9 +504,7 @@ export function AddPracticeFlow() {
|
||||||
toast.success("Practice created successfully");
|
toast.success("Practice created successfully");
|
||||||
setIsPublished(true);
|
setIsPublished(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error("Could not save practice", {
|
notifyApiError(e, "Could not save practice");
|
||||||
description: learnEnglishPracticeApiErrorMessage(e),
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|
@ -547,7 +543,7 @@ export function AddPracticeFlow() {
|
||||||
</p>
|
</p>
|
||||||
<div className="flex flex-col gap-4 w-full max-w-[400px]">
|
<div className="flex flex-col gap-4 w-full max-w-[400px]">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
className="h-14 rounded-[6px] bg-[#9E2891] font-bold shadow-xl shadow-brand-500/20 text-[16px] text-white "
|
className="h-14 rounded-[6px] bg-[#9E2891] font-bold shadow-xl shadow-brand-500/20 text-[16px] text-white "
|
||||||
>
|
>
|
||||||
{backLabel}
|
{backLabel}
|
||||||
|
|
@ -626,7 +622,7 @@ export function AddPracticeFlow() {
|
||||||
formData={formData}
|
formData={formData}
|
||||||
setFormData={setFormData}
|
setFormData={setFormData}
|
||||||
nextStep={nextStep}
|
nextStep={nextStep}
|
||||||
onCancel={() => navigate(backPath)}
|
onCancel={goBack}
|
||||||
isLessonPractice={isLearnEnglishLessonPractice}
|
isLessonPractice={isLearnEnglishLessonPractice}
|
||||||
lessonTitle={lessonTitleDisplay}
|
lessonTitle={lessonTitleDisplay}
|
||||||
parentSummary={parentSummary}
|
parentSummary={parentSummary}
|
||||||
|
|
@ -755,13 +751,7 @@ export function AddPracticeFlow() {
|
||||||
<div className="space-y-8 px-6 pb-16 pt-6">
|
<div className="space-y-8 px-6 pb-16 pt-6">
|
||||||
<div className="mx-auto max-w-7xl w-full">
|
<div className="mx-auto max-w-7xl w-full">
|
||||||
<div className="flex items-center justify-between mb-8">
|
<div className="flex items-center justify-between mb-8">
|
||||||
<Link
|
<PageBackLink fallbackTo={backPath} label={backLabel} />
|
||||||
to={backPath}
|
|
||||||
className="flex items-center gap-2 text-[15px] font-medium text-grayScale-600 transition-colors hover:text-brand-500 decoration-none"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
{backLabel}
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className=" mb-10">
|
<div className=" mb-10">
|
||||||
|
|
@ -772,7 +762,7 @@ export function AddPracticeFlow() {
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="rounded-[8px] border-grayScale-200 text-grayScale-600 h-10 px-6 font-bold bg-white hover:bg-grayScale-50"
|
className="rounded-[8px] border-grayScale-200 text-grayScale-600 h-10 px-6 font-bold bg-white hover:bg-grayScale-50"
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { useNavigate, useParams } from "react-router-dom"
|
import { useNavigate, useParams } from "react-router-dom"
|
||||||
import { ArrowLeft, Plus, X } from "lucide-react"
|
import { ArrowLeft, Plus, X } from "lucide-react"
|
||||||
|
import { navigateBack } from "../../lib/navigateBack"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Button } from "../../components/ui/button"
|
import { Button } from "../../components/ui/button"
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card"
|
import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card"
|
||||||
|
|
@ -128,7 +130,7 @@ export function AddQuestionPage() {
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to load question:", error)
|
console.error("Failed to load question:", error)
|
||||||
toast.error("Failed to load question details")
|
notifyApiError(error, "Failed to load question details")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -339,7 +341,7 @@ export function AddQuestionPage() {
|
||||||
navigate("/content/questions")
|
navigate("/content/questions")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to save question:", error)
|
console.error("Failed to save question:", error)
|
||||||
toast.error("Failed to save question")
|
notifyApiError(error, "Failed to save question")
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
@ -351,7 +353,7 @@ export function AddQuestionPage() {
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => navigate("/content/questions")}
|
onClick={() => navigateBack(navigate, "/content/questions")}
|
||||||
className="h-9 w-9 shrink-0 rounded-lg bg-grayScale-50 hover:bg-brand-500/10 hover:text-brand-500"
|
className="h-9 w-9 shrink-0 rounded-lg bg-grayScale-50 hover:bg-brand-500/10 hover:text-brand-500"
|
||||||
>
|
>
|
||||||
<ArrowLeft className="h-4 w-4" />
|
<ArrowLeft className="h-4 w-4" />
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ArrowLeft } from "lucide-react";
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
|
import { navigateBack } from "../../lib/navigateBack";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { Stepper } from "../../components/ui/stepper";
|
import { Stepper } from "../../components/ui/stepper";
|
||||||
import { createModuleLesson } from "../../api/courses.api";
|
import { createModuleLesson } from "../../api/courses.api";
|
||||||
|
|
@ -62,6 +64,7 @@ export function AddVideoFlow() {
|
||||||
const prevStep = () => setCurrentStep((prev) => Math.max(prev - 1, 1));
|
const prevStep = () => setCurrentStep((prev) => Math.max(prev - 1, 1));
|
||||||
|
|
||||||
const backPath = `/new-content/learn-english/${level}/courses/${courseId}/modules/${moduleId}`;
|
const backPath = `/new-content/learn-english/${level}/courses/${courseId}/modules/${moduleId}`;
|
||||||
|
const goBack = () => navigateBack(navigate, backPath);
|
||||||
|
|
||||||
const handleCreateLesson = async (publishStatus: PracticePublishStatus) => {
|
const handleCreateLesson = async (publishStatus: PracticePublishStatus) => {
|
||||||
const mid = Number(moduleId);
|
const mid = Number(moduleId);
|
||||||
|
|
@ -118,10 +121,7 @@ export function AddVideoFlow() {
|
||||||
setIsPublished(true);
|
setIsPublished(true);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to create lesson");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create lesson";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishing(false);
|
setPublishing(false);
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +155,7 @@ export function AddVideoFlow() {
|
||||||
|
|
||||||
<div className="flex flex-col gap-4 w-full max-w-[400px]">
|
<div className="flex flex-col gap-4 w-full max-w-[400px]">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
className="h-12 rounded-[6px] bg-brand-500 font-bold text-[17px] text-white transition-all active:scale-95"
|
className="h-12 rounded-[6px] bg-brand-500 font-bold text-[17px] text-white transition-all active:scale-95"
|
||||||
>
|
>
|
||||||
View module
|
View module
|
||||||
|
|
@ -189,17 +189,11 @@ export function AddVideoFlow() {
|
||||||
<div className="space-y-8 pb-32 px-6 pt-6 min-h-screen ">
|
<div className="space-y-8 pb-32 px-6 pt-6 min-h-screen ">
|
||||||
<div className="mx-auto max-w-7xl w-full">
|
<div className="mx-auto max-w-7xl w-full">
|
||||||
<div className="flex items-center justify-between mb-8">
|
<div className="flex items-center justify-between mb-8">
|
||||||
<Link
|
<PageBackLink fallbackTo={backPath} label="Back to module" className="text-grayScale-500" />
|
||||||
to={backPath}
|
|
||||||
className="flex items-center gap-2 text-[15px] font-medium text-grayScale-500 transition-colors hover:text-brand-500 decoration-none"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
Back to module
|
|
||||||
</Link>
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="rounded-[8px] border-grayScale-200 text-grayScale-600 h-10 px-6 font-bold bg-white hover:bg-grayScale-50"
|
className="rounded-[8px] border-grayScale-200 text-grayScale-600 h-10 px-6 font-bold bg-white hover:bg-grayScale-50"
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { Search, Plus, RefreshCw, Edit2, ToggleLeft, ToggleRight, BookOpen, ChevronDown, ChevronLeft, ChevronRight } from "lucide-react"
|
import { Search, Plus, RefreshCw, Edit2, ToggleLeft, ToggleRight, BookOpen, ChevronDown, ChevronLeft, ChevronRight } from "lucide-react"
|
||||||
|
|
@ -32,6 +33,7 @@ import { countActiveFilters } from "../../lib/adminFilterUtils"
|
||||||
import { cn } from "../../lib/utils"
|
import { cn } from "../../lib/utils"
|
||||||
import { TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
import { TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
||||||
import spinnerSrc from "../../assets/Circular-indeterminate progress indicator.svg"
|
import spinnerSrc from "../../assets/Circular-indeterminate progress indicator.svg"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
|
|
||||||
type CourseWithCategory = Course & { category_name: string }
|
type CourseWithCategory = Course & { category_name: string }
|
||||||
|
|
||||||
|
|
@ -173,9 +175,7 @@ export function AllCoursesPage() {
|
||||||
await fetchAllCourses()
|
await fetchAllCourses()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error("Failed to create course:", err)
|
console.error("Failed to create course:", err)
|
||||||
toast.error("Failed to create sub-category", {
|
notifyApiError(err, "Failed to create sub-category")
|
||||||
description: err?.response?.data?.message || "Please try again.",
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreating(false)
|
setCreating(false)
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +188,7 @@ export function AllCoursesPage() {
|
||||||
await fetchAllCourses()
|
await fetchAllCourses()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to update course status:", err)
|
console.error("Failed to update course status:", err)
|
||||||
toast.error("Failed to update sub-category status")
|
notifyApiError(err, "Failed to update sub-category status")
|
||||||
} finally {
|
} finally {
|
||||||
setTogglingId(null)
|
setTogglingId(null)
|
||||||
}
|
}
|
||||||
|
|
@ -222,9 +222,7 @@ export function AllCoursesPage() {
|
||||||
await fetchAllCourses()
|
await fetchAllCourses()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error("Failed to update course:", err)
|
console.error("Failed to update course:", err)
|
||||||
toast.error("Failed to update sub-category", {
|
notifyApiError(err, "Failed to update sub-category")
|
||||||
description: err?.response?.data?.message || "Please try again.",
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setUpdating(false)
|
setUpdating(false)
|
||||||
}
|
}
|
||||||
|
|
@ -262,6 +260,7 @@ export function AllCoursesPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
<PageBackLink fallbackTo="/content" label="Back" />
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import { FolderOpen, RefreshCw, BookOpen, Plus, Trash2 } from "lucide-react"
|
import { FolderOpen, RefreshCw, BookOpen, Plus, Trash2 } from "lucide-react"
|
||||||
|
|
@ -371,13 +372,8 @@ export function CourseCategoryPage() {
|
||||||
setPendingSubCategories([])
|
setPendingSubCategories([])
|
||||||
setCreateOpen(false)
|
setCreateOpen(false)
|
||||||
fetchCategories()
|
fetchCategories()
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
const message =
|
notifyApiError(err, "Could not create category")
|
||||||
err?.response?.data?.message ||
|
|
||||||
"Failed to create category. Please try again."
|
|
||||||
toast.error("Could not create category", {
|
|
||||||
description: message,
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreating(false)
|
setCreating(false)
|
||||||
}
|
}
|
||||||
|
|
@ -415,9 +411,8 @@ export function CourseCategoryPage() {
|
||||||
toast.success("Category deleted")
|
toast.success("Category deleted")
|
||||||
setDeleteTarget(null)
|
setDeleteTarget(null)
|
||||||
await fetchCategories()
|
await fetchCategories()
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
const message = err?.response?.data?.message || "Failed to delete category."
|
notifyApiError(err, "Could not delete category")
|
||||||
toast.error("Could not delete category", { description: message })
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
|
|
@ -282,18 +283,14 @@ export function CourseDetailPage() {
|
||||||
} else {
|
} else {
|
||||||
console.error(modulesOutcome.reason);
|
console.error(modulesOutcome.reason);
|
||||||
setModules([]);
|
setModules([]);
|
||||||
toast.error("Could not load modules", {
|
notifyApiError(err, "Could not load modules");
|
||||||
description: "Check your connection or try again.",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setError("Failed to load course");
|
setError("Failed to load course");
|
||||||
setCourse(null);
|
setCourse(null);
|
||||||
setModules([]);
|
setModules([]);
|
||||||
toast.error("Could not load course", {
|
notifyApiError(e, "Could not load course");
|
||||||
description: "Check your connection or try again.",
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -378,10 +375,7 @@ export function CourseDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update practice status");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update practice status";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusPracticeId(null);
|
setPublishStatusPracticeId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -406,10 +400,7 @@ export function CourseDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update module status");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module status";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusModuleId(null);
|
setPublishStatusModuleId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -434,10 +425,7 @@ export function CourseDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update module access tier");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module access tier";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierModuleId(null);
|
setAccessTierModuleId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -474,10 +462,7 @@ export function CourseDetailPage() {
|
||||||
await loadPage();
|
await loadPage();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update module");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingModuleEdit(false);
|
setSavingModuleEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -493,10 +478,7 @@ export function CourseDetailPage() {
|
||||||
await loadPage();
|
await loadPage();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to delete module");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete module";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingModuleInFlight(false);
|
setDeletingModuleInFlight(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import {
|
import {
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
|
|
@ -28,6 +29,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/ca
|
||||||
import { Button } from "../../components/ui/button"
|
import { Button } from "../../components/ui/button"
|
||||||
import { Select } from "../../components/ui/select"
|
import { Select } from "../../components/ui/select"
|
||||||
import { Badge } from "../../components/ui/badge"
|
import { Badge } from "../../components/ui/badge"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
import {
|
import {
|
||||||
getCourseCategories,
|
getCourseCategories,
|
||||||
getCoursesByCategory,
|
getCoursesByCategory,
|
||||||
|
|
@ -226,7 +228,7 @@ export function CourseFlowBuilderPage() {
|
||||||
const all = sortByDisplayOrder(res.data.data.categories ?? [])
|
const all = sortByDisplayOrder(res.data.data.categories ?? [])
|
||||||
setCategories(all)
|
setCategories(all)
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to load course categories.")
|
notifyApiError(err, "Failed to load course categories.")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -263,7 +265,7 @@ export function CourseFlowBuilderPage() {
|
||||||
setCoursesByCategory((prev) => ({ ...prev, [selectedCategoryId]: items }))
|
setCoursesByCategory((prev) => ({ ...prev, [selectedCategoryId]: items }))
|
||||||
setSelectedCourseId(items[0]?.id ?? null)
|
setSelectedCourseId(items[0]?.id ?? null)
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to load course sub-categories.")
|
notifyApiError(err, "Failed to load course sub-categories.")
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingCourses(false)
|
setLoadingCourses(false)
|
||||||
}
|
}
|
||||||
|
|
@ -351,7 +353,7 @@ export function CourseFlowBuilderPage() {
|
||||||
})
|
})
|
||||||
setVideosBySubCourse(videoMap)
|
setVideosBySubCourse(videoMap)
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to load course flow detail.")
|
notifyApiError(err, "Failed to load course flow detail.")
|
||||||
setLearningPath(null)
|
setLearningPath(null)
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingPath(false)
|
setLoadingPath(false)
|
||||||
|
|
@ -402,7 +404,7 @@ export function CourseFlowBuilderPage() {
|
||||||
[subCourseId]: videos,
|
[subCourseId]: videos,
|
||||||
}))
|
}))
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to load practice sets for course.")
|
notifyApiError(err, "Failed to load practice sets for course.")
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingPracticesBySubCourse((prev) => ({ ...prev, [subCourseId]: false }))
|
setLoadingPracticesBySubCourse((prev) => ({ ...prev, [subCourseId]: false }))
|
||||||
}
|
}
|
||||||
|
|
@ -429,7 +431,7 @@ export function CourseFlowBuilderPage() {
|
||||||
await reorderCategories(toReorderItems(reordered))
|
await reorderCategories(toReorderItems(reordered))
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setCategories(previous)
|
setCategories(previous)
|
||||||
toast.error(err?.response?.data?.message || "Failed to reorder categories.")
|
notifyApiError(err, "Failed to reorder categories.")
|
||||||
} finally {
|
} finally {
|
||||||
setSavingKey(null)
|
setSavingKey(null)
|
||||||
}
|
}
|
||||||
|
|
@ -455,7 +457,7 @@ export function CourseFlowBuilderPage() {
|
||||||
await reorderCourses(toReorderItems(reordered))
|
await reorderCourses(toReorderItems(reordered))
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setCoursesByCategory((prev) => ({ ...prev, [selectedCategoryId]: previous }))
|
setCoursesByCategory((prev) => ({ ...prev, [selectedCategoryId]: previous }))
|
||||||
toast.error(err?.response?.data?.message || "Failed to reorder courses.")
|
notifyApiError(err, "Failed to reorder courses.")
|
||||||
} finally {
|
} finally {
|
||||||
setSavingKey(null)
|
setSavingKey(null)
|
||||||
}
|
}
|
||||||
|
|
@ -481,7 +483,7 @@ export function CourseFlowBuilderPage() {
|
||||||
await reorderSubModules(toReorderItems(reordered))
|
await reorderSubModules(toReorderItems(reordered))
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setLearningPath((prev) => (prev ? { ...prev, sub_courses: previous } : prev))
|
setLearningPath((prev) => (prev ? { ...prev, sub_courses: previous } : prev))
|
||||||
toast.error(err?.response?.data?.message || "Failed to reorder sub-modules.")
|
notifyApiError(err, "Failed to reorder sub-modules.")
|
||||||
} finally {
|
} finally {
|
||||||
setSavingKey(null)
|
setSavingKey(null)
|
||||||
}
|
}
|
||||||
|
|
@ -526,7 +528,7 @@ export function CourseFlowBuilderPage() {
|
||||||
}
|
}
|
||||||
: prev,
|
: prev,
|
||||||
)
|
)
|
||||||
toast.error(err?.response?.data?.message || "Failed to reorder videos.")
|
notifyApiError(err, "Failed to reorder videos.")
|
||||||
} finally {
|
} finally {
|
||||||
setSavingKey(null)
|
setSavingKey(null)
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +554,7 @@ export function CourseFlowBuilderPage() {
|
||||||
await reorderPractices(toReorderItems(reordered))
|
await reorderPractices(toReorderItems(reordered))
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setPracticesBySubCourse((prev) => ({ ...prev, [subCourseId]: previous }))
|
setPracticesBySubCourse((prev) => ({ ...prev, [subCourseId]: previous }))
|
||||||
toast.error(err?.response?.data?.message || "Failed to reorder practices.")
|
notifyApiError(err, "Failed to reorder practices.")
|
||||||
} finally {
|
} finally {
|
||||||
setSavingKey(null)
|
setSavingKey(null)
|
||||||
}
|
}
|
||||||
|
|
@ -569,6 +571,7 @@ export function CourseFlowBuilderPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
<PageBackLink fallbackTo="/content" label="Back" />
|
||||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold tracking-tight text-grayScale-700">
|
<h1 className="text-2xl font-bold tracking-tight text-grayScale-700">
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Link, useParams, useNavigate } from "react-router-dom";
|
import { Link, useParams, useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
|
|
@ -183,7 +184,7 @@ export function CourseManagementPage() {
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Failed to load units");
|
notifyApiError(error, "Failed to load units");
|
||||||
setUnits([]);
|
setUnits([]);
|
||||||
} finally {
|
} finally {
|
||||||
setUnitsLoading(false);
|
setUnitsLoading(false);
|
||||||
|
|
@ -212,10 +213,7 @@ export function CourseManagementPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Course published" : "Course saved as draft",
|
nextStatus === "PUBLISHED" ? "Course published" : "Course saved as draft",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update course status");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course status";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCatalogCoursePublishStatusUpdating(false);
|
setCatalogCoursePublishStatusUpdating(false);
|
||||||
}
|
}
|
||||||
|
|
@ -239,10 +237,7 @@ export function CourseManagementPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Unit published" : "Unit saved as draft",
|
nextStatus === "PUBLISHED" ? "Unit published" : "Unit saved as draft",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update unit status");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update unit status";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null);
|
setPublishStatusUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -264,10 +259,7 @@ export function CourseManagementPage() {
|
||||||
nextTier === "PREMIUM" ? "Unit set to Premium" : "Unit set to Free",
|
nextTier === "PREMIUM" ? "Unit set to Premium" : "Unit set to Free",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update unit access tier");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update unit access tier";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierUpdatingId(null);
|
setAccessTierUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -328,10 +320,7 @@ export function CourseManagementPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -373,10 +362,7 @@ export function CourseManagementPage() {
|
||||||
setAddUnitOpen(false);
|
setAddUnitOpen(false);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to create unit");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create unit";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreating(false);
|
setCreating(false);
|
||||||
}
|
}
|
||||||
|
|
@ -394,10 +380,7 @@ export function CourseManagementPage() {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload URL to MinIO");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload URL to MinIO";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -415,10 +398,7 @@ export function CourseManagementPage() {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload URL to MinIO");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload URL to MinIO";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -458,10 +438,7 @@ export function CourseManagementPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -504,10 +481,7 @@ export function CourseManagementPage() {
|
||||||
closeEditUnit();
|
closeEditUnit();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to update unit");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update unit";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingEdit(false);
|
setSavingEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -523,10 +497,7 @@ export function CourseManagementPage() {
|
||||||
setDeletingUnitId(null);
|
setDeletingUnitId(null);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to delete unit");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete unit";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingUnit(false);
|
setDeletingUnit(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { ArrowLeft, Plus, Video } from "lucide-react";
|
import { ArrowLeft, Plus, Video } from "lucide-react";
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
@ -282,10 +283,7 @@ export function CourseModuleDetailPage() {
|
||||||
toast.success("Video uploaded");
|
toast.success("Video uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload video");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload video";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingVideo(false);
|
setUploadingVideo(false);
|
||||||
}
|
}
|
||||||
|
|
@ -310,10 +308,7 @@ export function CourseModuleDetailPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -331,10 +326,7 @@ export function CourseModuleDetailPage() {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload URL to MinIO");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload URL to MinIO";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -376,10 +368,7 @@ export function CourseModuleDetailPage() {
|
||||||
setCreateLessonOpen(false);
|
setCreateLessonOpen(false);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to create lesson");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create lesson";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreatingLesson(false);
|
setCreatingLesson(false);
|
||||||
}
|
}
|
||||||
|
|
@ -427,10 +416,7 @@ export function CourseModuleDetailPage() {
|
||||||
toast.success("Video uploaded");
|
toast.success("Video uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload video");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload video";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditVideo(false);
|
setUploadingEditVideo(false);
|
||||||
}
|
}
|
||||||
|
|
@ -455,10 +441,7 @@ export function CourseModuleDetailPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -476,10 +459,7 @@ export function CourseModuleDetailPage() {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload URL to MinIO");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload URL to MinIO";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -513,10 +493,7 @@ export function CourseModuleDetailPage() {
|
||||||
closeEditLesson();
|
closeEditLesson();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to update lesson");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update lesson";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingEdit(false);
|
setSavingEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -532,10 +509,7 @@ export function CourseModuleDetailPage() {
|
||||||
setDeletingLessonId(null);
|
setDeletingLessonId(null);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to delete lesson");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete lesson";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingLesson(false);
|
setDeletingLesson(false);
|
||||||
}
|
}
|
||||||
|
|
@ -556,10 +530,7 @@ export function CourseModuleDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to update module status");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module status";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setModulePublishStatusUpdating(false);
|
setModulePublishStatusUpdating(false);
|
||||||
}
|
}
|
||||||
|
|
@ -586,13 +557,10 @@ export function CourseModuleDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
error,
|
||||||
?.message ??
|
nextStatus === "PUBLISHED" ? "Failed to publish lesson" : "Failed to save lesson as draft",
|
||||||
(nextStatus === "PUBLISHED"
|
);
|
||||||
? "Failed to publish lesson"
|
|
||||||
: "Failed to save lesson as draft");
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusLessonId(null);
|
setPublishStatusLessonId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -617,10 +585,7 @@ export function CourseModuleDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to update lesson access tier");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update lesson access tier";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierLessonId(null);
|
setAccessTierLessonId(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getApiErrorMessage } from "../../lib/apiErrors"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { Link, useParams, useNavigate } from "react-router-dom"
|
import { Link, useParams, useNavigate } from "react-router-dom"
|
||||||
import {
|
import {
|
||||||
|
|
@ -150,7 +151,7 @@ export function CoursesPage() {
|
||||||
await fetchSubCategories()
|
await fetchSubCategories()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error("Failed to create course:", err)
|
console.error("Failed to create course:", err)
|
||||||
setSaveError(err.response?.data?.message || "Failed to create sub-category")
|
setSaveError(getApiErrorMessage(err, "Failed to create sub-category"))
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +231,7 @@ export function CoursesPage() {
|
||||||
await fetchSubCategories()
|
await fetchSubCategories()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error("Failed to update course:", err)
|
console.error("Failed to update course:", err)
|
||||||
setUpdateError(err.response?.data?.message || "Failed to update sub-category")
|
setUpdateError(getApiErrorMessage(err, "Failed to update sub-category"))
|
||||||
} finally {
|
} finally {
|
||||||
setUpdating(false)
|
setUpdating(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom"
|
import { useNavigate, useParams, useSearchParams } from "react-router-dom"
|
||||||
import { ArrowLeft, Loader2 } from "lucide-react"
|
import { Loader2 } from "lucide-react"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Button } from "../../components/ui/button"
|
import { Button } from "../../components/ui/button"
|
||||||
import { Card } from "../../components/ui/card"
|
import { Card } from "../../components/ui/card"
|
||||||
|
|
@ -129,7 +131,7 @@ export function CreateQuestionTypeFlow() {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
setCatalogError("Failed to load component catalog.")
|
setCatalogError("Failed to load component catalog.")
|
||||||
toast.error("Failed to load component catalog")
|
notifyApiError(e, "Failed to load component catalog")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) setCatalogLoading(false)
|
if (!cancelled) setCatalogLoading(false)
|
||||||
|
|
@ -165,7 +167,7 @@ export function CreateQuestionTypeFlow() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load definition")
|
notifyApiError(e, "Failed to load definition")
|
||||||
navigate("/new-content/question-types")
|
navigate("/new-content/question-types")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -276,9 +278,7 @@ export function CreateQuestionTypeFlow() {
|
||||||
navigate(`/new-content/question-types?updated=${id}`)
|
navigate(`/new-content/question-types?updated=${id}`)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string; error?: string } } }
|
const err = e as { response?: { data?: { message?: string; error?: string } } }
|
||||||
toast.error(String(err.response?.data?.message || "Save failed"), {
|
notifyApiError(err, "Save failed")
|
||||||
description: err.response?.data?.error ? String(err.response.data.error) : undefined,
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -326,9 +326,7 @@ export function CreateQuestionTypeFlow() {
|
||||||
navigate(`/new-content/question-types?created=${id}`)
|
navigate(`/new-content/question-types?created=${id}`)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string; error?: string } } }
|
const err = e as { response?: { data?: { message?: string; error?: string } } }
|
||||||
toast.error(String(err.response?.data?.message || "Save failed"), {
|
notifyApiError(err, "Save failed")
|
||||||
description: err.response?.data?.error ? String(err.response.data.error) : undefined,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,13 +347,11 @@ export function CreateQuestionTypeFlow() {
|
||||||
<div className=" border-b border-grayScale-100 sticky top-0 z-50 bg-white/95 backdrop-blur">
|
<div className=" border-b border-grayScale-100 sticky top-0 z-50 bg-white/95 backdrop-blur">
|
||||||
<div className="max-w-[1440px] mx-auto py-6 px-4 sm:px-6">
|
<div className="max-w-[1440px] mx-auto py-6 px-4 sm:px-6">
|
||||||
<div className="flex items-center justify-between mb-8">
|
<div className="flex items-center justify-between mb-8">
|
||||||
<Link
|
<PageBackLink
|
||||||
to="/new-content/question-types"
|
fallbackTo="/new-content/question-types"
|
||||||
className="flex items-center gap-2 text-[15px] font-medium text-grayScale-600 transition-colors hover:text-brand-500 group"
|
label="Back to Question Type Library"
|
||||||
>
|
iconClassName="h-5 w-5 group-hover:-translate-x-1"
|
||||||
<ArrowLeft className="h-5 w-5 transition-transform group-hover:-translate-x-1" />
|
/>
|
||||||
Back to Question Type Library
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col lg:flex-row lg:items-start lg:justify-between gap-6">
|
<div className="flex flex-col lg:flex-row lg:items-start lg:justify-between gap-6">
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
|
import { getApiErrorMessage, notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import {
|
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
||||||
Link,
|
import { Loader2 } from "lucide-react";
|
||||||
useNavigate,
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
useParams,
|
import { navigateBack } from "../../lib/navigateBack";
|
||||||
useSearchParams,
|
|
||||||
} from "react-router-dom";
|
|
||||||
import { ArrowLeft, Loader2 } from "lucide-react";
|
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { Stepper } from "../../components/ui/stepper";
|
import { Stepper } from "../../components/ui/stepper";
|
||||||
import successIcon from "../../assets/success.svg";
|
|
||||||
import type { QuestionTypeDefinition } from "../../types/questionTypeDefinition.types";
|
import type { QuestionTypeDefinition } from "../../types/questionTypeDefinition.types";
|
||||||
import {
|
import {
|
||||||
getExamPrepPracticeFull,
|
getExamPrepPracticeFull,
|
||||||
|
|
@ -17,7 +14,6 @@ import {
|
||||||
} from "../../api/courses.api";
|
} from "../../api/courses.api";
|
||||||
import { getQuestionTypeDefinitions } from "../../api/questionTypeDefinitions.api";
|
import { getQuestionTypeDefinitions } from "../../api/questionTypeDefinitions.api";
|
||||||
import {
|
import {
|
||||||
learnEnglishPracticeApiErrorMessage,
|
|
||||||
validateLearnEnglishQuestionsWithDefinitions,
|
validateLearnEnglishQuestionsWithDefinitions,
|
||||||
} from "../../lib/learnEnglishPracticePublish";
|
} from "../../lib/learnEnglishPracticePublish";
|
||||||
import { executePracticeUpdate } from "../../lib/practiceEditOrchestrator";
|
import { executePracticeUpdate } from "../../lib/practiceEditOrchestrator";
|
||||||
|
|
@ -37,6 +33,10 @@ import {
|
||||||
unwrapPracticeFullData,
|
unwrapPracticeFullData,
|
||||||
type PreservedQuestionSetFields,
|
type PreservedQuestionSetFields,
|
||||||
} from "../../lib/practiceFullMapper";
|
} from "../../lib/practiceFullMapper";
|
||||||
|
import {
|
||||||
|
buildPracticeEditSnapshot,
|
||||||
|
hasPracticeEditChanges,
|
||||||
|
} from "../../lib/practiceEditDirty";
|
||||||
|
|
||||||
import { ContextStep } from "./components/practice-steps/ContextStep";
|
import { ContextStep } from "./components/practice-steps/ContextStep";
|
||||||
import { ScenarioStep } from "./components/practice-steps/ScenarioStep";
|
import { ScenarioStep } from "./components/practice-steps/ScenarioStep";
|
||||||
|
|
@ -221,13 +221,15 @@ export function EditPracticeFlow() {
|
||||||
level,
|
level,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const goBack = () => navigateBack(navigate, backPath);
|
||||||
|
|
||||||
const [currentStep, setCurrentStep] = useState(1);
|
const [currentStep, setCurrentStep] = useState(1);
|
||||||
const [isSaved, setIsSaved] = useState(false);
|
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [loadingPractice, setLoadingPractice] = useState(true);
|
const [loadingPractice, setLoadingPractice] = useState(true);
|
||||||
const [loadError, setLoadError] = useState<string | null>(null);
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
|
|
||||||
const [selectedPersona, setSelectedPersona] = useState<string | null>(null);
|
const [selectedPersona, setSelectedPersona] = useState<string | null>(null);
|
||||||
|
const [loadedPersonaId, setLoadedPersonaId] = useState<number | null>(null);
|
||||||
const [preservedQuestionSet, setPreservedQuestionSet] =
|
const [preservedQuestionSet, setPreservedQuestionSet] =
|
||||||
useState<PreservedQuestionSetFields>({
|
useState<PreservedQuestionSetFields>({
|
||||||
timeLimitMinutes: null,
|
timeLimitMinutes: null,
|
||||||
|
|
@ -241,7 +243,7 @@ export function EditPracticeFlow() {
|
||||||
loading: personasLoading,
|
loading: personasLoading,
|
||||||
error: personasError,
|
error: personasError,
|
||||||
reload: reloadPersonas,
|
reload: reloadPersonas,
|
||||||
} = useActivePersonas();
|
} = useActivePersonas({ ensurePersonaId: loadedPersonaId });
|
||||||
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
title: "",
|
title: "",
|
||||||
|
|
@ -282,6 +284,7 @@ export function EditPracticeFlow() {
|
||||||
);
|
);
|
||||||
const [definitionsLoading, setDefinitionsLoading] = useState(true);
|
const [definitionsLoading, setDefinitionsLoading] = useState(true);
|
||||||
const [definitionsError, setDefinitionsError] = useState<string | null>(null);
|
const [definitionsError, setDefinitionsError] = useState<string | null>(null);
|
||||||
|
const [initialSnapshot, setInitialSnapshot] = useState<string | null>(null);
|
||||||
const initialParentsRef = useRef<PracticeParent[]>([]);
|
const initialParentsRef = useRef<PracticeParent[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -297,7 +300,7 @@ export function EditPracticeFlow() {
|
||||||
if (!cancelled) setTypeDefinitions(list);
|
if (!cancelled) setTypeDefinitions(list);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
setDefinitionsError(learnEnglishPracticeApiErrorMessage(e));
|
setDefinitionsError(getApiErrorMessage(e, "Failed to load question type definitions"));
|
||||||
setTypeDefinitions([]);
|
setTypeDefinitions([]);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -323,15 +326,23 @@ export function EditPracticeFlow() {
|
||||||
if (!full) throw new Error("Practice details were missing from the response.");
|
if (!full) throw new Error("Practice details were missing from the response.");
|
||||||
const mapped = mapPracticeFullToFormState(full, typeDefinitions);
|
const mapped = mapPracticeFullToFormState(full, typeDefinitions);
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
|
const loadedPersona =
|
||||||
|
mapped.personaId != null ? String(mapped.personaId) : null;
|
||||||
setFormData(mapped.formData);
|
setFormData(mapped.formData);
|
||||||
setPreservedQuestionSet(mapped.preservedQuestionSet);
|
setPreservedQuestionSet(mapped.preservedQuestionSet);
|
||||||
initialParentsRef.current = mapped.parents;
|
initialParentsRef.current = mapped.parents;
|
||||||
if (mapped.personaId != null) {
|
setLoadedPersonaId(mapped.personaId);
|
||||||
setSelectedPersona(String(mapped.personaId));
|
setSelectedPersona(loadedPersona);
|
||||||
}
|
setInitialSnapshot(
|
||||||
|
buildPracticeEditSnapshot({
|
||||||
|
formData: mapped.formData,
|
||||||
|
selectedPersona: loadedPersona,
|
||||||
|
preservedQuestionSet: mapped.preservedQuestionSet,
|
||||||
|
}),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
setLoadError(learnEnglishPracticeApiErrorMessage(e));
|
setLoadError(getApiErrorMessage(e, "Failed to load practice"));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) setLoadingPractice(false);
|
if (!cancelled) setLoadingPractice(false);
|
||||||
|
|
@ -342,6 +353,23 @@ export function EditPracticeFlow() {
|
||||||
};
|
};
|
||||||
}, [validPracticeId, practiceId, isExamPrep, typeDefinitions, definitionsLoading]);
|
}, [validPracticeId, practiceId, isExamPrep, typeDefinitions, definitionsLoading]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (loadedPersonaId == null || personasLoading) return;
|
||||||
|
const idStr = String(loadedPersonaId);
|
||||||
|
if (!personas.some((persona) => persona.id === idStr)) return;
|
||||||
|
setSelectedPersona((current) => (current === idStr ? current : idStr));
|
||||||
|
}, [loadedPersonaId, personas, personasLoading]);
|
||||||
|
|
||||||
|
const hasUnsavedChanges = useMemo(
|
||||||
|
() =>
|
||||||
|
hasPracticeEditChanges(initialSnapshot, {
|
||||||
|
formData,
|
||||||
|
selectedPersona,
|
||||||
|
preservedQuestionSet,
|
||||||
|
}),
|
||||||
|
[initialSnapshot, formData, selectedPersona, preservedQuestionSet],
|
||||||
|
);
|
||||||
|
|
||||||
const submitPractice = async (status: "DRAFT" | "PUBLISHED") => {
|
const submitPractice = async (status: "DRAFT" | "PUBLISHED") => {
|
||||||
if (!validPracticeId) {
|
if (!validPracticeId) {
|
||||||
toast.error("Invalid practice", { description: "Missing practice id in the URL." });
|
toast.error("Invalid practice", { description: "Missing practice id in the URL." });
|
||||||
|
|
@ -448,15 +476,14 @@ export function EditPracticeFlow() {
|
||||||
initialParentsRef.current,
|
initialParentsRef.current,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
initialParentsRef.current = dedupeParents(formData.parents);
|
||||||
|
setPreservedQuestionSet((prev) => ({ ...prev, status }));
|
||||||
toast.success(
|
toast.success(
|
||||||
status === "PUBLISHED" ? "Practice updated and published" : "Practice saved as draft",
|
status === "PUBLISHED" ? "Practice updated and published" : "Practice saved as draft",
|
||||||
);
|
);
|
||||||
initialParentsRef.current = dedupeParents(formData.parents);
|
navigate(backPath);
|
||||||
setIsSaved(true);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error("Could not update practice", {
|
notifyApiError(e, "Could not update practice");
|
||||||
description: learnEnglishPracticeApiErrorMessage(e),
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|
@ -466,11 +493,16 @@ export function EditPracticeFlow() {
|
||||||
setCurrentStep((prev) => Math.min(prev + 1, STEP_LABELS.length));
|
setCurrentStep((prev) => Math.min(prev + 1, STEP_LABELS.length));
|
||||||
const prevStep = () => setCurrentStep((prev) => Math.max(prev - 1, 1));
|
const prevStep = () => setCurrentStep((prev) => Math.max(prev - 1, 1));
|
||||||
|
|
||||||
|
const saveStatus: "DRAFT" | "PUBLISHED" =
|
||||||
|
preservedQuestionSet.status === "DRAFT" ? "DRAFT" : "PUBLISHED";
|
||||||
|
|
||||||
|
const handleSaveChanges = () => void submitPractice(saveStatus);
|
||||||
|
|
||||||
if (!validPracticeId) {
|
if (!validPracticeId) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen flex-col items-center justify-center px-6 text-center">
|
<div className="flex min-h-screen flex-col items-center justify-center px-6 text-center">
|
||||||
<p className="text-lg font-semibold text-grayScale-800">Invalid practice link</p>
|
<p className="text-lg font-semibold text-grayScale-800">Invalid practice link</p>
|
||||||
<Button className="mt-6" variant="outline" onClick={() => navigate(-1)}>
|
<Button className="mt-6" variant="outline" onClick={goBack}>
|
||||||
Go back
|
Go back
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -492,7 +524,7 @@ export function EditPracticeFlow() {
|
||||||
<p className="text-lg font-semibold text-grayScale-800">Could not load practice</p>
|
<p className="text-lg font-semibold text-grayScale-800">Could not load practice</p>
|
||||||
<p className="mt-2 max-w-md text-sm text-grayScale-600">{loadError}</p>
|
<p className="mt-2 max-w-md text-sm text-grayScale-600">{loadError}</p>
|
||||||
<div className="mt-6 flex gap-3">
|
<div className="mt-6 flex gap-3">
|
||||||
<Button variant="outline" onClick={() => navigate(backPath)}>
|
<Button variant="outline" onClick={() => goBack()}>
|
||||||
{backLabel}
|
{backLabel}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={() => window.location.reload()}>Try again</Button>
|
<Button onClick={() => window.location.reload()}>Try again</Button>
|
||||||
|
|
@ -501,33 +533,6 @@ export function EditPracticeFlow() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSaved) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center justify-center min-h-screen px-4 text-center pb-20 animate-in fade-in zoom-in duration-500">
|
|
||||||
<div className="mb-10 relative">
|
|
||||||
<div className="absolute inset-0 bg-brand-500/10 blur-3xl rounded-full" />
|
|
||||||
<img
|
|
||||||
src={successIcon}
|
|
||||||
alt="Success"
|
|
||||||
className="h-[128px] w-[128px] relative"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<h1 className="text-[28px] font-bold text-grayScale-900 mb-2">
|
|
||||||
Practice Updated Successfully!
|
|
||||||
</h1>
|
|
||||||
<p className="text-grayScale-600 text-md mb-14 max-w-lg font-medium leading-relaxed">
|
|
||||||
Your changes to this practice have been saved.
|
|
||||||
</p>
|
|
||||||
<Button
|
|
||||||
onClick={() => navigate(backPath)}
|
|
||||||
className="h-14 rounded-[6px] bg-[#9E2891] font-bold shadow-xl shadow-brand-500/20 text-[16px] text-white w-full max-w-[400px]"
|
|
||||||
>
|
|
||||||
{backLabel}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const reviewParentSummary =
|
const reviewParentSummary =
|
||||||
formData.parents.length > 0
|
formData.parents.length > 0
|
||||||
? formatPracticeParentsSummary(formData.parents, { isExamPrep })
|
? formatPracticeParentsSummary(formData.parents, { isExamPrep })
|
||||||
|
|
@ -548,7 +553,7 @@ export function EditPracticeFlow() {
|
||||||
formData={formData}
|
formData={formData}
|
||||||
setFormData={setFormData}
|
setFormData={setFormData}
|
||||||
nextStep={nextStep}
|
nextStep={nextStep}
|
||||||
onCancel={() => navigate(backPath)}
|
onCancel={() => goBack()}
|
||||||
isLessonPractice={isLearnEnglishLessonPractice}
|
isLessonPractice={isLearnEnglishLessonPractice}
|
||||||
lessonTitle={lessonTitleDisplay}
|
lessonTitle={lessonTitleDisplay}
|
||||||
parentSummary={reviewParentSummary}
|
parentSummary={reviewParentSummary}
|
||||||
|
|
@ -558,8 +563,15 @@ export function EditPracticeFlow() {
|
||||||
parentsCollapsedDefault={isExamPrep}
|
parentsCollapsedDefault={isExamPrep}
|
||||||
practiceId={practiceId}
|
practiceId={practiceId}
|
||||||
onParentsUnlinked={(parents) => {
|
onParentsUnlinked={(parents) => {
|
||||||
setFormData((fd) => ({ ...fd, parents }))
|
setFormData((fd) => ({ ...fd, parents }));
|
||||||
initialParentsRef.current = parents
|
initialParentsRef.current = parents;
|
||||||
|
setInitialSnapshot(
|
||||||
|
buildPracticeEditSnapshot({
|
||||||
|
formData: { ...formData, parents },
|
||||||
|
selectedPersona,
|
||||||
|
preservedQuestionSet,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
@ -685,26 +697,37 @@ export function EditPracticeFlow() {
|
||||||
<div className="space-y-8 px-6 pb-16 pt-6">
|
<div className="space-y-8 px-6 pb-16 pt-6">
|
||||||
<div className="mx-auto max-w-7xl w-full">
|
<div className="mx-auto max-w-7xl w-full">
|
||||||
<div className="flex items-center justify-between mb-8">
|
<div className="flex items-center justify-between mb-8">
|
||||||
<Link
|
<PageBackLink fallbackTo={backPath} label={backLabel} />
|
||||||
to={backPath}
|
|
||||||
className="flex items-center gap-2 text-[15px] font-medium text-grayScale-600 transition-colors hover:text-brand-500 decoration-none"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
{backLabel}
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-10">
|
<div className="mb-10">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between gap-4">
|
||||||
<h1 className="text-3xl font-bold text-[#0F172A]">Edit Practice</h1>
|
<h1 className="text-3xl font-bold text-[#0F172A]">Edit Practice</h1>
|
||||||
|
<div className="flex shrink-0 items-center gap-3">
|
||||||
|
<Button
|
||||||
|
className="h-10 rounded-[8px] bg-brand-500 px-6 font-bold text-white shadow-md shadow-brand-500/20 hover:bg-brand-600 disabled:opacity-50"
|
||||||
|
disabled={submitting || !hasUnsavedChanges}
|
||||||
|
onClick={handleSaveChanges}
|
||||||
|
>
|
||||||
|
{submitting ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
Saving…
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"Save changes"
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="rounded-[8px] border-grayScale-200 text-grayScale-600 h-10 px-6 font-bold bg-white hover:bg-grayScale-50"
|
className="h-10 rounded-[8px] border-grayScale-200 bg-white px-6 font-bold text-grayScale-600 hover:bg-grayScale-50"
|
||||||
onClick={() => navigate(backPath)}
|
disabled={submitting}
|
||||||
|
onClick={() => goBack()}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<p className="text-grayScale-400 text-base">
|
<p className="text-grayScale-400 text-base">
|
||||||
Update story details, persona, and questions for practice #{practiceId}.
|
Update story details, persona, and questions for practice #{practiceId}.
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { type Dispatch, type SetStateAction, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
import { type Dispatch, type SetStateAction, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import { BookOpen, ChevronDown, ChevronRight, FolderTree, Languages, Pencil, Plus, Trash2 } from "lucide-react"
|
import { BookOpen, ChevronDown, ChevronRight, FolderTree, Languages, Pencil, Plus, Trash2 } from "lucide-react"
|
||||||
|
|
@ -10,6 +11,7 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D
|
||||||
import { Input } from "../../components/ui/input"
|
import { Input } from "../../components/ui/input"
|
||||||
import { Select } from "../../components/ui/select"
|
import { Select } from "../../components/ui/select"
|
||||||
import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
import {
|
import {
|
||||||
createModule,
|
createModule,
|
||||||
deleteModule,
|
deleteModule,
|
||||||
|
|
@ -303,7 +305,7 @@ export function HumanLanguageHierarchyPage() {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
setHierarchyRows([])
|
setHierarchyRows([])
|
||||||
setHierarchyError("Could not load Human Language hierarchy")
|
setHierarchyError("Could not load Human Language hierarchy")
|
||||||
toast.error("Failed to load Human Language hierarchy")
|
notifyApiError(err, "Failed to load Human Language hierarchy")
|
||||||
} finally {
|
} finally {
|
||||||
setHierarchyLoading(false)
|
setHierarchyLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -358,7 +360,7 @@ export function HumanLanguageHierarchyPage() {
|
||||||
setCourseRowsByCourseId({})
|
setCourseRowsByCourseId({})
|
||||||
setLevelPracticesByLevelId({})
|
setLevelPracticesByLevelId({})
|
||||||
setCourseHierarchyError("Could not load hierarchy for selected courses")
|
setCourseHierarchyError("Could not load hierarchy for selected courses")
|
||||||
toast.error("Failed to load course hierarchy")
|
notifyApiError(err, "Failed to load course hierarchy")
|
||||||
} finally {
|
} finally {
|
||||||
setCourseHierarchyLoading(false)
|
setCourseHierarchyLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -516,7 +518,7 @@ export function HumanLanguageHierarchyPage() {
|
||||||
await fetchHierarchiesForCourses(refreshCourseIds)
|
await fetchHierarchiesForCourses(refreshCourseIds)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Failed to create module")
|
notifyApiError(error, "Failed to create module")
|
||||||
} finally {
|
} finally {
|
||||||
setCreateModuleSaving(false)
|
setCreateModuleSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -606,7 +608,7 @@ export function HumanLanguageHierarchyPage() {
|
||||||
await fetchHierarchiesForCourses(refreshCourseIds)
|
await fetchHierarchiesForCourses(refreshCourseIds)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Failed to update module")
|
notifyApiError(error, "Failed to update module")
|
||||||
} finally {
|
} finally {
|
||||||
setEditModuleSaving(false)
|
setEditModuleSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -633,7 +635,7 @@ export function HumanLanguageHierarchyPage() {
|
||||||
await fetchHierarchiesForCourses(refreshCourseIds)
|
await fetchHierarchiesForCourses(refreshCourseIds)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Failed to delete module")
|
notifyApiError(error, "Failed to delete module")
|
||||||
} finally {
|
} finally {
|
||||||
setDeleteModuleSavingId(null)
|
setDeleteModuleSavingId(null)
|
||||||
}
|
}
|
||||||
|
|
@ -666,6 +668,7 @@ export function HumanLanguageHierarchyPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto max-w-6xl space-y-6">
|
<div className="mx-auto max-w-6xl space-y-6">
|
||||||
|
<PageBackLink fallbackTo="/content" label="Back to Content Management" />
|
||||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-brand-50 text-brand-700 ring-1 ring-inset ring-brand-100">
|
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-brand-50 text-brand-700 ring-1 ring-inset ring-brand-100">
|
||||||
|
|
@ -676,9 +679,6 @@ export function HumanLanguageHierarchyPage() {
|
||||||
<p className="text-sm text-grayScale-500">Hierarchy management</p>
|
<p className="text-sm text-grayScale-500">Hierarchy management</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button type="button" variant="outline" asChild>
|
|
||||||
<Link to="/content">Back to Content Management</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AdminFiltersPanel
|
<AdminFiltersPanel
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { Link, useLocation, useNavigate, useParams } from "react-router-dom"
|
import { Link, useLocation, useNavigate, useParams } from "react-router-dom"
|
||||||
import { ArrowLeft, BookOpen, Eye, FileText, Plus, Search, Trophy, Video } from "lucide-react"
|
import { ArrowLeft, BookOpen, Eye, FileText, Plus, Search, Trophy, Video } from "lucide-react"
|
||||||
|
|
@ -184,7 +185,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
setMetaError("Failed to load sub-module")
|
setMetaError("Failed to load sub-module")
|
||||||
setSubCourse(null)
|
setSubCourse(null)
|
||||||
toast.error("Failed to load sub-module")
|
notifyApiError(e, "Failed to load sub-module")
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingMeta(false)
|
setLoadingMeta(false)
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +203,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
setSets(list)
|
setSets(list)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load question sets")
|
notifyApiError(e, "Failed to load question sets")
|
||||||
setSets([])
|
setSets([])
|
||||||
} finally {
|
} finally {
|
||||||
setSetsLoading(false)
|
setSetsLoading(false)
|
||||||
|
|
@ -217,7 +218,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
setVideos(res.data?.data?.videos ?? [])
|
setVideos(res.data?.data?.videos ?? [])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load videos")
|
notifyApiError(e, "Failed to load videos")
|
||||||
setVideos([])
|
setVideos([])
|
||||||
} finally {
|
} finally {
|
||||||
setVideosLoading(false)
|
setVideosLoading(false)
|
||||||
|
|
@ -233,7 +234,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
setLessons(list)
|
setLessons(list)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load lessons")
|
notifyApiError(e, "Failed to load lessons")
|
||||||
setLessons([])
|
setLessons([])
|
||||||
} finally {
|
} finally {
|
||||||
setLessonsLoading(false)
|
setLessonsLoading(false)
|
||||||
|
|
@ -250,7 +251,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
setLessonDetail(res.data?.data ?? null)
|
setLessonDetail(res.data?.data ?? null)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load lesson detail")
|
notifyApiError(e, "Failed to load lesson detail")
|
||||||
} finally {
|
} finally {
|
||||||
setLessonDetailLoading(false)
|
setLessonDetailLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -298,7 +299,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
await fetchLessons()
|
await fetchLessons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Failed to update lesson")
|
notifyApiError(error, "Failed to update lesson")
|
||||||
} finally {
|
} finally {
|
||||||
setLessonUpdateSaving(false)
|
setLessonUpdateSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -317,7 +318,7 @@ export function HumanLanguageSubModulePage() {
|
||||||
await fetchLessons()
|
await fetchLessons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Failed to soft delete lesson")
|
notifyApiError(error, "Failed to soft delete lesson")
|
||||||
} finally {
|
} finally {
|
||||||
setLessonSoftDeleteSaving(false)
|
setLessonSoftDeleteSaving(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Plus, ArrowRight, Pencil, Trash2, X } from "lucide-react";
|
import { Plus, ArrowRight, Pencil, Trash2, X } from "lucide-react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Card, CardContent } from "../../components/ui/card";
|
import { Card, CardContent } from "../../components/ui/card";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
|
|
@ -147,10 +149,7 @@ export function LearnEnglishPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload thumbnail");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -198,10 +197,7 @@ export function LearnEnglishPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload thumbnail");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreateUploadingThumbnail(false);
|
setCreateUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -238,10 +234,7 @@ export function LearnEnglishPage() {
|
||||||
await fetchPrograms();
|
await fetchPrograms();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to create program");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create program";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreateSaving(false);
|
setCreateSaving(false);
|
||||||
}
|
}
|
||||||
|
|
@ -277,10 +270,7 @@ export function LearnEnglishPage() {
|
||||||
await fetchPrograms();
|
await fetchPrograms();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update program");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update program";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingEdit(false);
|
setSavingEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -304,10 +294,7 @@ export function LearnEnglishPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Program published" : "Program saved as draft",
|
nextStatus === "PUBLISHED" ? "Program published" : "Program saved as draft",
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to update program status");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update program status";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null);
|
setPublishStatusUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -329,10 +316,7 @@ export function LearnEnglishPage() {
|
||||||
nextTier === "PREMIUM" ? "Program set to Premium" : "Program set to Free",
|
nextTier === "PREMIUM" ? "Program set to Premium" : "Program set to Free",
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to update program access tier");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update program access tier";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierUpdatingId(null);
|
setAccessTierUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -348,10 +332,7 @@ export function LearnEnglishPage() {
|
||||||
await fetchPrograms();
|
await fetchPrograms();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to delete program");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete program";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false);
|
setDeleting(false);
|
||||||
}
|
}
|
||||||
|
|
@ -401,9 +382,7 @@ export function LearnEnglishPage() {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setError("Failed to load programs");
|
setError("Failed to load programs");
|
||||||
setPrograms([]);
|
setPrograms([]);
|
||||||
toast.error("Could not load programs", {
|
notifyApiError(e, "Could not load programs");
|
||||||
description: "Check your connection or try again.",
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -415,6 +394,7 @@ export function LearnEnglishPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
|
<PageBackLink fallbackTo="/new-content" label="Back to Content Management" />
|
||||||
{/* Header section */}
|
{/* Header section */}
|
||||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import {
|
import {
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
|
|
@ -344,7 +345,7 @@ export function LessonPracticesPage() {
|
||||||
setPractices([]);
|
setPractices([]);
|
||||||
setTotalCount(0);
|
setTotalCount(0);
|
||||||
setLoadError("Could not load practices for this lesson.");
|
setLoadError("Could not load practices for this lesson.");
|
||||||
toast.error("Failed to load practices");
|
notifyApiError(err, "Failed to load practices");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -420,7 +421,7 @@ export function LessonPracticesPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } };
|
const err = e as { response?: { data?: { message?: string } } };
|
||||||
toast.error(err.response?.data?.message || "Failed to update practice status");
|
notifyApiError(err, "Failed to update practice status");
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null);
|
setPublishStatusUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -450,9 +451,7 @@ export function LessonPracticesPage() {
|
||||||
await load();
|
await load();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast.error("Could not remove from lesson", {
|
notifyApiError(err, "Could not remove from lesson");
|
||||||
description: mapPracticeParentUnlinkError(e),
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setUnlinking(false);
|
setUnlinking(false);
|
||||||
}
|
}
|
||||||
|
|
@ -468,7 +467,7 @@ export function LessonPracticesPage() {
|
||||||
await load();
|
await load();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } };
|
const err = e as { response?: { data?: { message?: string } } };
|
||||||
toast.error(err.response?.data?.message || "Failed to delete practice");
|
notifyApiError(err, "Failed to delete practice");
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false);
|
setDeleting(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useMemo, useState } from "react"
|
import { useMemo, useState } from "react"
|
||||||
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom"
|
import { useNavigate, useParams, useSearchParams } from "react-router-dom"
|
||||||
import { ArrowLeft, Link2 } from "lucide-react"
|
import { Link2 } from "lucide-react"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
|
import { navigateBack } from "../../lib/navigateBack"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Button } from "../../components/ui/button"
|
import { Button } from "../../components/ui/button"
|
||||||
import { Stepper } from "../../components/ui/stepper"
|
import { Stepper } from "../../components/ui/stepper"
|
||||||
import successIcon from "../../assets/success.svg"
|
import successIcon from "../../assets/success.svg"
|
||||||
import type { ParentContextPractice, PracticeParentKind } from "../../types/course.types"
|
import type { ParentContextPractice, PracticeParentKind } from "../../types/course.types"
|
||||||
import { attachPracticeToParent } from "../../lib/attachPracticeToParent"
|
import { attachPracticeToParent } from "../../lib/attachPracticeToParent"
|
||||||
import { learnEnglishPracticeApiErrorMessage } from "../../lib/learnEnglishPracticePublish"
|
|
||||||
import { formatPracticeParentLabel } from "../../lib/practiceParents"
|
import { formatPracticeParentLabel } from "../../lib/practiceParents"
|
||||||
import type { PracticeParentTitleHints } from "../../lib/practiceParentTitles"
|
import type { PracticeParentTitleHints } from "../../lib/practiceParentTitles"
|
||||||
import { LinkExistingPracticeReviewStep } from "./components/practice-steps/LinkExistingPracticeReviewStep"
|
import { LinkExistingPracticeReviewStep } from "./components/practice-steps/LinkExistingPracticeReviewStep"
|
||||||
|
|
@ -170,6 +172,8 @@ export function LinkExistingPracticeFlow() {
|
||||||
level,
|
level,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const goBack = () => navigateBack(navigate, backPath)
|
||||||
|
|
||||||
const parentTitleHints = useMemo((): PracticeParentTitleHints => {
|
const parentTitleHints = useMemo((): PracticeParentTitleHints => {
|
||||||
const hints: PracticeParentTitleHints = {}
|
const hints: PracticeParentTitleHints = {}
|
||||||
const lid = lessonId ? Number(lessonId) : NaN
|
const lid = lessonId ? Number(lessonId) : NaN
|
||||||
|
|
@ -198,7 +202,7 @@ export function LinkExistingPracticeFlow() {
|
||||||
<Button
|
<Button
|
||||||
className="mt-6 rounded-[6px]"
|
className="mt-6 rounded-[6px]"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
>
|
>
|
||||||
{backLabel}
|
{backLabel}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
@ -215,9 +219,7 @@ export function LinkExistingPracticeFlow() {
|
||||||
toast.success("Practice linked successfully")
|
toast.success("Practice linked successfully")
|
||||||
setIsComplete(true)
|
setIsComplete(true)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error("Could not link practice", {
|
notifyApiError(e, "Could not link practice")
|
||||||
description: learnEnglishPracticeApiErrorMessage(e),
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
@ -240,7 +242,7 @@ export function LinkExistingPracticeFlow() {
|
||||||
is now attached to {targetSummary}.
|
is now attached to {targetSummary}.
|
||||||
</p>
|
</p>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
className="h-14 rounded-[6px] bg-brand-500 px-10 text-[16px] font-bold text-white shadow-xl shadow-brand-500/20"
|
className="h-14 rounded-[6px] bg-brand-500 px-10 text-[16px] font-bold text-white shadow-xl shadow-brand-500/20"
|
||||||
>
|
>
|
||||||
{backLabel}
|
{backLabel}
|
||||||
|
|
@ -253,13 +255,7 @@ export function LinkExistingPracticeFlow() {
|
||||||
<div className="space-y-8 px-6 pb-16 pt-6">
|
<div className="space-y-8 px-6 pb-16 pt-6">
|
||||||
<div className="mx-auto w-full max-w-7xl">
|
<div className="mx-auto w-full max-w-7xl">
|
||||||
<div className="mb-8 flex items-center justify-between">
|
<div className="mb-8 flex items-center justify-between">
|
||||||
<Link
|
<PageBackLink fallbackTo={backPath} label={backLabel} />
|
||||||
to={backPath}
|
|
||||||
className="flex items-center gap-2 text-[15px] font-medium text-grayScale-600 decoration-none transition-colors hover:text-brand-500"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
{backLabel}
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-10">
|
<div className="mb-10">
|
||||||
|
|
@ -268,7 +264,7 @@ export function LinkExistingPracticeFlow() {
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="h-10 rounded-[8px] border-grayScale-200 bg-white px-6 font-bold text-grayScale-600 hover:bg-grayScale-50"
|
className="h-10 rounded-[8px] border-grayScale-200 bg-white px-6 font-bold text-grayScale-600 hover:bg-grayScale-50"
|
||||||
onClick={() => navigate(backPath)}
|
onClick={goBack}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
@ -304,7 +300,7 @@ export function LinkExistingPracticeFlow() {
|
||||||
selectedPracticeId={selectedPractice?.id ?? null}
|
selectedPracticeId={selectedPractice?.id ?? null}
|
||||||
onSelect={setSelectedPractice}
|
onSelect={setSelectedPractice}
|
||||||
nextStep={() => setCurrentStep(2)}
|
nextStep={() => setCurrentStep(2)}
|
||||||
onCancel={() => navigate(backPath)}
|
onCancel={goBack}
|
||||||
/>
|
/>
|
||||||
) : selectedPractice ? (
|
) : selectedPractice ? (
|
||||||
<LinkExistingPracticeReviewStep
|
<LinkExistingPracticeReviewStep
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { ArrowLeft, Video, Calendar, Trash2, X } from "lucide-react";
|
import { ArrowLeft, Video, Calendar, Trash2, X } from "lucide-react";
|
||||||
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
|
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
@ -246,7 +247,7 @@ export function ModuleDetailPage() {
|
||||||
setLessons([]);
|
setLessons([]);
|
||||||
setLessonsLoadError("Failed to load lessons. Please try again.");
|
setLessonsLoadError("Failed to load lessons. Please try again.");
|
||||||
} else {
|
} else {
|
||||||
toast.error("Failed to refresh lessons");
|
notifyApiError(err, "Failed to refresh lessons");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (showPageLoading) {
|
if (showPageLoading) {
|
||||||
|
|
@ -337,7 +338,7 @@ export function ModuleDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } };
|
const err = e as { response?: { data?: { message?: string } } };
|
||||||
toast.error(err.response?.data?.message || "Failed to update practice status");
|
notifyApiError(err, "Failed to update practice status");
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusPracticeId(null);
|
setPublishStatusPracticeId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -368,9 +369,7 @@ export function ModuleDetailPage() {
|
||||||
await loadModulePractices();
|
await loadModulePractices();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast.error("Could not remove from module", {
|
notifyApiError(err, "Could not remove from module");
|
||||||
description: mapPracticeParentUnlinkError(e),
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setUnlinkingPractice(false);
|
setUnlinkingPractice(false);
|
||||||
}
|
}
|
||||||
|
|
@ -421,10 +420,7 @@ export function ModuleDetailPage() {
|
||||||
await loadModuleLessons({ showPageLoading: false });
|
await loadModuleLessons({ showPageLoading: false });
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update lesson");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update lesson";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingLessonEdit(false);
|
setSavingLessonEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -451,13 +447,10 @@ export function ModuleDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
e,
|
||||||
?.message ??
|
nextStatus === "PUBLISHED" ? "Failed to publish lesson" : "Failed to save lesson as draft",
|
||||||
(nextStatus === "PUBLISHED"
|
);
|
||||||
? "Failed to publish lesson"
|
|
||||||
: "Failed to save lesson as draft");
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusLessonId(null);
|
setPublishStatusLessonId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -482,10 +475,7 @@ export function ModuleDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update lesson access tier");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update lesson access tier";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierLessonId(null);
|
setAccessTierLessonId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -501,10 +491,7 @@ export function ModuleDetailPage() {
|
||||||
await loadModuleLessons({ showPageLoading: false });
|
await loadModuleLessons({ showPageLoading: false });
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to delete lesson");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete lesson";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingLessonInFlight(false);
|
setDeletingLessonInFlight(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getApiErrorMessage, notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
import { BookOpen, GraduationCap, Layers, PlayCircle, RefreshCw, Pencil, Search, Trash2 } from "lucide-react"
|
import { BookOpen, GraduationCap, Layers, PlayCircle, RefreshCw, Pencil, Search, Trash2 } from "lucide-react"
|
||||||
import { useSearchParams } from "react-router-dom"
|
import { useSearchParams } from "react-router-dom"
|
||||||
|
|
@ -39,6 +40,7 @@ import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
||||||
import { CreatePracticeWizard } from "./components/CreatePracticeWizard"
|
import { CreatePracticeWizard } from "./components/CreatePracticeWizard"
|
||||||
import type { PracticeParentKind } from "../../types/course.types"
|
import type { PracticeParentKind } from "../../types/course.types"
|
||||||
import { cn } from "../../lib/utils"
|
import { cn } from "../../lib/utils"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
|
|
||||||
type ParentTab = "course" | "module" | "lesson"
|
type ParentTab = "course" | "module" | "lesson"
|
||||||
|
|
||||||
|
|
@ -336,7 +338,7 @@ export function PracticeDetailsPage() {
|
||||||
setPractice(list[0] ?? null)
|
setPractice(list[0] ?? null)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
setLoadError(err.response?.data?.message || "Failed to load practices for this parent.")
|
setLoadError(getApiErrorMessage(err, "Failed to load practices for this parent."))
|
||||||
setPractice(null)
|
setPractice(null)
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -609,7 +611,7 @@ export function PracticeDetailsPage() {
|
||||||
setEditOpen(false)
|
setEditOpen(false)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(err.response?.data?.message || "Failed to update practice")
|
notifyApiError(err, "Failed to update practice")
|
||||||
} finally {
|
} finally {
|
||||||
setSavePracticeLoading(false)
|
setSavePracticeLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -632,7 +634,7 @@ export function PracticeDetailsPage() {
|
||||||
}
|
}
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(err.response?.data?.message || "Failed to delete practice")
|
notifyApiError(err, "Failed to delete practice")
|
||||||
} finally {
|
} finally {
|
||||||
setDeletePracticeLoading(false)
|
setDeletePracticeLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -658,6 +660,7 @@ export function PracticeDetailsPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
<PageBackLink fallbackTo="/content" label="Back" />
|
||||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold tracking-tight text-grayScale-600">Practice Management</h1>
|
<h1 className="text-2xl font-bold tracking-tight text-grayScale-600">Practice Management</h1>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Plus } from "lucide-react"
|
import { Plus } from "lucide-react"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
import { Button } from "../../components/ui/button"
|
import { Button } from "../../components/ui/button"
|
||||||
import { Card } from "../../components/ui/card"
|
import { Card } from "../../components/ui/card"
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "../../components/ui/avatar"
|
import { Avatar, AvatarFallback, AvatarImage } from "../../components/ui/avatar"
|
||||||
|
|
@ -29,6 +30,7 @@ export function PracticeMembersPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
|
<PageBackLink fallbackTo="/content/practices" label="Back to Practice Management" />
|
||||||
{/* Page Header */}
|
{/* Page Header */}
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold tracking-tight text-grayScale-600">Practice Management</h1>
|
<h1 className="text-2xl font-bold tracking-tight text-grayScale-600">Practice Management</h1>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { ArrowLeft, Plus, Pencil, Trash2, X } from "lucide-react";
|
import { Plus, Pencil, Trash2, X } from "lucide-react";
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Card, CardContent } from "../../components/ui/card";
|
import { Card, CardContent } from "../../components/ui/card";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
|
|
@ -121,10 +123,7 @@ export function ProgramCoursesPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Course published" : "Course saved as draft",
|
nextStatus === "PUBLISHED" ? "Course published" : "Course saved as draft",
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to update course status");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course status";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null);
|
setPublishStatusUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -146,10 +145,7 @@ export function ProgramCoursesPage() {
|
||||||
nextTier === "PREMIUM" ? "Course set to Premium" : "Course set to Free",
|
nextTier === "PREMIUM" ? "Course set to Premium" : "Course set to Free",
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to update course access tier");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course access tier";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierUpdatingId(null);
|
setAccessTierUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -187,9 +183,7 @@ export function ProgramCoursesPage() {
|
||||||
setError("Failed to load courses");
|
setError("Failed to load courses");
|
||||||
setCourses([]);
|
setCourses([]);
|
||||||
setProgram(null);
|
setProgram(null);
|
||||||
toast.error("Could not load courses", {
|
notifyApiError(e, "Could not load courses");
|
||||||
description: "Check your connection or try again.",
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -209,10 +203,7 @@ export function ProgramCoursesPage() {
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to delete course");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete course";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false);
|
setDeleting(false);
|
||||||
}
|
}
|
||||||
|
|
@ -266,10 +257,7 @@ export function ProgramCoursesPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload thumbnail");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -305,10 +293,7 @@ export function ProgramCoursesPage() {
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to update course");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingEdit(false);
|
setSavingEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -357,10 +342,7 @@ export function ProgramCoursesPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload thumbnail");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreateUploadingThumbnail(false);
|
setCreateUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -397,10 +379,7 @@ export function ProgramCoursesPage() {
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to create course");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create course";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreateSaving(false);
|
setCreateSaving(false);
|
||||||
}
|
}
|
||||||
|
|
@ -418,13 +397,7 @@ export function ProgramCoursesPage() {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8 pt-10">
|
<div className="space-y-8 pt-10">
|
||||||
{/* Navigation */}
|
{/* Navigation */}
|
||||||
<Link
|
<PageBackLink fallbackTo="/new-content/learn-english" label="Back to Programs" className="text-sm text-grayScale-500" />
|
||||||
to="/new-content/learn-english"
|
|
||||||
className="flex items-center gap-2 text-sm font-medium text-grayScale-500 transition-colors hover:text-brand-500"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
Back to Programs
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
{/* Header section */}
|
{/* Header section */}
|
||||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Link, useParams, useNavigate } from "react-router-dom";
|
import { Link, useParams, useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
|
|
@ -127,7 +128,7 @@ export function ProgramDetailPage() {
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Failed to fetch catalog courses");
|
notifyApiError(error, "Failed to fetch catalog courses");
|
||||||
setCreatedCourses([]);
|
setCreatedCourses([]);
|
||||||
} finally {
|
} finally {
|
||||||
setCatalogLoading(false);
|
setCatalogLoading(false);
|
||||||
|
|
@ -190,10 +191,7 @@ export function ProgramDetailPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Course published" : "Course saved as draft",
|
nextStatus === "PUBLISHED" ? "Course published" : "Course saved as draft",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update course status");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course status";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null);
|
setPublishStatusUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -217,10 +215,7 @@ export function ProgramDetailPage() {
|
||||||
nextTier === "PREMIUM" ? "Course set to Premium" : "Course set to Free",
|
nextTier === "PREMIUM" ? "Course set to Premium" : "Course set to Free",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update course access tier");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course access tier";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierUpdatingId(null);
|
setAccessTierUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -257,10 +252,7 @@ export function ProgramDetailPage() {
|
||||||
toast.success("Thumbnail URL uploaded to MinIO");
|
toast.success("Thumbnail URL uploaded to MinIO");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail URL");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail URL";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -335,10 +327,7 @@ export function ProgramDetailPage() {
|
||||||
setCreateOpen(false);
|
setCreateOpen(false);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to create course");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create course";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreating(false);
|
setCreating(false);
|
||||||
}
|
}
|
||||||
|
|
@ -380,10 +369,7 @@ export function ProgramDetailPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
@ -438,10 +424,7 @@ export function ProgramDetailPage() {
|
||||||
closeEditCourse();
|
closeEditCourse();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to update course");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update course";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingEdit(false);
|
setSavingEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -457,10 +440,7 @@ export function ProgramDetailPage() {
|
||||||
setDeletingCourseId(null);
|
setDeletingCourseId(null);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to delete course");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete course";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingCourse(false);
|
setDeletingCourse(false);
|
||||||
}
|
}
|
||||||
|
|
@ -493,10 +473,7 @@ export function ProgramDetailPage() {
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload thumbnail");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { GraduationCap, Brain } from "lucide-react";
|
import { GraduationCap, Brain } from "lucide-react";
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
|
|
||||||
export function ProgramTypeSelectionPage() {
|
export function ProgramTypeSelectionPage() {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-500">
|
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-500">
|
||||||
|
<PageBackLink fallbackTo="/new-content" label="Back to Content Management" />
|
||||||
{/* Header section */}
|
{/* Header section */}
|
||||||
<div className="space-y-1.5 pt-2">
|
<div className="space-y-1.5 pt-2">
|
||||||
<h1 className="text-[28px] font-bold tracking-tight text-grayScale-900">
|
<h1 className="text-[28px] font-bold tracking-tight text-grayScale-900">
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom"
|
import { Link, useNavigate, useParams } from "react-router-dom"
|
||||||
import {
|
import {
|
||||||
|
|
@ -26,7 +27,6 @@ import { cn } from "../../lib/utils"
|
||||||
import {
|
import {
|
||||||
deleteQuestionTypeDefinitionGroup,
|
deleteQuestionTypeDefinitionGroup,
|
||||||
getQuestionTypeDefinitionGroupById,
|
getQuestionTypeDefinitionGroupById,
|
||||||
groupApiErrorMessage,
|
|
||||||
} from "../../api/questionTypeDefinitionGroups.api"
|
} from "../../api/questionTypeDefinitionGroups.api"
|
||||||
import { assignQuestionTypeDefinitionGroups } from "../../api/questionTypeDefinitions.api"
|
import { assignQuestionTypeDefinitionGroups } from "../../api/questionTypeDefinitions.api"
|
||||||
import { removeGroupFromMembership } from "../../lib/questionTypeGroupIds"
|
import { removeGroupFromMembership } from "../../lib/questionTypeGroupIds"
|
||||||
|
|
@ -67,7 +67,7 @@ export function QuestionTypeGroupDetailPage() {
|
||||||
}
|
}
|
||||||
setGroup(detail)
|
setGroup(detail)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(groupApiErrorMessage(e, "Failed to load group"))
|
notifyApiError(e, "Failed to load group")
|
||||||
setGroup(null)
|
setGroup(null)
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
@ -88,7 +88,7 @@ export function QuestionTypeGroupDetailPage() {
|
||||||
toast.success("Removed from this group")
|
toast.success("Removed from this group")
|
||||||
await load()
|
await load()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(groupApiErrorMessage(e, "Could not remove from group"))
|
notifyApiError(e, "Could not remove from group")
|
||||||
} finally {
|
} finally {
|
||||||
setDetachingId(null)
|
setDetachingId(null)
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ export function QuestionTypeGroupDetailPage() {
|
||||||
toast.success("Group deleted. Membership links for this group were removed.")
|
toast.success("Group deleted. Membership links for this group were removed.")
|
||||||
navigate("/new-content/question-types")
|
navigate("/new-content/question-types")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(groupApiErrorMessage(e, "Delete failed"))
|
notifyApiError(e, "Delete failed")
|
||||||
} finally {
|
} finally {
|
||||||
setDeleteSubmitting(false)
|
setDeleteSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { Link, useNavigate, useSearchParams } from "react-router-dom"
|
import { Link, useNavigate, useSearchParams } from "react-router-dom"
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
|
|
@ -42,13 +42,13 @@ import {
|
||||||
import {
|
import {
|
||||||
deleteQuestionTypeDefinitionGroup,
|
deleteQuestionTypeDefinitionGroup,
|
||||||
getQuestionTypeDefinitionGroups,
|
getQuestionTypeDefinitionGroups,
|
||||||
groupApiErrorMessage,
|
|
||||||
} from "../../api/questionTypeDefinitionGroups.api"
|
} from "../../api/questionTypeDefinitionGroups.api"
|
||||||
import type {
|
import type {
|
||||||
QuestionTypeDefinition,
|
QuestionTypeDefinition,
|
||||||
QuestionTypeDefinitionGroup,
|
QuestionTypeDefinitionGroup,
|
||||||
} from "../../types/questionTypeDefinition.types"
|
} from "../../types/questionTypeDefinition.types"
|
||||||
import { QuestionTypeGroupFormDialog } from "./components/QuestionTypeGroupFormDialog"
|
import { QuestionTypeGroupFormDialog } from "./components/QuestionTypeGroupFormDialog"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
import {
|
import {
|
||||||
definitionBelongsToGroup,
|
definitionBelongsToGroup,
|
||||||
isDefinitionUngrouped,
|
isDefinitionUngrouped,
|
||||||
|
|
@ -115,7 +115,7 @@ export function QuestionTypeLibraryPage() {
|
||||||
setGroups(rows)
|
setGroups(rows)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load question type groups")
|
notifyApiError(e, "Failed to load question type groups")
|
||||||
setGroups([])
|
setGroups([])
|
||||||
} finally {
|
} finally {
|
||||||
setGroupsLoading(false)
|
setGroupsLoading(false)
|
||||||
|
|
@ -134,7 +134,7 @@ export function QuestionTypeLibraryPage() {
|
||||||
setDefinitions(visibleRows)
|
setDefinitions(visibleRows)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load question type definitions")
|
notifyApiError(e, "Failed to load question type definitions")
|
||||||
setDefinitions([])
|
setDefinitions([])
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
@ -231,7 +231,7 @@ export function QuestionTypeLibraryPage() {
|
||||||
if (groupFilter === row.id) setGroupFilter("all")
|
if (groupFilter === row.id) setGroupFilter("all")
|
||||||
await Promise.all([load(), loadGroups()])
|
await Promise.all([load(), loadGroups()])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(groupApiErrorMessage(e, "Delete failed"))
|
notifyApiError(e, "Delete failed")
|
||||||
} finally {
|
} finally {
|
||||||
setGroupDeleteSubmitting(false)
|
setGroupDeleteSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +260,7 @@ export function QuestionTypeLibraryPage() {
|
||||||
void load()
|
void load()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(String(err.response?.data?.message || "Delete failed"))
|
notifyApiError(err, "Delete failed")
|
||||||
} finally {
|
} finally {
|
||||||
setDeleteSubmitting(false)
|
setDeleteSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
@ -269,13 +269,12 @@ export function QuestionTypeLibraryPage() {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8 animate-in fade-in duration-500 pb-20">
|
<div className="space-y-8 animate-in fade-in duration-500 pb-20">
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<Link
|
<PageBackLink
|
||||||
to="/new-content"
|
fallbackTo="/new-content"
|
||||||
className="flex items-center gap-2 text-[15px] font-bold text-grayScale-600 transition-colors hover:text-brand-500 group w-fit"
|
label="Back to Content Management"
|
||||||
>
|
className="font-bold"
|
||||||
<ArrowLeft className="h-5 w-5 transition-transform group-hover:-translate-x-1" />
|
iconClassName="h-5 w-5 group-hover:-translate-x-1"
|
||||||
Back to Content Management
|
/>
|
||||||
</Link>
|
|
||||||
|
|
||||||
<div className="flex items-start justify-between gap-4 flex-wrap">
|
<div className="flex items-start justify-between gap-4 flex-wrap">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import { deleteQuestion, getQuestionById, getQuestions, updateQuestion } from ".
|
||||||
import { countActiveFilters } from "../../lib/adminFilterUtils"
|
import { countActiveFilters } from "../../lib/adminFilterUtils"
|
||||||
import type { QuestionDetail } from "../../types/course.types"
|
import type { QuestionDetail } from "../../types/course.types"
|
||||||
import { cn } from "../../lib/utils"
|
import { cn } from "../../lib/utils"
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink"
|
||||||
import { TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
import { TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
||||||
|
|
||||||
type QuestionTypeFilter = "all" | "MCQ" | "TRUE_FALSE" | "SHORT_ANSWER" | "AUDIO"
|
type QuestionTypeFilter = "all" | "MCQ" | "TRUE_FALSE" | "SHORT_ANSWER" | "AUDIO"
|
||||||
|
|
@ -338,6 +339,7 @@ export function QuestionsPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
|
<PageBackLink fallbackTo="/content" label="Back" />
|
||||||
{/* Page Header */}
|
{/* Page Header */}
|
||||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,11 @@
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import { ArrowLeft } from "lucide-react";
|
|
||||||
import { ContentHierarchyList } from "./components/ContentHierarchyList";
|
import { ContentHierarchyList } from "./components/ContentHierarchyList";
|
||||||
|
import { PageBackLink } from "../../components/navigation/PageBackLink";
|
||||||
|
|
||||||
export function ReorderContentPage() {
|
export function ReorderContentPage() {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8 animate-in fade-in duration-500 pb-20">
|
<div className="space-y-8 animate-in fade-in duration-500 pb-20">
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<Link
|
<PageBackLink fallbackTo="/new-content" label="Back to Content Management" iconClassName="h-5 w-5 group-hover:-translate-x-1" />
|
||||||
to="/new-content"
|
|
||||||
className="flex items-center gap-2 text-[15px] font-bold text-grayScale-600 transition-colors hover:text-brand-500 group w-fit"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-5 w-5 transition-transform group-hover:-translate-x-1" />
|
|
||||||
Back to Content Management
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h1 className="text-2xl font-bold tracking-tight text-grayScale-700">
|
<h1 className="text-2xl font-bold tracking-tight text-grayScale-700">
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { type ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
import { type ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
import { ArrowLeft, ChevronDown, ChevronRight, Image as ImageIcon, Mic, Plus, Trash2, Upload } from "lucide-react"
|
import { ArrowLeft, ChevronDown, ChevronRight, Image as ImageIcon, Mic, Plus, Trash2, Upload } from "lucide-react"
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card"
|
import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card"
|
||||||
|
|
@ -593,7 +594,7 @@ export function SpeakingPage() {
|
||||||
toast.success("Practice created. Continue adding questions.")
|
toast.success("Practice created. Continue adding questions.")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to create speaking practice set:", error)
|
console.error("Failed to create speaking practice set:", error)
|
||||||
toast.error("Failed to create practice set")
|
notifyApiError(error, "Failed to create practice set")
|
||||||
} finally {
|
} finally {
|
||||||
setCreatingSet(false)
|
setCreatingSet(false)
|
||||||
}
|
}
|
||||||
|
|
@ -616,7 +617,7 @@ export function SpeakingPage() {
|
||||||
toast.success("Intro video uploaded", { description: "The URL has been filled in for you." })
|
toast.success("Intro video uploaded", { description: "The URL has been filled in for you." })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload intro video:", error)
|
console.error("Failed to upload intro video:", error)
|
||||||
toast.error("Failed to upload intro video")
|
notifyApiError(error, "Failed to upload intro video")
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingIntroVideo(false)
|
setUploadingIntroVideo(false)
|
||||||
}
|
}
|
||||||
|
|
@ -715,7 +716,7 @@ export function SpeakingPage() {
|
||||||
toast.success("Audio uploaded successfully")
|
toast.success("Audio uploaded successfully")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload audio:", error)
|
console.error("Failed to upload audio:", error)
|
||||||
toast.error("Failed to upload audio file")
|
notifyApiError(error, "Failed to upload audio file")
|
||||||
} finally {
|
} finally {
|
||||||
updateDraft(draftIndex, (draft) =>
|
updateDraft(draftIndex, (draft) =>
|
||||||
field === "voice_prompt"
|
field === "voice_prompt"
|
||||||
|
|
@ -768,7 +769,7 @@ export function SpeakingPage() {
|
||||||
toast.success("Image uploaded successfully")
|
toast.success("Image uploaded successfully")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to upload image:", error)
|
console.error("Failed to upload image:", error)
|
||||||
toast.error("Failed to upload image")
|
notifyApiError(error, "Failed to upload image")
|
||||||
} finally {
|
} finally {
|
||||||
updateDraft(draftIndex, (draft) => ({ ...draft, uploadingImage: false }))
|
updateDraft(draftIndex, (draft) => ({ ...draft, uploadingImage: false }))
|
||||||
event.target.value = ""
|
event.target.value = ""
|
||||||
|
|
@ -839,7 +840,7 @@ export function SpeakingPage() {
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to resolve audio preview URL:", error)
|
console.error("Failed to resolve audio preview URL:", error)
|
||||||
toast.error("Could not import/resolve audio URL")
|
notifyApiError(error, "Could not import/resolve audio URL")
|
||||||
} finally {
|
} finally {
|
||||||
updateDraft(draftIndex, (draft) =>
|
updateDraft(draftIndex, (draft) =>
|
||||||
field === "voice_prompt"
|
field === "voice_prompt"
|
||||||
|
|
@ -861,7 +862,7 @@ export function SpeakingPage() {
|
||||||
updateDraft(draftIndex, (current) => ({ ...current, imagePreviewUrl: resolved }))
|
updateDraft(draftIndex, (current) => ({ ...current, imagePreviewUrl: resolved }))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to resolve image preview URL:", error)
|
console.error("Failed to resolve image preview URL:", error)
|
||||||
toast.error("Could not resolve image preview URL")
|
notifyApiError(error, "Could not resolve image preview URL")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1093,7 +1094,7 @@ export function SpeakingPage() {
|
||||||
await fetchAudioQuestions()
|
await fetchAudioQuestions()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to create speaking practice:", error)
|
console.error("Failed to create speaking practice:", error)
|
||||||
toast.error("Failed to create speaking practice")
|
notifyApiError(error, "Failed to create speaking practice")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -1138,7 +1139,7 @@ export function SpeakingPage() {
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch question detail:", error)
|
console.error("Failed to fetch question detail:", error)
|
||||||
toast.error("Failed to load question detail")
|
notifyApiError(error, "Failed to load question detail")
|
||||||
setDetailOpen(false)
|
setDetailOpen(false)
|
||||||
} finally {
|
} finally {
|
||||||
setDetailLoading(false)
|
setDetailLoading(false)
|
||||||
|
|
@ -1199,7 +1200,7 @@ export function SpeakingPage() {
|
||||||
toast.success("AUDIO question updated")
|
toast.success("AUDIO question updated")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update AUDIO question:", error)
|
console.error("Failed to update AUDIO question:", error)
|
||||||
toast.error("Failed to update AUDIO question")
|
notifyApiError(error, "Failed to update AUDIO question")
|
||||||
} finally {
|
} finally {
|
||||||
setDetailSaving(false)
|
setDetailSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -1219,7 +1220,7 @@ export function SpeakingPage() {
|
||||||
toast.success("AUDIO question deleted")
|
toast.success("AUDIO question deleted")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to delete AUDIO question:", error)
|
console.error("Failed to delete AUDIO question:", error)
|
||||||
toast.error("Failed to delete AUDIO question")
|
notifyApiError(error, "Failed to delete AUDIO question")
|
||||||
} finally {
|
} finally {
|
||||||
setDetailDeleting(false)
|
setDetailDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
@ -1254,7 +1255,7 @@ export function SpeakingPage() {
|
||||||
toast.success(`Deleted ${selectedQuestionIds.length} AUDIO question(s)`)
|
toast.success(`Deleted ${selectedQuestionIds.length} AUDIO question(s)`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to delete selected AUDIO questions:", error)
|
console.error("Failed to delete selected AUDIO questions:", error)
|
||||||
toast.error("Failed to delete selected AUDIO questions")
|
notifyApiError(error, "Failed to delete selected AUDIO questions")
|
||||||
} finally {
|
} finally {
|
||||||
setBulkDeleting(false)
|
setBulkDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Link, useParams, useNavigate } from "react-router-dom";
|
import { Link, useParams, useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
|
|
@ -226,7 +227,7 @@ export function UnitManagementPage() {
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Failed to load modules");
|
notifyApiError(error, "Failed to load modules");
|
||||||
setModules([]);
|
setModules([]);
|
||||||
} finally {
|
} finally {
|
||||||
setModulesLoading(false);
|
setModulesLoading(false);
|
||||||
|
|
@ -253,10 +254,7 @@ export function UnitManagementPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Unit published" : "Unit saved as draft",
|
nextStatus === "PUBLISHED" ? "Unit published" : "Unit saved as draft",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update unit status");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update unit status";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setUnitPublishStatusUpdating(false);
|
setUnitPublishStatusUpdating(false);
|
||||||
}
|
}
|
||||||
|
|
@ -280,10 +278,7 @@ export function UnitManagementPage() {
|
||||||
nextStatus === "PUBLISHED" ? "Module published" : "Module saved as draft",
|
nextStatus === "PUBLISHED" ? "Module published" : "Module saved as draft",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update module status");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module status";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null);
|
setPublishStatusUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -305,10 +300,7 @@ export function UnitManagementPage() {
|
||||||
nextTier === "PREMIUM" ? "Module set to Premium" : "Module set to Free",
|
nextTier === "PREMIUM" ? "Module set to Premium" : "Module set to Free",
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const message =
|
notifyApiError(error, "Failed to update module access tier");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module access tier";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setAccessTierUpdatingId(null);
|
setAccessTierUpdatingId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -355,10 +347,7 @@ export function UnitManagementPage() {
|
||||||
toast.success(`${target === "thumbnail" ? "Thumbnail" : "Icon"} uploaded`);
|
toast.success(`${target === "thumbnail" ? "Thumbnail" : "Icon"} uploaded`);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload image");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload image";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (target === "thumbnail") {
|
if (target === "thumbnail") {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
|
|
@ -391,10 +380,7 @@ export function UnitManagementPage() {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload URL to MinIO");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload URL to MinIO";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (target === "thumbnail") {
|
if (target === "thumbnail") {
|
||||||
setUploadingThumbnail(false);
|
setUploadingThumbnail(false);
|
||||||
|
|
@ -430,10 +416,7 @@ export function UnitManagementPage() {
|
||||||
setAddModuleOpen(false);
|
setAddModuleOpen(false);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to create module");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create module";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setCreating(false);
|
setCreating(false);
|
||||||
}
|
}
|
||||||
|
|
@ -484,10 +467,7 @@ export function UnitManagementPage() {
|
||||||
toast.success(`${target === "thumbnail" ? "Thumbnail" : "Icon"} uploaded`);
|
toast.success(`${target === "thumbnail" ? "Thumbnail" : "Icon"} uploaded`);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload image");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload image";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (target === "thumbnail") {
|
if (target === "thumbnail") {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
|
|
@ -517,10 +497,7 @@ export function UnitManagementPage() {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to upload URL to MinIO");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload URL to MinIO";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (target === "thumbnail") {
|
if (target === "thumbnail") {
|
||||||
setUploadingEditThumbnail(false);
|
setUploadingEditThumbnail(false);
|
||||||
|
|
@ -564,10 +541,7 @@ export function UnitManagementPage() {
|
||||||
closeEditModule();
|
closeEditModule();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to update module");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update module";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSavingEdit(false);
|
setSavingEdit(false);
|
||||||
}
|
}
|
||||||
|
|
@ -583,10 +557,7 @@ export function UnitManagementPage() {
|
||||||
setDeletingModuleId(null);
|
setDeletingModuleId(null);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message =
|
notifyApiError(error, "Failed to delete module");
|
||||||
(error as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete module";
|
|
||||||
toast.error(message);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingModule(false);
|
setDeletingModule(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useEffect, useState, type FormEvent } from "react";
|
import { useEffect, useState, type FormEvent } from "react";
|
||||||
import { Button } from "../../../components/ui/button";
|
import { Button } from "../../../components/ui/button";
|
||||||
import {
|
import {
|
||||||
|
|
@ -97,10 +98,7 @@ export function AddModuleModal({
|
||||||
resetAndClose();
|
resetAndClose();
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
const msg =
|
notifyApiError(err, "Failed to create module");
|
||||||
(err as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create module";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { BookOpen, Loader2, RefreshCw } from "lucide-react"
|
import { BookOpen, Loader2, RefreshCw } from "lucide-react"
|
||||||
|
|
@ -95,7 +96,7 @@ export function CatalogCoursePracticesPanel({
|
||||||
setPractices([])
|
setPractices([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
setLoadError("Could not load practices for this catalog course.")
|
setLoadError("Could not load practices for this catalog course.")
|
||||||
toast.error("Failed to load practices")
|
notifyApiError(err, "Failed to load practices")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +139,7 @@ export function CatalogCoursePracticesPanel({
|
||||||
)
|
)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(err.response?.data?.message || "Failed to update practice status")
|
notifyApiError(err, "Failed to update practice status")
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null)
|
setPublishStatusUpdatingId(null)
|
||||||
}
|
}
|
||||||
|
|
@ -168,9 +169,7 @@ export function CatalogCoursePracticesPanel({
|
||||||
await load()
|
await load()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
toast.error("Could not remove location", {
|
notifyApiError(err, "Could not remove location")
|
||||||
description: mapPracticeParentUnlinkError(e),
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setUnlinking(false)
|
setUnlinking(false)
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +185,7 @@ export function CatalogCoursePracticesPanel({
|
||||||
await load()
|
await load()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(err.response?.data?.message || "Failed to delete practice")
|
notifyApiError(err, "Failed to delete practice")
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import React, { useState, useEffect, useCallback } from "react";
|
import React, { useState, useEffect, useCallback } from "react";
|
||||||
import {
|
import {
|
||||||
DndContext,
|
DndContext,
|
||||||
|
|
@ -439,12 +440,6 @@ export function ContentHierarchyList() {
|
||||||
return arrayMove(siblings, oldIndex, newIndex);
|
return arrayMove(siblings, oldIndex, newIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
const reorderErrorMessage = (error: unknown, fallback: string) => {
|
|
||||||
const message = (error as { response?: { data?: { message?: string } } })
|
|
||||||
?.response?.data?.message;
|
|
||||||
return typeof message === "string" && message.trim() ? message : fallback;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleProgramReorder = async (activeId: string, overId: string) => {
|
const handleProgramReorder = async (activeId: string, overId: string) => {
|
||||||
const reordered = reorderSiblings(programs, activeId, overId);
|
const reordered = reorderSiblings(programs, activeId, overId);
|
||||||
if (!reordered) return;
|
if (!reordered) return;
|
||||||
|
|
@ -456,7 +451,7 @@ export function ContentHierarchyList() {
|
||||||
toast.success("Programs reordered");
|
toast.success("Programs reordered");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setPrograms(previous);
|
setPrograms(previous);
|
||||||
toast.error(reorderErrorMessage(error, "Failed to reorder programs"));
|
notifyApiError(error, "Failed to reorder programs");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -481,7 +476,7 @@ export function ContentHierarchyList() {
|
||||||
toast.success("Courses reordered");
|
toast.success("Courses reordered");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setCourses(previous);
|
setCourses(previous);
|
||||||
toast.error(reorderErrorMessage(error, "Failed to reorder courses"));
|
notifyApiError(error, "Failed to reorder courses");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -506,7 +501,7 @@ export function ContentHierarchyList() {
|
||||||
toast.success("Modules reordered");
|
toast.success("Modules reordered");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setModules(previous);
|
setModules(previous);
|
||||||
toast.error(reorderErrorMessage(error, "Failed to reorder modules"));
|
notifyApiError(error, "Failed to reorder modules");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -531,7 +526,7 @@ export function ContentHierarchyList() {
|
||||||
toast.success("Lessons reordered");
|
toast.success("Lessons reordered");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLessons(previous);
|
setLessons(previous);
|
||||||
toast.error(reorderErrorMessage(error, "Failed to reorder lessons"));
|
notifyApiError(error, "Failed to reorder lessons");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { Check, ChevronLeft, ChevronRight, ListOrdered, Plus, Trash2 } from "lucide-react"
|
import { Check, ChevronLeft, ChevronRight, ListOrdered, Plus, Trash2 } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
@ -106,7 +107,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
||||||
setStep(2)
|
setStep(2)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
||||||
toast.error(err.response?.data?.message || err.message || "Failed to create question set")
|
notifyApiError(err, "Failed to create question set")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +153,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
||||||
setStep(3)
|
setStep(3)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
||||||
toast.error(err.response?.data?.message || err.message || "Failed to create questions")
|
notifyApiError(err, "Failed to create questions")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +173,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
||||||
setStep(4)
|
setStep(4)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
||||||
toast.error(err.response?.data?.message || err.message || "Failed to attach questions")
|
notifyApiError(err, "Failed to attach questions")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +206,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
||||||
onCreated?.()
|
onCreated?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
const err = e as { response?: { data?: { message?: string } }; message?: string }
|
||||||
toast.error(err.response?.data?.message || err.message || "Failed to create practice")
|
notifyApiError(err, "Failed to create practice")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
setPendingSaveStatus(null)
|
setPendingSaveStatus(null)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useRef, useState, type ChangeEvent, type DragEvent } from "react";
|
import { useCallback, useRef, useState, type ChangeEvent, type DragEvent } from "react";
|
||||||
import { CloudUpload } from "lucide-react";
|
import { CloudUpload } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
@ -78,10 +79,7 @@ export function LessonMediaUploadField({
|
||||||
toast.success("Thumbnail uploaded");
|
toast.success("Thumbnail uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload thumbnail");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload thumbnail";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
@ -107,10 +105,7 @@ export function LessonMediaUploadField({
|
||||||
toast.success("Video uploaded");
|
toast.success("Video uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload video");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload video";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useRef, useState, type ChangeEvent, type DragEvent } from "react";
|
import { useCallback, useRef, useState, type ChangeEvent, type DragEvent } from "react";
|
||||||
import { CloudUpload } from "lucide-react";
|
import { CloudUpload } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
@ -66,10 +67,7 @@ export function ModuleIconUploadField({
|
||||||
toast.success("Icon uploaded");
|
toast.success("Icon uploaded");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const msg =
|
notifyApiError(e, "Failed to upload icon");
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to upload icon";
|
|
||||||
toast.error(msg);
|
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { Loader2 } from "lucide-react"
|
import { Loader2 } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
getPracticesByParentCourse,
|
getPracticesByParentCourse,
|
||||||
getPracticesByParentModule,
|
getPracticesByParentModule,
|
||||||
|
|
@ -97,10 +98,7 @@ export function PublishPracticeButton({
|
||||||
await loadPractices()
|
await loadPractices()
|
||||||
onPublished?.()
|
onPublished?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to publish practice")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to publish practice"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setActing(false)
|
setActing(false)
|
||||||
}
|
}
|
||||||
|
|
@ -133,10 +131,7 @@ export function PublishPracticeButton({
|
||||||
await loadPractices()
|
await loadPractices()
|
||||||
onPublished?.()
|
onPublished?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
notifyApiError(e, "Failed to save practice as draft")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to save practice as draft"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setActing(false)
|
setActing(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { ChevronDown, ChevronLeft, ChevronRight, GraduationCap, Pencil, Plus } from "lucide-react"
|
import { ChevronDown, ChevronLeft, ChevronRight, GraduationCap, Pencil, Plus } from "lucide-react"
|
||||||
|
|
@ -69,7 +70,7 @@ export function QuestionTypeDefinitionPracticesDialog({
|
||||||
setTotalCount(result.total_count)
|
setTotalCount(result.total_count)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to load practices for this definition")
|
notifyApiError(e, "Failed to load practices for this definition")
|
||||||
setPractices([])
|
setPractices([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -103,19 +104,14 @@ export function QuestionTypeDefinitionPracticesDialog({
|
||||||
try {
|
try {
|
||||||
const path = await resolveQuestionTypeDefinitionPracticeEditPath(practice)
|
const path = await resolveQuestionTypeDefinitionPracticeEditPath(practice)
|
||||||
if (!path) {
|
if (!path) {
|
||||||
toast.error("Could not open practice editor", {
|
notifyApiError(e, "Could not open practice editor")
|
||||||
description:
|
|
||||||
practice.practice_kind === "EXAM_PREP"
|
|
||||||
? "This exam-prep practice could not be linked to its catalog context."
|
|
||||||
: "This practice could not be linked to its course context.",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
navigate(path)
|
navigate(path)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error("Failed to open practice editor")
|
notifyApiError(e, "Failed to open practice editor")
|
||||||
} finally {
|
} finally {
|
||||||
setEditingPracticeId(null)
|
setEditingPracticeId(null)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Button } from "../../../components/ui/button"
|
import { Button } from "../../../components/ui/button"
|
||||||
|
|
@ -16,7 +17,6 @@ import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
||||||
import {
|
import {
|
||||||
createQuestionTypeDefinitionGroup,
|
createQuestionTypeDefinitionGroup,
|
||||||
extractGroupMutationId,
|
extractGroupMutationId,
|
||||||
groupApiErrorMessage,
|
|
||||||
updateQuestionTypeDefinitionGroup,
|
updateQuestionTypeDefinitionGroup,
|
||||||
} from "../../../api/questionTypeDefinitionGroups.api"
|
} from "../../../api/questionTypeDefinitionGroups.api"
|
||||||
import type {
|
import type {
|
||||||
|
|
@ -97,7 +97,7 @@ export function QuestionTypeGroupFormDialog({
|
||||||
}
|
}
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(groupApiErrorMessage(e, isEdit ? "Update failed" : "Create failed"))
|
notifyApiError(e, isEdit ? "Update failed" : "Create failed")
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { BookOpen, Loader2, RefreshCw } from "lucide-react"
|
import { BookOpen, Loader2, RefreshCw } from "lucide-react"
|
||||||
|
|
@ -97,7 +98,7 @@ export function UnitPracticesPanel({
|
||||||
setPractices([])
|
setPractices([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
setLoadError("Could not load practices for this unit.")
|
setLoadError("Could not load practices for this unit.")
|
||||||
toast.error("Failed to load practices")
|
notifyApiError(err, "Failed to load practices")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +141,7 @@ export function UnitPracticesPanel({
|
||||||
)
|
)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(err.response?.data?.message || "Failed to update practice status")
|
notifyApiError(err, "Failed to update practice status")
|
||||||
} finally {
|
} finally {
|
||||||
setPublishStatusUpdatingId(null)
|
setPublishStatusUpdatingId(null)
|
||||||
}
|
}
|
||||||
|
|
@ -170,9 +171,7 @@ export function UnitPracticesPanel({
|
||||||
await load()
|
await load()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
toast.error("Could not remove location", {
|
notifyApiError(err, "Could not remove location")
|
||||||
description: mapPracticeParentUnlinkError(e),
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setUnlinking(false)
|
setUnlinking(false)
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +187,7 @@ export function UnitPracticesPanel({
|
||||||
await load()
|
await load()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string } } }
|
const err = e as { response?: { data?: { message?: string } } }
|
||||||
toast.error(err.response?.data?.message || "Failed to delete practice")
|
notifyApiError(err, "Failed to delete practice")
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../../lib/apiErrors"
|
||||||
import { useRef, useState, type ChangeEvent } from "react";
|
import { useRef, useState, type ChangeEvent } from "react";
|
||||||
import { ArrowRight, ChevronDown, ChevronUp, Loader2, Upload } from "lucide-react";
|
import { ArrowRight, ChevronDown, ChevronUp, Loader2, Upload } from "lucide-react";
|
||||||
import { Button } from "../../../../components/ui/button";
|
import { Button } from "../../../../components/ui/button";
|
||||||
|
|
@ -75,7 +76,7 @@ export function ContextStep({
|
||||||
setFormData({ ...formData, storyImageUrl: url });
|
setFormData({ ...formData, storyImageUrl: url });
|
||||||
toast.success("Story image uploaded");
|
toast.success("Story image uploaded");
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Could not upload story image");
|
notifyApiError(err, "Could not upload story image");
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingStory(false);
|
setUploadingStory(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
import { Check, ArrowRight, Loader2 } from "lucide-react";
|
import { Check, ArrowRight, Loader2 } from "lucide-react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { Button } from "../../../../components/ui/button";
|
import { Button } from "../../../../components/ui/button";
|
||||||
import {
|
import { PersonaAvatar } from "../../../../components/personas/PersonaAvatar";
|
||||||
Avatar,
|
|
||||||
AvatarFallback,
|
|
||||||
AvatarImage,
|
|
||||||
} from "../../../../components/ui/avatar";
|
|
||||||
import { cn } from "../../../../lib/utils";
|
import { cn } from "../../../../lib/utils";
|
||||||
import type { PersonaCardModel } from "../../../../lib/personaDisplay";
|
import type { PersonaCardModel } from "../../../../lib/personaDisplay";
|
||||||
|
|
||||||
|
|
@ -96,19 +92,12 @@ export function PersonaStep({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-col items-center gap-4">
|
<div className="flex flex-col items-center gap-4">
|
||||||
<div
|
<PersonaAvatar
|
||||||
className={cn(
|
src={persona.avatar}
|
||||||
"rounded-full p-[3px] transition-all duration-300",
|
alt={persona.name}
|
||||||
isSelected ? "bg-brand-500" : "bg-transparent",
|
size="xl"
|
||||||
)}
|
selected={isSelected}
|
||||||
>
|
/>
|
||||||
<Avatar className="h-24 w-24 border-2 border-white">
|
|
||||||
<AvatarImage src={persona.avatar} alt={persona.name} />
|
|
||||||
<AvatarFallback>
|
|
||||||
{persona.name.substring(0, 2).toUpperCase()}
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1 text-center">
|
<div className="space-y-1 text-center">
|
||||||
<span className="block text-lg font-bold text-grayScale-700">
|
<span className="block text-lg font-bold text-grayScale-700">
|
||||||
{persona.name}
|
{persona.name}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
import { useState } from "react"
|
import { notifyApiError } from "../../../../lib/apiErrors"
|
||||||
|
import { useMemo, useState } from "react"
|
||||||
import { Loader2, Plus, Trash2 } from "lucide-react"
|
import { Loader2, Plus, Trash2 } from "lucide-react"
|
||||||
|
import { usePracticeParentTitles } from "../../../../hooks/usePracticeParentTitles"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Button } from "../../../../components/ui/button"
|
import { Button } from "../../../../components/ui/button"
|
||||||
import { Input } from "../../../../components/ui/input"
|
import { Input } from "../../../../components/ui/input"
|
||||||
import type { PracticeParent, PracticeParentKind } from "../../../../types/course.types"
|
import type { PracticeParent, PracticeParentKind } from "../../../../types/course.types"
|
||||||
import {
|
import {
|
||||||
dedupeParents,
|
dedupeParents,
|
||||||
formatPracticeParentLabel,
|
|
||||||
isPracticeParentKind,
|
isPracticeParentKind,
|
||||||
newParentRow,
|
newParentRow,
|
||||||
parentsFromPractice,
|
parentsFromPractice,
|
||||||
} from "../../../../lib/practiceParents"
|
} from "../../../../lib/practiceParents"
|
||||||
|
import { formatPracticeParentDisplayLabel } from "../../../../lib/practiceParentTitles"
|
||||||
import {
|
import {
|
||||||
isPracticeParentUnlinkNotLinkedError,
|
isPracticeParentUnlinkNotLinkedError,
|
||||||
mapPracticeParentUnlinkError,
|
mapPracticeParentUnlinkError,
|
||||||
|
|
@ -62,6 +64,11 @@ export function PracticeParentsField({
|
||||||
}: PracticeParentsFieldProps) {
|
}: PracticeParentsFieldProps) {
|
||||||
const kindOptions = isExamPrep ? EXAM_PREP_KIND_OPTIONS : LMS_KIND_OPTIONS
|
const kindOptions = isExamPrep ? EXAM_PREP_KIND_OPTIONS : LMS_KIND_OPTIONS
|
||||||
const rows = parents.length > 0 ? parents : [newParentRow(isExamPrep ? "CATALOG_COURSE" : "LESSON")]
|
const rows = parents.length > 0 ? parents : [newParentRow(isExamPrep ? "CATALOG_COURSE" : "LESSON")]
|
||||||
|
const savedParents = useMemo(
|
||||||
|
() => dedupeParents(parents.filter((parent) => parent.parent_id > 0)),
|
||||||
|
[parents],
|
||||||
|
)
|
||||||
|
const { titles, loading: titlesLoading } = usePracticeParentTitles(savedParents)
|
||||||
const [unlinkingKey, setUnlinkingKey] = useState<string | null>(null)
|
const [unlinkingKey, setUnlinkingKey] = useState<string | null>(null)
|
||||||
const canPersistUnlink =
|
const canPersistUnlink =
|
||||||
practiceId != null && Number.isFinite(practiceId) && practiceId > 0
|
practiceId != null && Number.isFinite(practiceId) && practiceId > 0
|
||||||
|
|
@ -88,7 +95,7 @@ export function PracticeParentsField({
|
||||||
|
|
||||||
const hasSavedParent = row.parent_id > 0 && isPracticeParentKind(row.parent_kind)
|
const hasSavedParent = row.parent_id > 0 && isPracticeParentKind(row.parent_kind)
|
||||||
if (canPersistUnlink && hasSavedParent) {
|
if (canPersistUnlink && hasSavedParent) {
|
||||||
const label = formatPracticeParentLabel(row)
|
const label = formatPracticeParentDisplayLabel(row, titles)
|
||||||
const remaining = parentsFromPractice({ parents }).filter(
|
const remaining = parentsFromPractice({ parents }).filter(
|
||||||
(p) => parentKey(p) !== parentKey(row),
|
(p) => parentKey(p) !== parentKey(row),
|
||||||
)
|
)
|
||||||
|
|
@ -125,9 +132,7 @@ export function PracticeParentsField({
|
||||||
toast.info("This location was already removed.")
|
toast.info("This location was already removed.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
toast.error("Could not remove location", {
|
notifyApiError(err, "Could not remove location")
|
||||||
description: mapPracticeParentUnlinkError(err),
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setUnlinkingKey(null)
|
setUnlinkingKey(null)
|
||||||
}
|
}
|
||||||
|
|
@ -163,11 +168,21 @@ export function PracticeParentsField({
|
||||||
const key = parentKey(row)
|
const key = parentKey(row)
|
||||||
const isLocked = Boolean(lockedParentKey && key === lockedParentKey && row.parent_id > 0)
|
const isLocked = Boolean(lockedParentKey && key === lockedParentKey && row.parent_id > 0)
|
||||||
const isUnlinking = unlinkingKey === key
|
const isUnlinking = unlinkingKey === key
|
||||||
|
const isSavedLocation = row.parent_id > 0 && isPracticeParentKind(row.parent_kind)
|
||||||
|
const locationLabel = isSavedLocation
|
||||||
|
? formatPracticeParentDisplayLabel(row, titles)
|
||||||
|
: null
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
key={`${index}-${row.parent_kind}`}
|
key={`${index}-${row.parent_kind}`}
|
||||||
className="flex flex-wrap items-center gap-2 rounded-xl border border-grayScale-200 bg-grayScale-50/50 px-3 py-2.5"
|
className="flex flex-wrap items-center gap-2 rounded-xl border border-grayScale-200 bg-grayScale-50/50 px-3 py-2.5"
|
||||||
>
|
>
|
||||||
|
{isSavedLocation ? (
|
||||||
|
<span className="min-w-0 flex-1 text-sm font-medium text-grayScale-800">
|
||||||
|
{titlesLoading ? "Loading location…" : locationLabel}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<select
|
<select
|
||||||
value={row.parent_kind}
|
value={row.parent_kind}
|
||||||
disabled={disabled || isLocked || isUnlinking}
|
disabled={disabled || isLocked || isUnlinking}
|
||||||
|
|
@ -196,6 +211,8 @@ export function PracticeParentsField({
|
||||||
<span className="text-xs text-grayScale-400 hidden sm:inline">
|
<span className="text-xs text-grayScale-400 hidden sm:inline">
|
||||||
{row.parent_kind} parent id from the content hierarchy
|
{row.parent_kind} parent id from the content hierarchy
|
||||||
</span>
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Edit, Info, Loader2, Play, Rocket } from "lucide-react";
|
import { Edit, Info, Loader2, Play, Rocket } from "lucide-react";
|
||||||
|
import { PersonaAvatar } from "../../../../components/personas/PersonaAvatar";
|
||||||
import { Button } from "../../../../components/ui/button";
|
import { Button } from "../../../../components/ui/button";
|
||||||
import { Card } from "../../../../components/ui/card";
|
import { Card } from "../../../../components/ui/card";
|
||||||
import { cn } from "../../../../lib/utils";
|
import { cn } from "../../../../lib/utils";
|
||||||
|
|
@ -221,11 +222,7 @@ export function PracticeSequentialReview({
|
||||||
className="h-full w-full object-cover"
|
className="h-full w-full object-cover"
|
||||||
/>
|
/>
|
||||||
) : persona?.avatar ? (
|
) : persona?.avatar ? (
|
||||||
<img
|
<PersonaAvatar src={persona.avatar} alt={persona.name} size="md" />
|
||||||
src={persona.avatar}
|
|
||||||
alt=""
|
|
||||||
className="h-full w-full object-cover"
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<div className="flex h-full w-full items-center justify-center bg-gradient-to-br from-[#E0F2FE] to-[#BFDBFE]" />
|
<div className="flex h-full w-full items-center justify-center bg-gradient-to-br from-[#E0F2FE] to-[#BFDBFE]" />
|
||||||
)}
|
)}
|
||||||
|
|
@ -260,13 +257,7 @@ export function PracticeSequentialReview({
|
||||||
</span>
|
</span>
|
||||||
{persona ? (
|
{persona ? (
|
||||||
<div className="flex flex-col items-center gap-1.5">
|
<div className="flex flex-col items-center gap-1.5">
|
||||||
<div className="h-12 w-12 overflow-hidden rounded-full bg-grayScale-100 ring-2 ring-brand-100">
|
<PersonaAvatar src={persona.avatar} alt={persona.name} size="md" />
|
||||||
<img
|
|
||||||
src={persona.avatar}
|
|
||||||
alt=""
|
|
||||||
className="h-full w-full object-cover"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<span className="text-sm font-semibold text-grayScale-900">
|
<span className="text-sm font-semibold text-grayScale-900">
|
||||||
{persona.name}
|
{persona.name}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../../lib/apiErrors"
|
||||||
import { useRef, useState, type ChangeEvent } from "react";
|
import { useRef, useState, type ChangeEvent } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { Upload, ArrowRight, Loader2 } from "lucide-react";
|
import { Upload, ArrowRight, Loader2 } from "lucide-react";
|
||||||
|
|
@ -35,7 +36,7 @@ export function ScenarioStep({
|
||||||
setFormData({ ...formData, storyImageUrl: url });
|
setFormData({ ...formData, storyImageUrl: url });
|
||||||
toast.success("Story image uploaded");
|
toast.success("Story image uploaded");
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Could not upload image");
|
notifyApiError(err, "Could not upload image");
|
||||||
} finally {
|
} finally {
|
||||||
setUploadingBanner(false);
|
setUploadingBanner(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { ArrowRight, ChevronLeft, ChevronRight, Search } from "lucide-react"
|
import { ArrowRight, ChevronLeft, ChevronRight, Search } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
@ -7,7 +8,6 @@ import { Input } from "../../../../components/ui/input"
|
||||||
import { SpinnerIcon } from "../../../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../../../components/ui/spinner-icon"
|
||||||
import { practiceAlreadyLinkedToParent } from "../../../../lib/attachPracticeToParent"
|
import { practiceAlreadyLinkedToParent } from "../../../../lib/attachPracticeToParent"
|
||||||
import { fetchAllPractices } from "../../../../lib/fetchAllPractices"
|
import { fetchAllPractices } from "../../../../lib/fetchAllPractices"
|
||||||
import { learnEnglishPracticeApiErrorMessage } from "../../../../lib/learnEnglishPracticePublish"
|
|
||||||
import { formatPracticeParentsSummary } from "../../../../lib/practiceParents"
|
import { formatPracticeParentsSummary } from "../../../../lib/practiceParents"
|
||||||
import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../../../lib/tablePagination"
|
import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../../../lib/tablePagination"
|
||||||
import type { ParentContextPractice, PracticeParent } from "../../../../types/course.types"
|
import type { ParentContextPractice, PracticeParent } from "../../../../types/course.types"
|
||||||
|
|
@ -74,9 +74,7 @@ export function SelectPracticeToAttachStep({
|
||||||
const practices = await fetchAllPractices(unlinkedOnly, { isExamPrep })
|
const practices = await fetchAllPractices(unlinkedOnly, { isExamPrep })
|
||||||
setAllPractices(practices)
|
setAllPractices(practices)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error("Could not load practices", {
|
notifyApiError(e, "Could not load practices")
|
||||||
description: learnEnglishPracticeApiErrorMessage(e),
|
|
||||||
})
|
|
||||||
setAllPractices([])
|
setAllPractices([])
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { useEffect, useState } from "react"
|
||||||
import { ArrowLeft, Loader2 } from "lucide-react"
|
import { ArrowLeft, Loader2 } from "lucide-react"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../../../lib/apiErrors"
|
||||||
import { Button } from "../../../../components/ui/button"
|
import { Button } from "../../../../components/ui/button"
|
||||||
import { Card } from "../../../../components/ui/card"
|
import { Card } from "../../../../components/ui/card"
|
||||||
import {
|
import {
|
||||||
|
|
@ -94,12 +95,7 @@ export function QuestionTypeReviewPublishStep({
|
||||||
})
|
})
|
||||||
navigate(`/new-content/question-types?created=${id}`)
|
navigate(`/new-content/question-types?created=${id}`)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { message?: string; error?: string } } }
|
notifyApiError(e, isEdit ? "Update failed" : "Create failed")
|
||||||
const msg =
|
|
||||||
err.response?.data?.message ||
|
|
||||||
(e instanceof Error ? e.message : isEdit ? "Update failed" : "Create failed")
|
|
||||||
const detail = err.response?.data?.error
|
|
||||||
toast.error(String(msg), { description: detail ? String(detail) : undefined })
|
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/ca
|
||||||
import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
||||||
import { useFaqPermissions } from "../../hooks/useFaqPermissions"
|
import { useFaqPermissions } from "../../hooks/useFaqPermissions"
|
||||||
import { deriveFaqCategories } from "../../lib/faqDisplay"
|
import { deriveFaqCategories } from "../../lib/faqDisplay"
|
||||||
import { getFaqApiErrorMessage, isFaqForbiddenError } from "../../lib/faqErrors"
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
|
import { isFaqForbiddenError } from "../../lib/faqErrors"
|
||||||
import type { FAQ, FAQStatus } from "../../types/faq.types"
|
import type { FAQ, FAQStatus } from "../../types/faq.types"
|
||||||
import { FaqAccessDenied } from "./components/FaqAccessDenied"
|
import { FaqAccessDenied } from "./components/FaqAccessDenied"
|
||||||
import {
|
import {
|
||||||
|
|
@ -79,10 +80,10 @@ export function EditFaqPage() {
|
||||||
}
|
}
|
||||||
if (isFaqForbiddenError(e)) {
|
if (isFaqForbiddenError(e)) {
|
||||||
setPermissionDenied(true)
|
setPermissionDenied(true)
|
||||||
toast.error(getFaqApiErrorMessage(e, "You do not have permission to view this FAQ"))
|
notifyApiError(e, "You do not have permission to view this FAQ")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
toast.error(getFaqApiErrorMessage(e, "Failed to load FAQ"))
|
notifyApiError(e, "Failed to load FAQ")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +122,7 @@ export function EditFaqPage() {
|
||||||
)
|
)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error(getFaqApiErrorMessage(e, "Failed to update FAQ"))
|
notifyApiError(e, "Failed to update FAQ")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
setSavingAction(null)
|
setSavingAction(null)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@ import {
|
||||||
formatFaqDate,
|
formatFaqDate,
|
||||||
suggestNextDisplayOrder,
|
suggestNextDisplayOrder,
|
||||||
} from "../../lib/faqDisplay"
|
} from "../../lib/faqDisplay"
|
||||||
import { getFaqApiErrorMessage, isFaqForbiddenError } from "../../lib/faqErrors"
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
|
import { isFaqForbiddenError } from "../../lib/faqErrors"
|
||||||
import { countActiveFilters } from "../../lib/adminFilterUtils"
|
import { countActiveFilters } from "../../lib/adminFilterUtils"
|
||||||
import { fetchAllOffsetPages } from "../../lib/fetchAllOffsetPages"
|
import { fetchAllOffsetPages } from "../../lib/fetchAllOffsetPages"
|
||||||
import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
||||||
|
|
@ -103,9 +104,9 @@ export function FaqsPage() {
|
||||||
setFaqs([])
|
setFaqs([])
|
||||||
if (isFaqForbiddenError(e)) {
|
if (isFaqForbiddenError(e)) {
|
||||||
setPermissionDenied(true)
|
setPermissionDenied(true)
|
||||||
toast.error(getFaqApiErrorMessage(e, "You do not have permission to view FAQs"))
|
notifyApiError(e, "You do not have permission to view FAQs")
|
||||||
} else {
|
} else {
|
||||||
toast.error(getFaqApiErrorMessage(e, "Failed to load FAQs"))
|
notifyApiError(e, "Failed to load FAQs")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
@ -168,8 +169,7 @@ export function FaqsPage() {
|
||||||
)
|
)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg = getFaqApiErrorMessage(e, "Failed to update FAQ status")
|
notifyApiError(e, "Failed to update FAQ status")
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setTogglingId(null)
|
setTogglingId(null)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "../../../components/ui/dialog"
|
} from "../../../components/ui/dialog"
|
||||||
import { getFaqApiErrorMessage } from "../../../lib/faqErrors"
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
draftToCreatePayload,
|
draftToCreatePayload,
|
||||||
EMPTY_FAQ_FORM_DRAFT,
|
EMPTY_FAQ_FORM_DRAFT,
|
||||||
|
|
@ -75,7 +75,7 @@ export function CreateFaqDialog({
|
||||||
onCreated?.()
|
onCreated?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error(getFaqApiErrorMessage(e, "Failed to create FAQ"))
|
notifyApiError(e, "Failed to create FAQ")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
setSavingAction(null)
|
setSavingAction(null)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { Button } from "../../../components/ui/button"
|
||||||
import { Card, CardContent } from "../../../components/ui/card"
|
import { Card, CardContent } from "../../../components/ui/card"
|
||||||
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
||||||
import { getSessionTeamRole, hasFaqRoleBypass } from "../../../lib/faqPermissions"
|
import { getSessionTeamRole, hasFaqRoleBypass } from "../../../lib/faqPermissions"
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { FAQ_FORBIDDEN_MESSAGE } from "../../../lib/faqErrors"
|
import { FAQ_FORBIDDEN_MESSAGE } from "../../../lib/faqErrors"
|
||||||
|
|
||||||
type FaqAccessDeniedProps = {
|
type FaqAccessDeniedProps = {
|
||||||
|
|
@ -25,10 +26,7 @@ export function FaqAccessDenied({ apiForbidden = false }: FaqAccessDeniedProps)
|
||||||
toast.success(res.data?.message ?? "RBAC permissions synced. Please sign in again.")
|
toast.success(res.data?.message ?? "RBAC permissions synced. Please sign in again.")
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg =
|
notifyApiError(e, "Failed to sync RBAC permissions")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data?.message ??
|
|
||||||
"Failed to sync RBAC permissions"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setSyncing(false)
|
setSyncing(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Trash2 } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { deleteFAQ } from "../../../api/faq.api"
|
import { deleteFAQ } from "../../../api/faq.api"
|
||||||
import { Button } from "../../../components/ui/button"
|
import { Button } from "../../../components/ui/button"
|
||||||
import { getFaqApiErrorMessage } from "../../../lib/faqErrors"
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
|
|
@ -44,8 +44,7 @@ export function FaqDeleteDialog({
|
||||||
onDeleted?.()
|
onDeleted?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg = getFaqApiErrorMessage(e, "Failed to delete FAQ")
|
notifyApiError(e, "Failed to delete FAQ")
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { Eye } from "lucide-react"
|
import { Eye } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
@ -36,7 +37,7 @@ export function FaqPublicPreviewDialog({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
setFaqs([])
|
setFaqs([])
|
||||||
toast.error("Failed to load public FAQ preview")
|
notifyApiError(e, "Failed to load public FAQ preview")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import { Bell, List, RefreshCw } from "lucide-react"
|
import { Bell, List, RefreshCw } from "lucide-react"
|
||||||
|
|
@ -132,7 +133,7 @@ export function AllNotificationsPage() {
|
||||||
setError(true)
|
setError(true)
|
||||||
setRows([])
|
setRows([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
toast.error("Failed to load notifications")
|
notifyApiError(err, "Failed to load notifications")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +193,7 @@ export function AllNotificationsPage() {
|
||||||
setSelectedNotification(notification)
|
setSelectedNotification(notification)
|
||||||
} else {
|
} else {
|
||||||
setDetailError(true)
|
setDetailError(true)
|
||||||
toast.error("Failed to load notification details")
|
notifyApiError(err, "Failed to load notification details")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setDetailLoading(false)
|
setDetailLoading(false)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { useMemo, useState } from "react"
|
||||||
import { Link, useNavigate } from "react-router-dom"
|
import { Link, useNavigate } from "react-router-dom"
|
||||||
import { ArrowLeft } from "lucide-react"
|
import { ArrowLeft } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
createEmailTemplate,
|
createEmailTemplate,
|
||||||
parseEmailTemplateResponse,
|
parseEmailTemplateResponse,
|
||||||
|
|
@ -94,10 +95,7 @@ export function CreateEmailTemplatePage() {
|
||||||
navigate(`/notifications/email-templates/${created.slug}`)
|
navigate(`/notifications/email-templates/${created.slug}`)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg =
|
notifyApiError(e, "Failed to create email template")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to create email template"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { Link, useNavigate } from "react-router-dom"
|
import { Link, useNavigate } from "react-router-dom"
|
||||||
import { Bell, CalendarClock, Mail, MailOpen, Megaphone, Search, Smartphone } from "lucide-react"
|
import { Bell, CalendarClock, Mail, MailOpen, Megaphone, Search, Smartphone } from "lucide-react"
|
||||||
|
|
@ -24,7 +25,6 @@ import {
|
||||||
validateEmailComposeInput,
|
validateEmailComposeInput,
|
||||||
} from "../../lib/notificationEmailCompose"
|
} from "../../lib/notificationEmailCompose"
|
||||||
import {
|
import {
|
||||||
extractApiErrorMessage,
|
|
||||||
fetchAllPlatformUsers,
|
fetchAllPlatformUsers,
|
||||||
fetchAllTeamMembers,
|
fetchAllTeamMembers,
|
||||||
formatScheduledAtLabel,
|
formatScheduledAtLabel,
|
||||||
|
|
@ -507,9 +507,7 @@ export function CreateNotificationPage() {
|
||||||
|
|
||||||
resetForm()
|
resetForm()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error("Failed to send notification", {
|
notifyApiError(err, "Failed to send notification")
|
||||||
description: extractApiErrorMessage(err, "Please try again."),
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
setSending(false)
|
setSending(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom"
|
import { Link, useNavigate, useParams } from "react-router-dom"
|
||||||
import { ArrowLeft, RefreshCw, Shield, Trash2 } from "lucide-react"
|
import { ArrowLeft, RefreshCw, Shield, Trash2 } from "lucide-react"
|
||||||
|
|
@ -65,7 +66,7 @@ export function EmailTemplateDetailPage() {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
setError(true)
|
setError(true)
|
||||||
setTemplate(null)
|
setTemplate(null)
|
||||||
toast.error("Failed to load email template")
|
notifyApiError(e, "Failed to load email template")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -104,10 +105,7 @@ export function EmailTemplateDetailPage() {
|
||||||
toast.success("Email template updated")
|
toast.success("Email template updated")
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg =
|
notifyApiError(e, "Failed to update email template")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to update email template"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import { Eye, Mail, Plus, RefreshCw, Search, Shield, Trash2 } from "lucide-react"
|
import { Eye, Mail, Plus, RefreshCw, Search, Shield, Trash2 } from "lucide-react"
|
||||||
|
|
@ -45,7 +46,7 @@ export function EmailTemplatesPage() {
|
||||||
setError(true)
|
setError(true)
|
||||||
setTemplates([])
|
setTemplates([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
toast.error("Failed to load email templates")
|
notifyApiError(e, "Failed to load email templates")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useEffect, useState, useCallback } from "react"
|
import { useEffect, useState, useCallback } from "react"
|
||||||
import {
|
import {
|
||||||
Bell,
|
Bell,
|
||||||
|
|
@ -396,7 +397,7 @@ export function NotificationsPage() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setDetailError(true)
|
setDetailError(true)
|
||||||
toast.error("Failed to load notification details")
|
notifyApiError(err, "Failed to load notification details")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setDetailLoading(false)
|
setDetailLoading(false)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import {
|
import {
|
||||||
|
|
@ -91,7 +92,7 @@ export function ScheduledNotificationsPage() {
|
||||||
setError(true)
|
setError(true)
|
||||||
setRows([])
|
setRows([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
toast.error("Failed to load scheduled notifications")
|
notifyApiError(err, "Failed to load scheduled notifications")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +116,7 @@ export function ScheduledNotificationsPage() {
|
||||||
})
|
})
|
||||||
await load()
|
await load()
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to cancel scheduled notification")
|
notifyApiError(err, "Failed to cancel scheduled notification")
|
||||||
} finally {
|
} finally {
|
||||||
setCancellingId(null)
|
setCancellingId(null)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Trash2 } from "lucide-react"
|
import { Trash2 } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { deleteEmailTemplate } from "../../../api/emailTemplates.api"
|
import { deleteEmailTemplate } from "../../../api/emailTemplates.api"
|
||||||
import { Button } from "../../../components/ui/button"
|
import { Button } from "../../../components/ui/button"
|
||||||
import {
|
import {
|
||||||
|
|
@ -47,10 +48,7 @@ export function EmailTemplateDeleteDialog({
|
||||||
onDeleted?.()
|
onDeleted?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg =
|
notifyApiError(e, "Failed to delete email template")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data
|
|
||||||
?.message ?? "Failed to delete email template"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react"
|
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react"
|
||||||
import {
|
import {
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
|
|
@ -168,7 +169,7 @@ export function PaymentsPage() {
|
||||||
setError(true)
|
setError(true)
|
||||||
setPayments([])
|
setPayments([])
|
||||||
setTotalCount(0)
|
setTotalCount(0)
|
||||||
toast.error("Failed to load payments")
|
notifyApiError(e, "Failed to load payments")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +191,7 @@ export function PaymentsPage() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
setPaymentStats(EMPTY_PAYMENT_STATS)
|
setPaymentStats(EMPTY_PAYMENT_STATS)
|
||||||
toast.error("Failed to load payment summary")
|
notifyApiError(e, "Failed to load payment summary")
|
||||||
} finally {
|
} finally {
|
||||||
setStatsLoading(false)
|
setStatsLoading(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,16 +30,15 @@ import {
|
||||||
import { usePersonaPermissions } from "../../hooks/usePersonaPermissions"
|
import { usePersonaPermissions } from "../../hooks/usePersonaPermissions"
|
||||||
import { countActiveFilters } from "../../lib/adminFilterUtils"
|
import { countActiveFilters } from "../../lib/adminFilterUtils"
|
||||||
import { fetchAllOffsetPages } from "../../lib/fetchAllOffsetPages"
|
import { fetchAllOffsetPages } from "../../lib/fetchAllOffsetPages"
|
||||||
|
import { PersonaAvatar } from "../../components/personas/PersonaAvatar"
|
||||||
import {
|
import {
|
||||||
formatPersonaDate,
|
formatPersonaDate,
|
||||||
personaAvatarUrl,
|
personaAvatarUrl,
|
||||||
personaGenderLabel,
|
personaGenderLabel,
|
||||||
personaStatusLabel,
|
personaStatusLabel,
|
||||||
} from "../../lib/personaDisplay"
|
} from "../../lib/personaDisplay"
|
||||||
import {
|
import { notifyApiError } from "../../lib/apiErrors"
|
||||||
getPersonaApiErrorMessage,
|
import { isPersonaForbiddenError } from "../../lib/personasErrors"
|
||||||
isPersonaForbiddenError,
|
|
||||||
} from "../../lib/personasErrors"
|
|
||||||
import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tablePagination"
|
||||||
import type { LmsPersona } from "../../types/persona.types"
|
import type { LmsPersona } from "../../types/persona.types"
|
||||||
import { CreatePersonaDialog } from "./components/CreatePersonaDialog"
|
import { CreatePersonaDialog } from "./components/CreatePersonaDialog"
|
||||||
|
|
@ -100,9 +99,9 @@ export function PersonasPage() {
|
||||||
setPersonas([])
|
setPersonas([])
|
||||||
if (isPersonaForbiddenError(e)) {
|
if (isPersonaForbiddenError(e)) {
|
||||||
setPermissionDenied(true)
|
setPermissionDenied(true)
|
||||||
toast.error(getPersonaApiErrorMessage(e, "You do not have permission to view personas"))
|
notifyApiError(e, "You do not have permission to view personas")
|
||||||
} else {
|
} else {
|
||||||
toast.error(getPersonaApiErrorMessage(e, "Failed to load personas"))
|
notifyApiError(e, "Failed to load personas")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
@ -173,7 +172,7 @@ export function PersonasPage() {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error(getPersonaApiErrorMessage(e, "Failed to update persona status"))
|
notifyApiError(e, "Failed to update persona status")
|
||||||
} finally {
|
} finally {
|
||||||
setTogglingId(null)
|
setTogglingId(null)
|
||||||
}
|
}
|
||||||
|
|
@ -299,14 +298,14 @@ export function PersonasPage() {
|
||||||
paginated.map((persona) => (
|
paginated.map((persona) => (
|
||||||
<TableRow key={persona.id}>
|
<TableRow key={persona.id}>
|
||||||
<TableCell className="py-3.5">
|
<TableCell className="py-3.5">
|
||||||
<img
|
<PersonaAvatar
|
||||||
src={personaAvatarUrl(
|
src={personaAvatarUrl(
|
||||||
persona.profile_picture,
|
persona.profile_picture,
|
||||||
persona.name,
|
persona.name,
|
||||||
persona.id,
|
persona.id,
|
||||||
)}
|
)}
|
||||||
alt=""
|
alt={persona.name}
|
||||||
className="h-10 w-10 rounded-full border border-grayScale-200 bg-grayScale-50 object-cover"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="py-3.5">
|
<TableCell className="py-3.5">
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "../../../components/ui/dialog"
|
} from "../../../components/ui/dialog"
|
||||||
import { getPersonaApiErrorMessage } from "../../../lib/personasErrors"
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
draftToCreatePayload,
|
draftToCreatePayload,
|
||||||
EMPTY_PERSONA_FORM_DRAFT,
|
EMPTY_PERSONA_FORM_DRAFT,
|
||||||
|
|
@ -62,7 +62,7 @@ export function CreatePersonaDialog({
|
||||||
onCreated?.()
|
onCreated?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error(getPersonaApiErrorMessage(e, "Failed to create persona"))
|
notifyApiError(e, "Failed to create persona")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "../../../components/ui/dialog"
|
} from "../../../components/ui/dialog"
|
||||||
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
||||||
import { getPersonaApiErrorMessage } from "../../../lib/personasErrors"
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import type { LmsPersona } from "../../../types/persona.types"
|
import type { LmsPersona } from "../../../types/persona.types"
|
||||||
import {
|
import {
|
||||||
draftToUpdatePayload,
|
draftToUpdatePayload,
|
||||||
|
|
@ -54,7 +54,7 @@ export function EditPersonaDialog({
|
||||||
if (status === 404) {
|
if (status === 404) {
|
||||||
toast.error("Persona not found")
|
toast.error("Persona not found")
|
||||||
} else {
|
} else {
|
||||||
toast.error(getPersonaApiErrorMessage(e, "Failed to load persona"))
|
notifyApiError(e, "Failed to load persona")
|
||||||
}
|
}
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -95,7 +95,7 @@ export function EditPersonaDialog({
|
||||||
onUpdated?.()
|
onUpdated?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error(getPersonaApiErrorMessage(e, "Failed to update persona"))
|
notifyApiError(e, "Failed to update persona")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { syncRbacPermissions } from "../../../api/rbac.api"
|
||||||
import { Button } from "../../../components/ui/button"
|
import { Button } from "../../../components/ui/button"
|
||||||
import { Card, CardContent } from "../../../components/ui/card"
|
import { Card, CardContent } from "../../../components/ui/card"
|
||||||
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
||||||
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import { PERSONAS_FORBIDDEN_MESSAGE } from "../../../lib/personasErrors"
|
import { PERSONAS_FORBIDDEN_MESSAGE } from "../../../lib/personasErrors"
|
||||||
import {
|
import {
|
||||||
getSessionTeamRole,
|
getSessionTeamRole,
|
||||||
|
|
@ -28,10 +29,7 @@ export function PersonaAccessDenied({ apiForbidden = false }: PersonaAccessDenie
|
||||||
toast.success(res.data?.message ?? "RBAC permissions synced. Please sign in again.")
|
toast.success(res.data?.message ?? "RBAC permissions synced. Please sign in again.")
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const msg =
|
notifyApiError(e, "Failed to sync RBAC permissions")
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data?.message ??
|
|
||||||
"Failed to sync RBAC permissions"
|
|
||||||
toast.error(msg)
|
|
||||||
} finally {
|
} finally {
|
||||||
setSyncing(false)
|
setSyncing(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Trash2 } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { deletePersona } from "../../../api/personas.api"
|
import { deletePersona } from "../../../api/personas.api"
|
||||||
import { Button } from "../../../components/ui/button"
|
import { Button } from "../../../components/ui/button"
|
||||||
import { getPersonaApiErrorMessage } from "../../../lib/personasErrors"
|
import { notifyApiError } from "../../../lib/apiErrors"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
|
|
@ -44,7 +44,7 @@ export function PersonaDeleteDialog({
|
||||||
onDeleted?.()
|
onDeleted?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.error(getPersonaApiErrorMessage(e, "Failed to delete persona"))
|
notifyApiError(e, "Failed to delete persona")
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||