import * as React from 'react'; import { Box, Center, Heading, Select, Spinner } from '@chakra-ui/react'; import { Formik, FormikProps } from 'formik'; import { useTranslation } from 'react-i18next'; import * as Yup from 'yup'; import GlobalReachAccountField from './GlobalReachAccountField'; import { GlobalReachAccount, useGetGlobalReachCertificates } from 'hooks/Network/GlobalReach'; type Props = { formRef: React.Ref>> | undefined; finishStep: (v: Record) => void; accounts: GlobalReachAccount[]; }; const CreateRadiusEndpointGlobalReachStep = ({ formRef, finishStep, accounts }: Props) => { const { t } = useTranslation(); const [selectedAccount, setSelectedAccount] = React.useState(accounts[0] as GlobalReachAccount); const getCertificates = useGetGlobalReachCertificates(selectedAccount.id); const FormSchema = React.useMemo( () => Yup.object() .shape({ Accounts: Yup.array() .of( Yup.object().shape({ UseOpenRoamingAccount: Yup.string().required(t('form.required')).default(''), Weight: Yup.number().required(t('form.required')).min(0).max(500).default(0), }), ) .min(1, 'Must select at least one account') .required(t('form.required')) .default([]), }) .default([]), [t], ); type FormValues = Yup.InferType; const initialValues: FormValues = FormSchema.cast({}); return ( | null) => void} initialValues={initialValues} validateOnMount validationSchema={FormSchema} onSubmit={async (values: FormValues) => { await finishStep({ RadsecServers: values.Accounts, }); }} > {({ isSubmitting }) => ( What Global Reach account would like to use? Please choose one or more certificates to use: {getCertificates.data ? ( ) : (
)}
)}
); }; export default CreateRadiusEndpointGlobalReachStep;