From 875a31ec2ab129df13abf9036ead3922f786187e Mon Sep 17 00:00:00 2001 From: Wang Sijie Date: Tue, 26 Apr 2022 16:50:47 +0800 Subject: [PATCH] feat(console): sign in experience setup others tab (#662) --- .../components/LanguagesForm.tsx | 74 +++++++++++++++++++ .../src/pages/SignInExperience/index.tsx | 8 +- .../src/pages/SignInExperience/types.ts | 13 +++- .../src/pages/SignInExperience/utilities.ts | 20 ++++- packages/phrases/src/locales/en.ts | 9 +-- packages/phrases/src/locales/zh-cn.ts | 9 +-- 6 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 packages/console/src/pages/SignInExperience/components/LanguagesForm.tsx diff --git a/packages/console/src/pages/SignInExperience/components/LanguagesForm.tsx b/packages/console/src/pages/SignInExperience/components/LanguagesForm.tsx new file mode 100644 index 000000000..9fc0978c5 --- /dev/null +++ b/packages/console/src/pages/SignInExperience/components/LanguagesForm.tsx @@ -0,0 +1,74 @@ +import { Language } from '@logto/phrases'; +import React, { useMemo } from 'react'; +import { Controller, useFormContext } from 'react-hook-form'; +import { useTranslation } from 'react-i18next'; + +import FormField from '@/components/FormField'; +import RadioGroup, { Radio } from '@/components/RadioGroup'; +import Select from '@/components/Select'; + +import { LanguageMode, SignInExperienceForm } from '../types'; +import * as styles from './index.module.scss'; + +const LanguagesForm = () => { + const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); + const { watch, control } = useFormContext(); + const mode = watch('languageInfo.mode'); + + const languageOptions = useMemo( + () => [ + { + value: Language.English, + title: t('sign_in_exp.others.languages.languages.english'), + }, + { + value: Language.Chinese, + title: t('sign_in_exp.others.languages.languages.chinese'), + }, + ], + [t] + ); + + return ( + <> +
{t('sign_in_exp.others.languages.title')}
+ + ( + + + + + )} + /> + + {mode === LanguageMode.Auto && ( + + ( + + )} + /> + + )} + + ); +}; + +export default LanguagesForm; diff --git a/packages/console/src/pages/SignInExperience/index.tsx b/packages/console/src/pages/SignInExperience/index.tsx index 43fce14b1..ef8b22ea2 100644 --- a/packages/console/src/pages/SignInExperience/index.tsx +++ b/packages/console/src/pages/SignInExperience/index.tsx @@ -14,6 +14,7 @@ import useApi, { RequestError } from '@/hooks/use-api'; import * as detailsStyles from '@/scss/details.module.scss'; import BrandingForm from './components/BrandingForm'; +import LanguagesForm from './components/LanguagesForm'; import SignInMethodsForm from './components/SignInMethodsForm'; import TermsForm from './components/TermsForm'; import * as styles from './index.module.scss'; @@ -44,10 +45,8 @@ const SignInExperience = () => { } const updatedData = await api - .patch(`/api/applications/${data.id}`, { - json: { - ...formData, - }, + .patch('/api/sign-in-exp', { + json: signInExperienceParser.toRemoteModel(formData), }) .json(); void mutate(updatedData); @@ -82,6 +81,7 @@ const SignInExperience = () => { )} {tab === 'methods' && } + {tab === 'others' && }