From d055507c800ac2a877a8329a366dbbda124712fa Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 5 Aug 2024 14:29:22 +0800 Subject: [PATCH] feat: Add badges to admin --- i18n/en_US.yaml | 16 ++- ui/src/common/constants.ts | 3 + ui/src/common/interface.ts | 2 + .../Admin/Badges/components/Action/index.tsx | 51 ++++++++ ui/src/pages/Admin/Badges/index.tsx | 122 ++++++++++++++++++ ui/src/pages/Admin/index.tsx | 1 + ui/src/router/routes.ts | 4 + 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 ui/src/pages/Admin/Badges/components/Action/index.tsx create mode 100644 ui/src/pages/Admin/Badges/index.tsx diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 5cd06573..f50465c2 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -1692,6 +1692,7 @@ ui: questions: Questions answers: Answers users: Users + badges: Badges flags: Flags settings: Settings general: General @@ -2117,7 +2118,20 @@ ui: msg: should_be_number: the input should be number number_larger_1: number should be equal or larger than 1 - + badges: + action: Action + active: Active + all: All + awards: Awards + deactivate: Deactivate + filter: + placeholder: Filter by name, badge:id + group: Group + inactive: Inactive + name: Name + show_logs: Show logs + status: Status + title: Badges form: optional: (optional) empty: cannot be empty diff --git a/ui/src/common/constants.ts b/ui/src/common/constants.ts index c846d4dd..d52f2b87 100644 --- a/ui/src/common/constants.ts +++ b/ui/src/common/constants.ts @@ -93,6 +93,9 @@ export const ADMIN_NAV_MENUS = [ { name: 'users', }, + { + name: 'badges', + }, { name: 'customize', children: [ diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts index ff7c0902..41dc0fef 100644 --- a/ui/src/common/interface.ts +++ b/ui/src/common/interface.ts @@ -328,6 +328,8 @@ export type UserFilterBy = | 'suspended' | 'deleted'; +export type BadgeFilterBy = 'all' | 'active' | 'inactive'; + export type InstalledPluginsFilterBy = | 'all' | 'active' diff --git a/ui/src/pages/Admin/Badges/components/Action/index.tsx b/ui/src/pages/Admin/Badges/components/Action/index.tsx new file mode 100644 index 00000000..77601cbb --- /dev/null +++ b/ui/src/pages/Admin/Badges/components/Action/index.tsx @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Dropdown } from 'react-bootstrap'; +import { useTranslation } from 'react-i18next'; + +import { Icon } from '@/components'; + +interface Props { + badgeData; +} + +const UserOperation = ({ badgeData }: Props) => { + const { t } = useTranslation('translation', { keyPrefix: 'admin.badges' }); + + console.log(badgeData); + + return ( + + + + + + + {t('active')} + {t('deactivate')} + + {t('show_logs')} + + + + ); +}; + +export default UserOperation; diff --git a/ui/src/pages/Admin/Badges/index.tsx b/ui/src/pages/Admin/Badges/index.tsx new file mode 100644 index 00000000..28854012 --- /dev/null +++ b/ui/src/pages/Admin/Badges/index.tsx @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FC } from 'react'; +import { Form, Table, Stack } from 'react-bootstrap'; +import { useSearchParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; + +import { QueryGroup } from '@/components'; +import * as Type from '@/common/interface'; + +import Action from './components/Action'; + +const BadgeFilterKeys: Type.BadgeFilterBy[] = ['all', 'active', 'inactive']; + +// const bgMap = { +// normal: 'text-bg-success', +// suspended: 'text-bg-danger', +// deleted: 'text-bg-danger', +// inactive: 'text-bg-secondary', +// }; + +const Users: FC = () => { + const { t } = useTranslation('translation', { keyPrefix: 'admin.badges' }); + + const [urlSearchParams, setUrlSearchParams] = useSearchParams(); + const curFilter = urlSearchParams.get('filter') || BadgeFilterKeys[0]; + const curQuery = urlSearchParams.get('query') || ''; + + const handleFilter = (e) => { + urlSearchParams.set('query', e.target.value); + urlSearchParams.delete('page'); + setUrlSearchParams(urlSearchParams); + }; + + return ( + <> +

{t('title')}

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
{t('name')}{t('group')}{t('awards')}{t('status')}{t('action')}
+ badge +
+
Nice Question
+
Question score of 10 or more.
+
+
Community Badges200Active
+ {/* {Number(data?.count) <= 0 && !isLoading && } */} + {/*
+ +
*/} + + ); +}; + +export default Users; diff --git a/ui/src/pages/Admin/index.tsx b/ui/src/pages/Admin/index.tsx index b527088f..5da0780d 100644 --- a/ui/src/pages/Admin/index.tsx +++ b/ui/src/pages/Admin/index.tsx @@ -37,6 +37,7 @@ const g10Paths = [ 'questions', 'answers', 'users', + 'badges', 'flags', 'installed-plugins', ]; diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts index 5c420e36..bd4a0c79 100644 --- a/ui/src/router/routes.ts +++ b/ui/src/router/routes.ts @@ -400,6 +400,10 @@ const routes: RouteNode[] = [ path: ':slug_name', page: 'pages/Admin/Plugins/Config', }, + { + path: 'badges', + page: 'pages/Admin/Badges', + }, ], }, {