/******************************************************************************
* 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 { FunctionComponent, ReactNode, useContext, useEffect, useState, useRef } from 'react';
import { Box, Typography, Tabs, Tab, useTheme, useMediaQuery } from '@mui/material';
import { Customer } from '../../extension-registry-types';
import { DelayedLoadIndicator } from '../../components/delayed-load-indicator';
import { MainContext } from '../../context';
import { UserSettingsCustomerDetail } from './user-settings-customer-detail';
interface CustomerTabsProps {
chosenCustomer: Customer;
onChange: (value: Customer) => void;
customers: Customer[];
}
const CustomersTabs = (props: CustomerTabsProps) => {
const theme = useTheme();
const isATablet = useMediaQuery(theme.breakpoints.down('md'));
return (
props.onChange(value)}
variant={isATablet ? 'scrollable' : 'standard'}
scrollButtons={isATablet ? 'auto' : false}
indicatorColor='secondary'
sx={{ width: { xs: '80%', sm: '80%', md: '80%', lg: '160px', xl: '160px' } }}
>
{props.customers.map(customer => (
))}
);
};
export const UserSettingsCustomers: FunctionComponent = () => {
const [loading, setLoading] = useState(true);
const [customers, setCustomers] = useState([]);
const [chosenCustomer, setChosenCustomer] = useState();
const { service, handleError } = useContext(MainContext);
const abortController = useRef(new AbortController());
useEffect(() => {
loadCustomers();
return () => {
abortController.current.abort();
};
}, []);
const loadCustomers = async (): Promise => {
try {
const data = await service.getCustomers(abortController.current);
const chosen = data.length ? data[0] : undefined;
setCustomers(data);
setChosenCustomer(chosen);
setLoading(false);
} catch (err) {
handleError(err);
setLoading(false);
}
};
let customerContainer: ReactNode = null;
if (customers.length > 0 && chosenCustomer) {
customerContainer = (
);
} else if (!loading) {
customerContainer = (
You are not a member of any rate limiting customer group.
);
}
return (
<>
Rate Limiting
{customerContainer}
>
);
};