From 0cc32cadf359eff4937c25fc4c84ab9c23120146 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Tue, 8 Mar 2022 15:13:45 +0800 Subject: [PATCH] feat(console): app create form (#325) * feat(console): app type description * refactor(console): remove unused code * feat(console): complete app create form inputs * feat(console): create app form submit * fix(console): update per review --- packages/console/package.json | 6 ++- .../components/AppContent/index.module.scss | 4 ++ .../console/src/components/Button/index.tsx | 11 ++++- .../components/FormField/index.module.scss | 12 ++--- .../src/components/FormField/index.tsx | 8 ++-- .../components/RadioGroup/index.module.scss | 2 +- .../src/components/RadioGroup/index.tsx | 2 +- .../components/TextInput/index.module.scss | 36 +++++++++++++++ .../src/components/TextInput/index.tsx | 23 ++++++++++ .../components/CreateForm/index.module.scss | 9 ++++ .../components/CreateForm/index.tsx | 44 ++++++++++++++----- .../TypeDescription/index.module.scss | 2 +- .../console/src/pages/Applications/index.tsx | 9 +++- packages/console/src/scss/modal.module.scss | 2 +- packages/phrases/src/locales/en.ts | 3 +- packages/phrases/src/locales/zh-cn.ts | 1 + pnpm-lock.yaml | 7 +++ 17 files changed, 153 insertions(+), 28 deletions(-) create mode 100644 packages/console/src/components/TextInput/index.module.scss create mode 100644 packages/console/src/components/TextInput/index.tsx diff --git a/packages/console/package.json b/packages/console/package.json index b1d050b85..0063f309e 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -22,6 +22,7 @@ "classnames": "^2.3.1", "i18next": "^21.6.12", "i18next-browser-languagedetector": "^6.1.3", + "ky": "^0.30.0", "lodash.kebabcase": "^4.1.1", "react": "^17.0.2", "react-dom": "^17.0.2", @@ -70,7 +71,10 @@ ] } } - ] + ], + "rules": { + "react/button-has-type": "off" + } }, "stylelint": { "extends": "@silverhand/eslint-config-react/.stylelintrc" diff --git a/packages/console/src/components/AppContent/index.module.scss b/packages/console/src/components/AppContent/index.module.scss index 35cc280ed..00553aef0 100644 --- a/packages/console/src/components/AppContent/index.module.scss +++ b/packages/console/src/components/AppContent/index.module.scss @@ -7,6 +7,7 @@ .light { --color-card-background: #fff; + --color-surface: #fbfdfd; --color-on-surface: #eff1f1; --color-on-surface-variant: #47464e; --color-primary: #4f37f9; @@ -31,12 +32,14 @@ --color-neutral-70: #a9acac; --color-neutral-90: #e0e3e3; --color-on-secondary-container: #201c00; + --color-component-border: #c4c7c7; --color-component-caption: #747778; --color-component-text: #191c1d; --color-outline: #78767f; --color-table-row-selected: rgba(0, 0, 0, 2%); --color-text-default: #202223; --color-foggy: #888; + --color-disabled: #c4c7c7; } $font-family: 'SF UI Text', 'SF Pro Display', sans-serif; @@ -47,6 +50,7 @@ $font-family: 'SF UI Text', 'SF Pro Display', sans-serif; --font-heading-small: 600 24px/32px #{$font-family}; --font-heading: 600 16px/24px #{$font-family}; --font-body: normal 16px/22px #{$font-family}; + --font-body-2: normal 14px/20px #{$font-family}; --font-small-text: normal 12px/16px #{$font-family}; --font-caption: normal 14px/20px #{$font-family}; --font-caption-bold: 600 14px/20px #{$font-family}; diff --git a/packages/console/src/components/Button/index.tsx b/packages/console/src/components/Button/index.tsx index cd6af9a6d..9459936c4 100644 --- a/packages/console/src/components/Button/index.tsx +++ b/packages/console/src/components/Button/index.tsx @@ -6,18 +6,25 @@ import { useTranslation } from 'react-i18next'; import * as styles from './index.module.scss'; type Props = Omit, 'type' | 'size' | 'title'> & { + htmlType?: 'button' | 'submit' | 'reset'; title: I18nKey; type?: 'primary' | 'danger'; size?: 'small' | 'medium' | 'large'; }; -const Button = ({ type = 'primary', size = 'medium', title, ...rest }: Props) => { +const Button = ({ + htmlType = 'button', + type = 'primary', + size = 'medium', + title, + ...rest +}: Props) => { const { t } = useTranslation(); return ( + + + + + + +
+
); diff --git a/packages/console/src/pages/Applications/components/TypeDescription/index.module.scss b/packages/console/src/pages/Applications/components/TypeDescription/index.module.scss index bc9495a78..a16d35b4d 100644 --- a/packages/console/src/pages/Applications/components/TypeDescription/index.module.scss +++ b/packages/console/src/pages/Applications/components/TypeDescription/index.module.scss @@ -7,7 +7,7 @@ } .subtitle { - font: var(--font-body); + font: var(--font-body-2); color: var(--color-text-default); } diff --git a/packages/console/src/pages/Applications/index.tsx b/packages/console/src/pages/Applications/index.tsx index e29f75c41..d516df885 100644 --- a/packages/console/src/pages/Applications/index.tsx +++ b/packages/console/src/pages/Applications/index.tsx @@ -1,4 +1,5 @@ import { Application } from '@logto/schemas'; +import { conditional } from '@silverhand/essentials/lib/utilities/conditional.js'; import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import Modal from 'react-modal'; @@ -20,7 +21,7 @@ import * as styles from './index.module.scss'; const Applications = () => { const [isCreateFormOpen, setIsCreateFormOpen] = useState(false); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data, error } = useSWR('/api/applications'); + const { data, error, mutate } = useSWR('/api/applications'); const isLoading = !data && !error; return ( @@ -39,8 +40,12 @@ const Applications = () => { overlayClassName={modalStyles.overlay} > { + onClose={(createdApp) => { setIsCreateFormOpen(false); + + if (createdApp) { + void mutate(conditional(data && [...data, createdApp])); + } }} /> diff --git a/packages/console/src/scss/modal.module.scss b/packages/console/src/scss/modal.module.scss index c32410973..f2075912a 100644 --- a/packages/console/src/scss/modal.module.scss +++ b/packages/console/src/scss/modal.module.scss @@ -2,7 +2,7 @@ position: absolute; left: 50%; top: 50%; - transform: translateX(-50%, -50%); + transform: translate(-50%, -50%); outline: none; } diff --git a/packages/phrases/src/locales/en.ts b/packages/phrases/src/locales/en.ts index 4e2dac9c1..98316b6c1 100644 --- a/packages/phrases/src/locales/en.ts +++ b/packages/phrases/src/locales/en.ts @@ -50,7 +50,8 @@ const translation = { 'Setup a mobile, single page or traditional application to use Logto for authentication.', create: 'Create Application', application_name: 'Application Name', - select_application_type: 'Select an application type', + application_description: 'Application Description', + select_application_type: 'Select an Application Type', client_id: 'Client ID', type: { native: { diff --git a/packages/phrases/src/locales/zh-cn.ts b/packages/phrases/src/locales/zh-cn.ts index c9b13ba89..0e4fd888e 100644 --- a/packages/phrases/src/locales/zh-cn.ts +++ b/packages/phrases/src/locales/zh-cn.ts @@ -52,6 +52,7 @@ const translation = { 'Setup a mobile, single page or traditional application to use Logto for authentication.', create: 'Create Application', application_name: 'Application Name', + application_description: 'Application Description', select_application_type: 'Select an application type', client_id: 'Client ID', type: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3224953ea..c6404e0f3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,6 +37,7 @@ importers: eslint: ^8.10.0 i18next: ^21.6.12 i18next-browser-languagedetector: ^6.1.3 + ky: ^0.30.0 lint-staged: ^11.1.1 lodash.kebabcase: ^4.1.1 parcel: ^2.3.1 @@ -59,6 +60,7 @@ importers: classnames: 2.3.1 i18next: 21.6.12 i18next-browser-languagedetector: 6.1.3 + ky: 0.30.0 lodash.kebabcase: 4.1.1 react: 17.0.2 react-dom: 17.0.2_react@17.0.2 @@ -8770,6 +8772,11 @@ packages: engines: {node: '>=12'} dev: false + /ky/0.30.0: + resolution: {integrity: sha512-X/u76z4JtDVq10u1JA5UQfatPxgPaVDMYTrgHyiTpGN2z4TMEJkIHsoSBBSg9SWZEIXTKsi9kHgiQ9o3Y/4yog==} + engines: {node: '>=12'} + dev: false + /lerna/4.0.0: resolution: {integrity: sha512-DD/i1znurfOmNJb0OBw66NmNqiM8kF6uIrzrJ0wGE3VNdzeOhz9ziWLYiRaZDGGwgbcjOo6eIfcx9O5Qynz+kg==} engines: {node: '>= 10.18.0'}