Skip to content

Commit

Permalink
bot usages
Browse files Browse the repository at this point in the history
  • Loading branch information
wadabee committed Mar 19, 2024
1 parent 0f70787 commit 02367d0
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 46 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/ChatListDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ const ChatListDrawer: React.FC<Props> = (props) => {
<DrawerItem
isActive={false}
icon={<PiGlobe />}
to="admin/published-bot-apis"
to="admin/publish-apis"
labelComponent={t('button.botPublishApis')}
/>
<DrawerItem
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/hooks/useAdminApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const useAdminApi = () => {
return http.get<ListBotApisResponse>(['/admin/published-bots', req]);
},
listPublicBots: (req: ListPublicBotsRequest) => {
return http.get<ListPublicBotsResponse>(['/admin/public-bots', req]);
return http.get<ListPublicBotsResponse>(
!!req.start === !!req.end ? ['/admin/public-bots', req] : null
);
},
};
};
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ How would you categorize this email?`,
pageTitle: 'Public Bot Usages',
noPublicBotUsages:
'During the Calculation Period, the public bots were not utilized.',
published: 'The Bot API is published.',
published: 'API is published.',
SearchCondition: {
title: 'Calculation Period',
from: 'From',
Expand All @@ -245,8 +245,18 @@ How would you categorize this email?`,
help: {
overview:
'Monitor the usage status of Shared Bots and Published Bot APIs.',
calculationPeriod:
'If the Calculation Period is not set, the cost for today will be displayed.',
},
},
publishApis: {
label: {
pageTitle: 'Bot Publish APIs',
},
},
validationError: {
period: 'Enter both From and To',
},
},
deleteDialog: {
title: 'Delete?',
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 AdminBotApisPage from './pages/AdminBotApisPage.tsx';

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -44,6 +45,10 @@ const router = createBrowserRouter([
path: '/admin/public-bots',
element: <AdminPublicBotsPage />,
},
{
path: '/admin/publish-apis',
element: <AdminBotApisPage />,
},
{
path: '/:conversationId',
element: <ChatPage />,
Expand Down
154 changes: 154 additions & 0 deletions frontend/src/pages/AdminBotApisPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import Help from '../components/Help';
import usePublicBotsForAdmin from '../hooks/usePublicBotsForAdmin';
import ListItemBot from '../components/ListItemBot';
import { formatDate, formatDatetime } from '../utils/DateUtils';

import InputText from '../components/InputText';
import Button from '../components/Button';
import { PiArrowDown } from 'react-icons/pi';
import Skeleton from '../components/Skeleton';

const AdminBotApisPage: React.FC = () => {
const { t } = useTranslation();
// const navigate = useNavigate();

const [searchDateFrom, setSearchDateFrom] = useState<null | string>(null);
const [searchDateTo, setSearchDateTo] = useState<null | string>(null);

const { publicBots, isLoading: isLoadingPublicBots } = usePublicBotsForAdmin({
start: searchDateFrom ? searchDateFrom + '00' : undefined,
end: searchDateTo ? searchDateTo + '23' : undefined,
});

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

return (
<>
{/* <DialogConfirmDeleteBot
isOpen={isOpenDeleteDialog}
target={targetDelete}
onDelete={onDeleteMyBot}
onClose={() => {
setIsOpenDeleteDialog(false);
}}
/>
<DialogConfirmShareBot
isOpen={isOpenShareDialog}
target={targetShareBot}
onToggleShare={onToggleShare}
onClose={() => {
setIsOpenShareDialog(false);
}}
/> */}
<div className="flex h-full justify-center">
<div className="w-2/3">
<div className="h-full w-full pt-8">
<div className="flex items-end justify-between">
<div className="flex items-center gap-2">
<div className="text-xl font-bold">
{t('admin.publishApis.label.pageTitle')}
</div>
<Help
direction="right"
message={t('admin.publicBotUsages.help.overview')}
/>
</div>
</div>

<div className="my-2 rounded border p-2">
<div className="text-sm font-bold">
{t('admin.publicBotUsages.label.SearchCondition.title')}
</div>

<div className="flex gap-2 sm:w-full md:w-3/4">
<InputText
className="w-full"
type="date"
label={t('admin.publicBotUsages.label.SearchCondition.from')}
value={formatDate(searchDateFrom, 'YYYY-MM-DD')}
onChange={(val) => {
setSearchDateFrom(formatDate(val, 'YYYYMMDD'));
}}
/>
<InputText
className="w-full"
type="date"
label={t('admin.publicBotUsages.label.SearchCondition.to')}
value={formatDate(searchDateTo, 'YYYY-MM-DD')}
onChange={(val) => {
setSearchDateTo(formatDate(val, 'YYYYMMDD'));
}}
/>
</div>
</div>

<div className="my-2 flex justify-end">
<Button outlined rightIcon={<PiArrowDown />} onClick={() => {}}>
{t('admin.publicBotUsages.label.sortByCost')}
</Button>
</div>

<div className="mt-2 border-b border-gray"></div>

<div className="h-4/5 overflow-x-hidden overflow-y-scroll border-b border-gray pr-1 scrollbar-thin scrollbar-thumb-aws-font-color/20 ">
{isLoadingPublicBots && (
<div className="flex flex-col gap-2">
{new Array(15).fill('').map((_, idx) => {
return <Skeleton key={idx} className="h-12 w-full" />;
})}
</div>
)}

{publicBots?.length === 0 && (
<div className="flex h-full w-full items-center justify-center italic text-dark-gray">
{t('admin.publicBotUsages.label.noPublicBotUsages')}
</div>
)}
{publicBots?.map((bot, idx) => (
<ListItemBot
key={idx}
bot={{
...bot,
available: true,
}}
onClick={() => {
// onClickViewBot(bot.id);
}}>
<div className="flex gap-3">
<div className="flex gap-1 text-lg font-bold">
{(Math.floor(bot.totalPrice * 100) / 100).toFixed(2)} USD
</div>

<div className="flex flex-col gap-1 text-sm">
{bot.isPublished ? (
<>
<div className="font-bold">
{/* {t('admin.label.publishedDate')}: */}
</div>
{bot.publishedDatetime
? formatDatetime(bot.publishedDatetime)
: null}
</>
) : (
<div></div>
)}
</div>
</div>
</ListItemBot>
))}
</div>
</div>
</div>
</div>
</>
);
};

export default AdminBotApisPage;
Loading

0 comments on commit 02367d0

Please sign in to comment.