Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wadabee committed Mar 22, 2024
1 parent b03c9b2 commit 8ee5130
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
8 changes: 6 additions & 2 deletions frontend/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,17 @@ How would you categorize this email?`,
body: 'You cannot publish an API for the bot that is not shared.',
},
deploying: {
title: 'The API deployment is in PROGRESS.',
title: 'The API deployment is in PROGRESS',
body: 'Please wait until the deployment is complete.',
},
deployed: {
title: 'The API has been DEPLOYED.',
title: 'The API has been DEPLOYED',
body: 'You can access the API from the Client using the API Endpoint and API Key.',
},
deployError: {
title: 'FAILED to deploy the API',
body: 'Please delete the API and re-create the API.',
},
},
deleteApiDaialog: {
title: 'Delete?',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './i18n';
import BotExplorePage from './pages/BotExplorePage.tsx';
import BotEditPage from './pages/BotEditPage.tsx';
import BotApiSettingsPage from './pages/BotApiSettingsPage.tsx';
import AdminPublicBotsPage from './pages/AdminPublicBotsPage.tsx';
import AdminPublicBotUsagesPage from './pages/AdminPublicBotUsagesPage.tsx';
import AdminBotApisPage from './pages/AdminBotApisPage.tsx';
import AdminBotApiManagePage from './pages/AdminBotApiManagePage.tsx';

Expand Down Expand Up @@ -44,7 +44,7 @@ const router = createBrowserRouter([
},
{
path: '/admin/public-bot/usages',
element: <AdminPublicBotsPage />,
element: <AdminPublicBotUsagesPage />,
},
{
path: '/admin/publish-apis',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import Help from '../components/Help';
import usePublicBotsForAdmin from '../hooks/usePublicBotsForAdmin';
Expand All @@ -10,10 +10,11 @@ import Button from '../components/Button';
import { PiArrowDown } from 'react-icons/pi';
import Skeleton from '../components/Skeleton';
import { twMerge } from 'tailwind-merge';
import { useNavigate } from 'react-router-dom';

const DATA_FORMAT = 'YYYYMMDD';

const AdminPublicBotsPage: React.FC = () => {
const AdminPublicBotUsagesPage: React.FC = () => {
const { t } = useTranslation();

const [searchDateFrom, setSearchDateFrom] = useState<null | string>(
Expand Down Expand Up @@ -42,6 +43,15 @@ const AdminPublicBotsPage: React.FC = () => {
: t('admin.validationError.period');
}, [searchDateFrom, searchDateTo, t]);

const navigate = useNavigate();

const onClickViewBot = useCallback(
(botId: string) => {
navigate(`/admin/bot/${botId}`);
},
[navigate]
);

return (
<>
<div className="flex h-full justify-center">
Expand Down Expand Up @@ -149,7 +159,7 @@ const AdminPublicBotsPage: React.FC = () => {
available: true,
}}
onClick={() => {
// onClickViewBot(bot.id);
onClickViewBot(bot.id);
}}>
<div className="relative flex h-full items-center">
<div className="text-lg font-bold">
Expand Down Expand Up @@ -178,4 +188,4 @@ const AdminPublicBotsPage: React.FC = () => {
);
};

export default AdminPublicBotsPage;
export default AdminPublicBotUsagesPage;
24 changes: 20 additions & 4 deletions frontend/src/pages/BotApiSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ const BotApiSettingsPage: React.FC = () => {
clearAll: clearErrorMessages,
} = useErrorMessage();

useEffect(() => {
clearErrorMessages();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const [origins, setOrigins] = useState<string[]>(['']);
const onClickAddOrigin = useCallback(() => {
setOrigins(
Expand Down Expand Up @@ -139,13 +144,16 @@ const BotApiSettingsPage: React.FC = () => {
setOrigins(['']);
}, []);

const [hasFailedDeploy, setHasFailedDeploy] = useState(false);
useEffect(() => {
setHasFailedDeploy(false);
if (!botPublication) {
return;
}

if (botPublication.cfnStatus === 'CREATE_COMPLETE') {
fillApiSettings();
} else if (botPublication.cfnStatus === 'ROLLBACK_COMPLETE') {
setHasFailedDeploy(true);
}
}, [botPublication, fillApiSettings]);

Expand Down Expand Up @@ -334,6 +342,13 @@ const BotApiSettingsPage: React.FC = () => {
<div>{t('bot.apiSettings.alert.botUnshared.body')}</div>
</Alert>
)}
{hasFailedDeploy && (
<Alert
severity="error"
title={t('bot.apiSettings.alert.deployError.title')}>
{t('bot.apiSettings.alert.deployError.body')}
</Alert>
)}

{hasCreated && (
<>
Expand Down Expand Up @@ -379,7 +394,7 @@ const BotApiSettingsPage: React.FC = () => {
</>
)}

{myBot?.isPublic && (
{myBot?.isPublic && !hasFailedDeploy && (
<div className="flex flex-col gap-1">
<div className="text-lg font-bold">
{t('bot.apiSettings.label.usagePlan')}
Expand Down Expand Up @@ -536,12 +551,13 @@ const BotApiSettingsPage: React.FC = () => {
{!isLoadingShare &&
!hasCreated &&
!isDeploying &&
hasShared && (
hasShared &&
!hasFailedDeploy && (
<Button onClick={onClickCreate} loading={isLoading}>
{t('bot.button.create')}
</Button>
)}
{hasCreated && (
{(hasCreated || hasFailedDeploy) && (
<Button
className="bg-red"
onClick={() => {
Expand Down

0 comments on commit 8ee5130

Please sign in to comment.