From 8fee9c6bb8b97063bd2264ad44f993ea33c3befe Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 5 Apr 2022 11:43:28 +0200 Subject: [PATCH] (ui) select authentication provier type --- .../authentication-provider/provider-form.tsx | 20 ++++- .../components/base/fab-multi-select.tsx | 50 ++++++++++++ .../javascript/components/base/fab-select.tsx | 53 ++++++++++--- app/frontend/src/stylesheets/application.scss | 3 +- .../stylesheets/modules/base/fab-select.scss | 79 +++++++++++++++++++ 5 files changed, 191 insertions(+), 14 deletions(-) create mode 100644 app/frontend/src/javascript/components/base/fab-multi-select.tsx create mode 100644 app/frontend/src/stylesheets/modules/base/fab-select.scss diff --git a/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx b/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx index 4d1e426b3..cfd6c9d9f 100644 --- a/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx +++ b/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx @@ -6,9 +6,17 @@ import { Loader } from '../base/loader'; import { IApplication } from '../../models/application'; import { RHFInput } from '../base/rhf-input'; import { useTranslation } from 'react-i18next'; +import { FabSelect } from '../base/fab-select'; declare const Application: IApplication; +// list of supported authentication methods +const METHODS = { + DatabaseProvider: 'local_database', + OAuth2Provider: 'o_auth2', + OpenIdConnectProvider: 'openid_connect' +}; + interface ProviderFormProps { action: 'create' | 'update', provider?: AuthenticationProvider, @@ -16,8 +24,10 @@ interface ProviderFormProps { onSuccess: (message: string) => void, } +type selectProvidableTypeOption = { value: string, label: string }; + export const ProviderForm: React.FC = ({ action, provider, onError, onSuccess }) => { - const { handleSubmit, register } = useForm({ defaultValues: { ...provider } }); + const { handleSubmit, register, control } = useForm({ defaultValues: { ...provider } }); const { t } = useTranslation('shared'); const onSubmit: SubmitHandler = (data: AuthenticationProvider) => { @@ -28,9 +38,17 @@ export const ProviderForm: React.FC = ({ action, provider, on } }; + const buildProvidableTypeOptions = (): Array => { + return Object.keys(METHODS).map((method: string) => { + return { value: method, label: t(`app.shared.authentication.${METHODS[method]}`) }; + }); + }; + return (
+ + ); }; diff --git a/app/frontend/src/javascript/components/base/fab-multi-select.tsx b/app/frontend/src/javascript/components/base/fab-multi-select.tsx new file mode 100644 index 000000000..077b69b39 --- /dev/null +++ b/app/frontend/src/javascript/components/base/fab-multi-select.tsx @@ -0,0 +1,50 @@ +import React, { SelectHTMLAttributes } from 'react'; +import Select from 'react-select'; +import { Controller, Path } from 'react-hook-form'; +import { Control } from 'react-hook-form/dist/types/form'; +import { FieldValues } from 'react-hook-form/dist/types/fields'; +import { FieldPath } from 'react-hook-form/dist/types/path'; +import { FieldPathValue, UnpackNestedValue } from 'react-hook-form/dist/types'; + +interface FabSelectProps extends SelectHTMLAttributes { + id: string, + label?: string, + className?: string, + control: Control, + placeholder?: string, + options: Array>, + valuesDefault?: Array, +} + +/** + * Option format, expected by react-select + * @see https://github.com/JedWatson/react-select + */ +type selectOption = { value: TOptionValue, label: string }; + +/** + * This component is a wrapper around react-select to use with react-hook-form. + * It is a multi-select component. + */ +export const FabMultiSelect = ({ id, label, className, control, placeholder, options, valuesDefault }: FabSelectProps) => { + return ( +