import React from 'react'; import { NewSchemaSubjectRaw } from 'redux/interfaces'; import { FormProvider, useForm, Controller } from 'react-hook-form'; import { ErrorMessage } from '@hookform/error-message'; import { clusterSchemaPath } from 'lib/paths'; import { SchemaType } from 'generated-sources'; import { SCHEMA_NAME_VALIDATION_PATTERN } from 'lib/constants'; import { useHistory, useParams } from 'react-router'; import { InputLabel } from 'components/common/Input/InputLabel.styled'; import Input from 'components/common/Input/Input'; import { FormError } from 'components/common/Input/Input.styled'; import Select, { SelectOption } from 'components/common/Select/Select'; import { Button } from 'components/common/Button/Button'; import { Textarea } from 'components/common/Textbox/Textarea.styled'; import PageHeading from 'components/common/PageHeading/PageHeading'; import { schemaAdded, schemasApiClient, } from 'redux/reducers/schemas/schemasSlice'; import { useAppDispatch } from 'lib/hooks/redux'; import { serverErrorAlertAdded } from 'redux/reducers/alerts/alertsSlice'; import { getResponse } from 'lib/errorHandling'; import * as S from './New.styled'; const SchemaTypeOptions: Array = [ { value: SchemaType.AVRO, label: 'AVRO' }, { value: SchemaType.JSON, label: 'JSON' }, { value: SchemaType.PROTOBUF, label: 'PROTOBUF' }, ]; const New: React.FC = () => { const { clusterName } = useParams<{ clusterName: string }>(); const history = useHistory(); const dispatch = useAppDispatch(); const methods = useForm(); const { register, handleSubmit, control, formState: { isDirty, isSubmitting, errors }, } = methods; const onSubmit = React.useCallback( async ({ subject, schema, schemaType }: NewSchemaSubjectRaw) => { try { const resp = await schemasApiClient.createNewSchema({ clusterName, newSchemaSubject: { subject, schema, schemaType }, }); dispatch(schemaAdded(resp)); history.push(clusterSchemaPath(clusterName, subject)); } catch (e) { const err = await getResponse(e as Response); dispatch(serverErrorAlertAdded(err)); } }, [clusterName, dispatch, history] ); return (
Subject *
Schema *