From 4733b3c9192d8fd2ae35a95dc2ef64e8e1a6f897 Mon Sep 17 00:00:00 2001 From: scarqin Date: Tue, 24 Dec 2024 18:14:50 +0800 Subject: [PATCH] feat: apikeys --- frontend/.windsurfrules | 11 +- .../keySettings/components/EditKeyModal.tsx | 67 ++++++ .../keySettings/components/StatusFilter.tsx | 40 ++++ .../core/src/pages/keySettings/index.tsx | 200 +++++++++++++++++- 4 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 frontend/packages/core/src/pages/keySettings/components/EditKeyModal.tsx create mode 100644 frontend/packages/core/src/pages/keySettings/components/StatusFilter.tsx diff --git a/frontend/.windsurfrules b/frontend/.windsurfrules index 9e10462d..23f6c91c 100644 --- a/frontend/.windsurfrules +++ b/frontend/.windsurfrules @@ -14,4 +14,13 @@ Create detailed components with these requirements: - Update current packages/core/src/pages/Root.tsx with new comprehensive code - Don't forget root route (page.tsx) handling - You MUST complete the entire prompt before stopping -​ \ No newline at end of file +​11. Table component should use +12. use `const { fetchData } = useFetch()` to fetch http data,such as ``` fetchData>('account/profile', { method: 'GET' }).then((response) => { + const { code, data, msg } = response + if (code === STATUS_CODE.SUCCESS) { + setUserInfo(data.profile) + dispatch({ type: 'UPDATE_USERDATA', userData: data.profile }) + } else { + message.error(msg || $t(RESPONSE_TIPS.error)) + } + })``` \ No newline at end of file diff --git a/frontend/packages/core/src/pages/keySettings/components/EditKeyModal.tsx b/frontend/packages/core/src/pages/keySettings/components/EditKeyModal.tsx new file mode 100644 index 00000000..ae0e4833 --- /dev/null +++ b/frontend/packages/core/src/pages/keySettings/components/EditKeyModal.tsx @@ -0,0 +1,67 @@ +import { $t } from '@common/locales' +import { DatePicker, Form, Input, Modal, Switch, theme } from 'antd' +import dayjs from 'dayjs' +import React from 'react' + +interface EditKeyModalProps { + visible: boolean + onCancel: () => void + onSave: (values: any) => void + initialValues?: { + key: string + expirationDate: string + enabled: boolean + } +} + +const EditKeyModal: React.FC = ({ visible, onCancel, onSave, initialValues }) => { + const [form] = Form.useForm() + const { token } = theme.useToken() + + const handleOk = async () => { + try { + const values = await form.validateFields() + onSave({ + ...values, + expirationDate: values.expirationDate.format('YYYY-MM-DD') + }) + } catch (error) { + console.error('Validation failed:', error) + } + } + + return ( + +
+ + + + + + + + + + + +
+
+ ) +} + +export default EditKeyModal diff --git a/frontend/packages/core/src/pages/keySettings/components/StatusFilter.tsx b/frontend/packages/core/src/pages/keySettings/components/StatusFilter.tsx new file mode 100644 index 00000000..64cc18e9 --- /dev/null +++ b/frontend/packages/core/src/pages/keySettings/components/StatusFilter.tsx @@ -0,0 +1,40 @@ +import { $t } from '@common/locales' +import { Select, Space, theme } from 'antd' +import React from 'react' + +interface StatusFilterProps { + value: string[] + onChange: (value: string[]) => void +} + +const StatusFilter: React.FC = ({ value, onChange }) => { + const { token } = theme.useToken() + + const options = [ + { label: $t('Normal'), value: 'normal', color: token.colorSuccess }, + { label: $t('Exceeded'), value: 'exceeded', color: token.colorError }, + { label: $t('Expired'), value: 'expired', color: token.colorWarning }, + { label: $t('Disabled'), value: 'disabled', color: token.colorTextDisabled }, + { label: $t('Error'), value: 'error', color: token.colorError } + ] + + return ( + + {$t('Status')}: + , + + ] + return ( + > + { + setEditingKey(null) + setEditModalVisible(true) + }} + rowKey="id" + /> + + { + setEditModalVisible(false) + setEditingKey(null) + }} + onSave={handleSave} + initialValues={ + editingKey + ? { + key: editingKey.key, + expirationDate: editingKey.expirationDate, + enabled: editingKey.status !== 'disabled' + } + : undefined + } + /> + ) }