Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Sep 13, 2024
1 parent bf221c8 commit 5a21386
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
12 changes: 6 additions & 6 deletions apps/router/src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ export const AppContextProvider: React.FC<AppContextProviderProps> = ({
const [state, dispatch] = useReducer(reducer, makeInitialState());

useEffect(() => {
const addService = (service: Service) => {
const addService = (service: Service, index: number) => {
const kind = isGuardian(service) ? 'guardian' : 'gateway';
const stateKey = `${kind}s` as 'guardians' | 'gateways';
const id = (Object.keys(state[stateKey]).length + 1).toString();
const id = (index + 1).toString();

if (kind === 'guardian') {
dispatch({
Expand All @@ -173,12 +172,13 @@ export const AppContextProvider: React.FC<AppContextProviderProps> = ({

const handleConfig = (data: Service | Service[]) => {
const services = Array.isArray(data) ? data : [data];
services.forEach((service) => {
services.forEach((service, index) => {
if (isGuardian(service) || isGateway(service)) {
addService(service);
addService(service, index);
}
});
};

fetch('/config.json')
.then((response) => {
if (!response.ok) {
Expand All @@ -202,7 +202,7 @@ export const AppContextProvider: React.FC<AppContextProviderProps> = ({
.catch((error) => {
console.error('Error fetching or processing config:', error);
});
}, [state]);
}, []);

return (
<AppContext.Provider value={{ ...state, dispatch }}>
Expand Down
34 changes: 18 additions & 16 deletions apps/router/src/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,25 @@ export const HomePage: React.FC = () => {
<Table variant='simple'>
<Thead>
<Tr>
<Th>{t('home.guardianId', 'Guardian ID')}</Th>
<Th>{t('home.guardianUrl', 'Guardian URL')}</Th>
<Th>{t('home.actions', 'Actions')}</Th>
</Tr>
</Thead>
<Tbody>
{Object.keys(guardians).map((guardianIndex) => (
<Tr key={`guardian-${guardianIndex}`}>
<Td>{guardianIndex}</Td>
<Td>
<Link to={`/guardian/${guardianIndex}`}>
<Button size='sm' colorScheme='green'>
{t('home.view', 'View')}
</Button>
</Link>
</Td>
</Tr>
))}
{Object.entries(guardians).map(
([guardianIndex, guardian]) => (
<Tr key={`guardian-${guardianIndex}`}>
<Td>{guardian.config.fm_config_api}</Td>
<Td>
<Link to={`/guardian/${guardianIndex}`}>
<Button size='sm' colorScheme='green'>
{t('home.view', 'View')}
</Button>
</Link>
</Td>
</Tr>
)
)}
</Tbody>
</Table>
</CardBody>
Expand All @@ -84,14 +86,14 @@ export const HomePage: React.FC = () => {
<Table variant='simple'>
<Thead>
<Tr>
<Th>{t('home.gatewayId', 'Gateway ID')}</Th>
<Th>{t('home.gatewayUrl', 'Gateway URL')}</Th>
<Th>{t('home.actions', 'Actions')}</Th>
</Tr>
</Thead>
<Tbody>
{Object.keys(gateways).map((gatewayIndex) => (
{Object.entries(gateways).map(([gatewayIndex, gateway]) => (
<Tr key={`gateway-${gatewayIndex}`}>
<Td>{gatewayIndex}</Td>
<Td>{gateway.config.baseUrl}</Td>
<Td>
<Link to={`/gateway/${gatewayIndex}`}>
<Button size='sm' colorScheme='purple'>
Expand Down
8 changes: 8 additions & 0 deletions apps/router/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = function (app) {
app.use('/config.json', (_req, res) => {
res.json({
fm_config_api: process.env.REACT_APP_FM_CONFIG_API,
tos: process.env.REACT_APP_TOS,
});
});
};

0 comments on commit 5a21386

Please sign in to comment.