import { Button, ButtonGroup, TextInput, Field, FieldLabel, FieldRow, FieldError, FieldHint, TextAreaInput, ToggleSwitch, FieldGroup, } from '@rocket.chat/fuselage'; import { ContextualbarScrollableContent } from '@rocket.chat/ui-client'; import { useToastMessageDispatch, useRoute, useEndpoint } from '@rocket.chat/ui-contexts'; import { useCallback, useId } from 'react'; import type { SubmitHandler } from 'react-hook-form'; import { useForm, Controller } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; type OAuthAddAppPayload = { name: string; active: boolean; redirectUri: string; }; const OAuthAddApp = () => { const { t } = useTranslation(); const dispatchToastMessage = useToastMessageDispatch(); const { register, handleSubmit, formState: { errors }, control, } = useForm(); const saveApp = useEndpoint('POST', '/v1/oauth-apps.create'); const router = useRoute('admin-oauth-apps'); const close = useCallback(() => router.push({}), [router]); const onSubmit: SubmitHandler = async (data) => { try { await saveApp(data); close(); dispatchToastMessage({ type: 'success', message: t('Application_added') }); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); } }; const nameField = useId(); const redirectUriField = useId(); return ( {t('Active')} } /> {t('Application_Name')} {t('Give_the_application_a_name_This_will_be_seen_by_your_users')} {errors?.name && {errors.name.message}} {t('Redirect_URI')} {t('After_OAuth2_authentication_users_will_be_redirected_to_this_URL')} {errors?.redirectUri && {t('Required_field', { field: t('Redirect_URI') })}} ); }; export default OAuthAddApp;