chore: added disabled property to the btn (#2775)

Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com>
This commit is contained in:
GermaVinsmoke 2023-05-24 16:50:09 +05:30 committed by GitHub
parent 2f27908434
commit 708f6dd03f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,7 @@ function ApplyLicenseForm({
licenseRefetch, licenseRefetch,
}: ApplyLicenseFormProps): JSX.Element { }: ApplyLicenseFormProps): JSX.Element {
const { t } = useTranslation(['licenses']); const { t } = useTranslation(['licenses']);
const [loading, setLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [form] = Form.useForm<FormValues>(); const [form] = Form.useForm<FormValues>();
const { featureResponse } = useSelector<AppState, AppReducer>( const { featureResponse } = useSelector<AppState, AppReducer>(
(state) => state.app, (state) => state.app,
@ -31,6 +31,8 @@ function ApplyLicenseForm({
const { notifications } = useNotifications(); const { notifications } = useNotifications();
const key = Form.useWatch('key', form); const key = Form.useWatch('key', form);
const isDisabled = isLoading || !key;
const onFinish = async (values: unknown | { key: string }): Promise<void> => { const onFinish = async (values: unknown | { key: string }): Promise<void> => {
const params = values as { key: string }; const params = values as { key: string };
if (params.key === '' || !params.key) { if (params.key === '' || !params.key) {
@ -41,7 +43,7 @@ function ApplyLicenseForm({
return; return;
} }
setLoading(true); setIsLoading(true);
try { try {
const response = await apply({ const response = await apply({
key: params.key, key: params.key,
@ -66,7 +68,7 @@ function ApplyLicenseForm({
description: t('unexpected_error'), description: t('unexpected_error'),
}); });
} }
setLoading(false); setIsLoading(false);
}; };
return ( return (
@ -85,8 +87,8 @@ function ApplyLicenseForm({
</LicenseInput> </LicenseInput>
<Form.Item> <Form.Item>
<Button <Button
loading={loading} loading={isLoading}
disabled={loading} disabled={isDisabled}
type="primary" type="primary"
htmlType="submit" htmlType="submit"
> >