Skip to content

Commit

Permalink
refactoring more
Browse files Browse the repository at this point in the history
  • Loading branch information
radhikav1 committed Sep 12, 2023
1 parent 3b39039 commit d402941
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions app/cdap/components/NamespaceAdmin/ServiceAccounts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ const ServiceAccountsView = ({ serviceacnts }) => {
confirmFn={deleteHanlder}
cancelFn={closeDeleteConfirmation}
isOpen={isDeleteModalOpen}
errorMessage={deleteErrorMsg}
severity="error"
statusMessage={deleteErrorMsg}
extendedMessage={extendedErrorMsg}
></ConfirmDialog>
);
Expand Down Expand Up @@ -180,7 +181,8 @@ const ServiceAccountsView = ({ serviceacnts }) => {
cancelFn={handleClose}
disableAction={!selectedServiceAcnt ? true : false}
isOpen={open}
errorMessage={saveErrorMsg}
severity="error"
statusMessage={saveErrorMsg}
extendedMessage={saveErrorDetails}
></ConfirmDialog>
);
Expand Down
25 changes: 16 additions & 9 deletions app/cdap/components/shared/ConfirmDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import React, { ReactElement, ReactNode, useState } from 'react';
import isObject from 'lodash/isObject';
import T from 'i18n-react';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import DialogActions from '@material-ui/core/DialogActions';
Expand All @@ -36,7 +35,8 @@ interface IConfirmDialogProps {
confirmFn: (arg0: any) => void;
confirmationElem?: string | ReactNode | ReactElement;
confirmationText?: string | ReactNode;
errorMessage?: string | ReactNode;
severity?: 'success' | 'info' | 'warning' | 'error';
statusMessage?: string | ReactNode;
extendedMessage?: { response: string };
disableAction?: boolean;
}
Expand All @@ -50,12 +50,24 @@ export const ConfirmDialog = ({
confirmFn,
confirmationElem,
confirmationText,
errorMessage,
severity,
statusMessage,
extendedMessage,
disableAction,
}: IConfirmDialogProps) => {
const [isExpanded, setIsExpanded] = useState(false);

const showStatusMessage = () => {
if (statusMessage) {
return (
<StyledAlert severity={severity}>
{statusMessage}
{getExtendedMessage()}
</StyledAlert>
);
}
};

const handleToggleExtendedMessage = () => {
setIsExpanded(!isExpanded);
};
Expand Down Expand Up @@ -89,12 +101,7 @@ export const ConfirmDialog = ({
return (
<StyledDialog open={isOpen} fullWidth>
<DialogTitle>{headerTitle}</DialogTitle>
{errorMessage && (
<StyledAlert severity="error">
{errorMessage}
{getExtendedMessage()}
</StyledAlert>
)}
{showStatusMessage()}
<DialogContent>
{confirmationText}
{confirmationElem}
Expand Down

0 comments on commit d402941

Please sign in to comment.