mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor(modal,edition-label): make Modal onSubmit optional and centralize modal props
- Make Modal.onSubmit and ModalFooter.onSubmit optional and use safe optional chaining when invoking - Extract modalSubmitButtonText, modalOnSubmit, modalIsLoading, and modalDisableSubmitButton in EditionLabel to simplify JSX and reduce inline conditional logic
This commit is contained in:
@@ -304,6 +304,32 @@ const EditionLabel: FunctionComponent<ComponentProps> = (
|
||||
}
|
||||
};
|
||||
|
||||
const shouldShowEnterpriseValidationButton: boolean =
|
||||
IS_ENTERPRISE_EDITION && !licenseValid;
|
||||
|
||||
const modalSubmitButtonText: string | undefined = IS_ENTERPRISE_EDITION
|
||||
? shouldShowEnterpriseValidationButton
|
||||
? "Validate License"
|
||||
: undefined
|
||||
: "Talk to Sales";
|
||||
|
||||
const modalOnSubmit: (() => void) | undefined = IS_ENTERPRISE_EDITION
|
||||
? shouldShowEnterpriseValidationButton
|
||||
? handleValidateClick
|
||||
: undefined
|
||||
: handlePrimaryAction;
|
||||
|
||||
const modalIsLoading: boolean =
|
||||
IS_ENTERPRISE_EDITION && shouldShowEnterpriseValidationButton
|
||||
? isValidating
|
||||
: false;
|
||||
|
||||
const modalDisableSubmitButton: boolean | undefined = IS_ENTERPRISE_EDITION
|
||||
? shouldShowEnterpriseValidationButton
|
||||
? !licenseKeyInput.trim() || isValidating || isConfigLoading
|
||||
: undefined
|
||||
: false;
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
@@ -326,21 +352,13 @@ const EditionLabel: FunctionComponent<ComponentProps> = (
|
||||
{isDialogOpen && (
|
||||
<Modal
|
||||
title={editionName}
|
||||
submitButtonText={
|
||||
IS_ENTERPRISE_EDITION ? "Validate License" : "Talk to Sales"
|
||||
}
|
||||
submitButtonText={modalSubmitButtonText}
|
||||
closeButtonText="Close"
|
||||
onClose={closeDialog}
|
||||
onSubmit={
|
||||
IS_ENTERPRISE_EDITION ? handleValidateClick : handlePrimaryAction
|
||||
}
|
||||
onSubmit={modalOnSubmit}
|
||||
modalWidth={ModalWidth.Large}
|
||||
isLoading={IS_ENTERPRISE_EDITION ? isValidating : false}
|
||||
disableSubmitButton={
|
||||
IS_ENTERPRISE_EDITION
|
||||
? !licenseKeyInput.trim() || isValidating || isConfigLoading
|
||||
: false
|
||||
}
|
||||
isLoading={modalIsLoading}
|
||||
disableSubmitButton={modalDisableSubmitButton}
|
||||
isBodyLoading={IS_ENTERPRISE_EDITION ? isConfigLoading : false}
|
||||
>
|
||||
<div className="space-y-3 text-sm text-gray-600">
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface ComponentProps {
|
||||
children: Array<ReactElement> | ReactElement;
|
||||
onClose?: undefined | (() => void);
|
||||
submitButtonText?: undefined | string;
|
||||
onSubmit: () => void;
|
||||
onSubmit?: (() => void) | undefined;
|
||||
submitButtonStyleType?: undefined | ButtonStyleType;
|
||||
submitButtonType?: undefined | ButtonType;
|
||||
closeButtonStyleType?: undefined | ButtonStyleType;
|
||||
|
||||
@@ -5,7 +5,7 @@ import React, { FunctionComponent, ReactElement } from "react";
|
||||
export interface ComponentProps {
|
||||
onClose?: undefined | (() => void) | undefined;
|
||||
submitButtonText?: undefined | string;
|
||||
onSubmit: () => void;
|
||||
onSubmit?: (() => void) | undefined;
|
||||
submitButtonStyleType?: undefined | ButtonStyleType;
|
||||
closeButtonStyleType?: undefined | ButtonStyleType;
|
||||
submitButtonType?: undefined | ButtonType;
|
||||
@@ -30,7 +30,7 @@ const ModalFooter: FunctionComponent<ComponentProps> = (
|
||||
props.submitButtonText ? props.submitButtonText : "Save Changes"
|
||||
}
|
||||
onClick={() => {
|
||||
props.onSubmit();
|
||||
props.onSubmit?.();
|
||||
}}
|
||||
disabled={props.disableSubmitButton || false}
|
||||
isLoading={props.isLoading || false}
|
||||
|
||||
Reference in New Issue
Block a user