NewOrgPage: Disable input validation on keypress (#43132)
* NewOrgPage: migrate API function calls to Redux * disable input validation on keypress
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { getBackendSrv } from '@grafana/runtime';
|
|
||||||
import Page from 'app/core/components/Page/Page';
|
import Page from 'app/core/components/Page/Page';
|
||||||
import { Button, Input, Field, Form } from '@grafana/ui';
|
import { Button, Input, Field, Form } from '@grafana/ui';
|
||||||
import { StoreState } from 'app/types';
|
import { StoreState } from 'app/types';
|
||||||
@@ -8,19 +7,6 @@ import { getNavModel } from '../../core/selectors/navModel';
|
|||||||
import { createOrganization } from './state/actions';
|
import { createOrganization } from './state/actions';
|
||||||
import { getConfig } from 'app/core/config';
|
import { getConfig } from 'app/core/config';
|
||||||
|
|
||||||
const validateOrg = async (orgName: string) => {
|
|
||||||
try {
|
|
||||||
await getBackendSrv().get(`api/orgs/name/${encodeURI(orgName)}`);
|
|
||||||
} catch (error) {
|
|
||||||
if (error.status === 404) {
|
|
||||||
error.isHandled = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return 'Something went wrong';
|
|
||||||
}
|
|
||||||
return 'Organization already exists';
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapStateToProps = (state: StoreState) => {
|
const mapStateToProps = (state: StoreState) => {
|
||||||
return { navModel: getNavModel(state.navIndex, 'global-orgs') };
|
return { navModel: getNavModel(state.navIndex, 'global-orgs') };
|
||||||
};
|
};
|
||||||
@@ -63,7 +49,6 @@ export const NewOrgPage: FC<Props> = ({ navModel, createOrganization }) => {
|
|||||||
placeholder="Org name"
|
placeholder="Org name"
|
||||||
{...register('name', {
|
{...register('name', {
|
||||||
required: 'Organization name is required',
|
required: 'Organization name is required',
|
||||||
validate: async (orgName) => await validateOrg(orgName),
|
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
|||||||
Reference in New Issue
Block a user