import { Field, Form, Formik } from 'formik'; import { useRouter } from '@uirouter/react'; import { Plus } from 'lucide-react'; import { ContainerInstanceFormValues } from '@/react/azure/types'; import * as notifications from '@/portainer/services/notifications'; import { useUser } from '@/react/hooks/useUser'; import { AccessControlForm } from '@/react/portainer/access-control/AccessControlForm'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { FormControl } from '@@/form-components/FormControl'; import { Input, Select } from '@@/form-components/Input'; import { FormSectionTitle } from '@@/form-components/FormSectionTitle'; import { LoadingButton } from '@@/buttons/LoadingButton'; import { validationSchema } from './CreateContainerInstanceForm.validation'; import { PortsMappingField } from './PortsMappingField'; import { useFormState, useLoadFormState } from './useLoadFormState'; import { getSubscriptionLocations, getSubscriptionResourceGroups, } from './utils'; import { useCreateInstanceMutation } from './useCreateInstanceMutation'; export function CreateContainerInstanceForm() { const environmentId = useEnvironmentId(); const { isAdmin } = useUser(); const { providers, subscriptions, resourceGroups, isLoading } = useLoadFormState(environmentId); const { initialValues, subscriptionOptions } = useFormState( subscriptions, resourceGroups, providers ); const router = useRouter(); const { mutateAsync } = useCreateInstanceMutation( resourceGroups, environmentId ); if (isLoading) { return null; } return ( initialValues={initialValues} validationSchema={() => validationSchema(isAdmin)} onSubmit={onSubmit} validateOnMount validateOnChange enableReinitialize > {({ errors, handleSubmit, isSubmitting, isValid, values, setFieldValue, }) => (
Azure settings Container configuration setFieldValue('ports', value)} errors={errors.ports} />
This will automatically deploy a container with a public IP address
Container Resources setFieldValue('accessControl', values)} values={values.accessControl} errors={errors.accessControl} environmentId={environmentId} />
Deploy the container
)} ); async function onSubmit(values: ContainerInstanceFormValues) { try { await mutateAsync(values); notifications.success('Container successfully created', values.name); router.stateService.go('azure.containerinstances'); } catch (e) { notifications.error('Failure', e as Error, 'Unable to create container'); } } }