import React from 'react'; import { NewSchemaSubjectRaw } from 'redux/interfaces'; import { FormProvider, useForm, Controller } from 'react-hook-form'; import { ErrorMessage } from '@hookform/error-message'; import { ClusterNameRoute, clusterSchemaPath, clusterSchemasPath, } from 'lib/paths'; import { SchemaType } from 'generated-sources'; import { SCHEMA_NAME_VALIDATION_PATTERN } from 'lib/constants'; import { useNavigate } from 'react-router-dom'; 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 } from 'redux/reducers/schemas/schemasSlice'; import { useAppDispatch } from 'lib/hooks/redux'; import useAppParams from 'lib/hooks/useAppParams'; import { showServerError } from 'lib/errorHandling'; import { schemasApiClient } from 'lib/api'; 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 } = useAppParams(); const navigate = useNavigate(); const dispatch = useAppDispatch(); const methods = useForm({ mode: 'onChange', defaultValues: { schemaType: SchemaType.AVRO, }, }); const { register, handleSubmit, control, formState: { isDirty, isSubmitting, errors, isValid }, } = methods; const onSubmit = async ({ subject, schema, schemaType, }: NewSchemaSubjectRaw) => { try { const resp = await schemasApiClient.createNewSchema({ clusterName, newSchemaSubject: { subject, schema, schemaType }, }); dispatch(schemaAdded(resp)); navigate(clusterSchemaPath(clusterName, subject)); } catch (e) { showServerError(e as Response); } }; return (
Subject *
Schema *