/****************************************************************************** * Copyright (c) 2026 Contributors to the Eclipse Foundation. * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 *****************************************************************************/ import { FC, useContext, useState, useEffect, useRef, useCallback } from "react"; import { Box, Typography, Button, Alert, LinearProgress } from "@mui/material"; import EditIcon from '@mui/icons-material/Edit'; import { useParams } from 'react-router-dom'; import { MainContext } from '../../../context'; import type { Customer } from '../../../extension-registry-types'; import { handleError } from '../../../utils'; import { useAdminUsageStats } from '../usage-stats/use-usage-stats'; import { GeneralDetails, UsageStats } from '../../../components/rate-limiting/customer'; import { CustomerFormDialog } from './customer-form-dialog'; import { CustomerMemberList } from './customer-member-list'; import { CustomerTokenList } from './customer-token-list'; const CustomerDetailsLoading: FC = () => ( ); const CustomerDetailsError: FC<{ message: string }> = ({ message }) => ( {message} ); export const CustomerDetails: FC = () => { const { customer: customerName } = useParams<{ customer: string }>(); const abortController = useRef(new AbortController()); const { service } = useContext(MainContext); const [customer, setCustomer] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [formDialogOpen, setFormDialogOpen] = useState(false); const { usageStats, dailyP95, error: statsError, startDate, setStartDate } = useAdminUsageStats(customerName); const loadCustomer = useCallback(async () => { if (!customerName) return; try { setLoading(true); setError(null); const data = await service.admin.getCustomer(abortController.current, customerName); setCustomer(data); } catch (err) { if ((err as { status?: number })?.status === 404) { setError(`Customer "${customerName}" not found.`); } else { setError(handleError(err as Error)); } } finally { setLoading(false); } }, [service, customerName]); useEffect(() => { loadCustomer(); return () => abortController.current.abort(); }, [loadCustomer]); const handleFormSubmit = async (updatedCustomer: Customer) => { if (customer) { await service.admin.updateCustomer(abortController.current, customer.name, updatedCustomer); await loadCustomer(); } }; if (loading) { return ; } if (error || statsError) { return ; } if (!customer) { return null; } return ( <> {customer.name} } onClick={() => setFormDialogOpen(true)}> Edit } /> setFormDialogOpen(false)} onSubmit={handleFormSubmit} /> ); };