fix: multiple error
This commit is contained in:
@@ -140,7 +140,7 @@ export function Demos() {
|
||||
setDetails(null)
|
||||
setDetailsLoading(true)
|
||||
try {
|
||||
const res = await api.getDemoDetails(d.username)
|
||||
const res = await api.getDemoDetails(d.namespace)
|
||||
setDetails(res)
|
||||
} catch (err) {
|
||||
const msg = err instanceof ApiError ? err.message : 'Erreur'
|
||||
@@ -156,10 +156,10 @@ export function Demos() {
|
||||
useEffect(() => {
|
||||
const current = demos.find((d) => d.id === expandedId)
|
||||
if (!current) return
|
||||
const username = current.username
|
||||
const namespace = current.namespace
|
||||
const id = setInterval(() => {
|
||||
api
|
||||
.getDemoDetails(username)
|
||||
.getDemoDetails(namespace)
|
||||
.then(setDetails)
|
||||
.catch(() => {
|
||||
/* échec silencieux : on garde le dernier état connu affiché */
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Heading,
|
||||
HStack,
|
||||
Input,
|
||||
Link,
|
||||
Spacer,
|
||||
Spinner,
|
||||
Stack,
|
||||
@@ -17,7 +18,8 @@ import {
|
||||
useToast,
|
||||
} from '@chakra-ui/react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { api, ApiError } from '../../lib/api'
|
||||
import { api, ApiError, type Demo } from '../../lib/api'
|
||||
import { statusColor, statusLabel } from '../../lib/format'
|
||||
|
||||
export function Subscription() {
|
||||
const toast = useToast()
|
||||
@@ -28,6 +30,8 @@ export function Subscription() {
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [code, setCode] = useState('')
|
||||
const [showRenewForm, setShowRenewForm] = useState(false)
|
||||
const [demos, setDemos] = useState<Demo[]>([])
|
||||
const [demosLoading, setDemosLoading] = useState(true)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
@@ -42,9 +46,21 @@ export function Subscription() {
|
||||
}
|
||||
}, [navigate, toast])
|
||||
|
||||
const loadDemos = useCallback(async () => {
|
||||
try {
|
||||
const res = await api.listMyDemos()
|
||||
setDemos(res.items ?? [])
|
||||
} catch {
|
||||
// Silencieux : l'absence de démo n'est pas une erreur à afficher ici.
|
||||
} finally {
|
||||
setDemosLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
void load()
|
||||
}, [load])
|
||||
void loadDemos()
|
||||
}, [load, loadDemos])
|
||||
|
||||
const submitCode = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
@@ -76,6 +92,36 @@ export function Subscription() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Flex mb={6} align="center">
|
||||
<Heading size="md">Ma démo</Heading>
|
||||
<Spacer />
|
||||
</Flex>
|
||||
|
||||
<Box mb={8} p={6} borderWidth="1px" borderRadius="lg" bg="bg-surface">
|
||||
{demosLoading ? (
|
||||
<Spinner size="sm" />
|
||||
) : demos.length === 0 ? (
|
||||
<Text color="gray.500">Aucune démo pour le moment.</Text>
|
||||
) : (
|
||||
<VStack align="stretch" spacing={3}>
|
||||
{demos.map((d) => (
|
||||
<HStack key={d.id} justify="space-between" flexWrap="wrap" rowGap={2}>
|
||||
{d.status === 'ready' ? (
|
||||
<Link href={d.url} color="primary.500" isExternal fontFamily="mono">
|
||||
{d.url}
|
||||
</Link>
|
||||
) : (
|
||||
<Text color="gray.400" fontFamily="mono">
|
||||
{d.url || '—'}
|
||||
</Text>
|
||||
)}
|
||||
<Badge colorScheme={statusColor(d.status)}>{statusLabel(d.status)}</Badge>
|
||||
</HStack>
|
||||
))}
|
||||
</VStack>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Flex mb={6} align="center">
|
||||
<Heading size="md">Mon abonnement</Heading>
|
||||
<Spacer />
|
||||
|
||||
Reference in New Issue
Block a user