forked from spinnaker/deck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): convert confirmation modal to react
- Loading branch information
1 parent
abf39e7
commit a59b2c3
Showing
39 changed files
with
521 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
app/scripts/modules/core/src/confirmationModal/ConfirmModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import React from 'react'; | ||
import { Modal } from 'react-bootstrap'; | ||
|
||
import { TaskMonitor, TaskReason, UserVerification } from 'core/task'; | ||
import { IModalComponentProps, Markdown } from 'core/presentation'; | ||
import { NgReact } from 'core/reactShims'; | ||
import { MultiTaskMonitor } from 'core/task/monitor/MultiTaskMonitor'; | ||
import { ModalClose } from 'core/modal'; | ||
import { PlatformHealthOverride } from 'core/application/modal/PlatformHealthOverride'; | ||
import { IConfirmationModalPassthroughProps } from './confirmationModal.service'; | ||
|
||
export interface IConfirmModalProps extends IModalComponentProps, IConfirmationModalPassthroughProps { | ||
taskMonitor?: TaskMonitor; | ||
taskMonitors?: TaskMonitor[]; | ||
} | ||
|
||
export const ConfirmModal = (props: IConfirmModalProps) => { | ||
const { account, verificationLabel, textToVerify, taskMonitor, taskMonitors, closeModal, dismissModal } = props; | ||
const { useState, useEffect } = React; | ||
|
||
const [isSubmitting, setIsSubmitting] = useState(false); | ||
const [isRetry, setIsRetry] = useState(false); | ||
const [isValid, setIsValid] = useState(!account && !verificationLabel && !textToVerify); | ||
const [error, setError] = useState<{ isError: boolean; message?: string }>({ isError: false }); | ||
|
||
const [reason, setReason] = useState<string>(); | ||
const [interestingHealthProviderNames, setInterestingHealthProviderNames] = useState<string[]>(); | ||
|
||
useEffect(() => { | ||
if (taskMonitor && !taskMonitor.modalInstance) { | ||
taskMonitor.modalInstance = TaskMonitor.modalInstanceEmulation(closeModal, dismissModal); | ||
} | ||
if (taskMonitor?.onTaskRetry) { | ||
const { onTaskRetry } = taskMonitor; | ||
taskMonitor.onTaskRetry = () => { | ||
setIsRetry(true); | ||
setIsSubmitting(false); | ||
onTaskRetry(); | ||
}; | ||
} | ||
}, [taskMonitor]); | ||
|
||
const requiresVerification = account || (verificationLabel && textToVerify); | ||
const isDisabled = isSubmitting || !isValid; | ||
|
||
const showError = (e: string) => { | ||
setError({ isError: true, message: e }); | ||
setIsSubmitting(false); | ||
}; | ||
|
||
const submit = () => { | ||
const { submitMethod, submitJustWithReason } = props; | ||
if (isDisabled) { | ||
return; | ||
} | ||
setIsSubmitting(true); | ||
if (taskMonitors) { | ||
taskMonitors.forEach(m => m.callPreconfiguredSubmit({ reason })); | ||
} else if (taskMonitor) { | ||
taskMonitor.submit(() => { | ||
return submitMethod({ | ||
interestingHealthProviderNames, | ||
reason, | ||
}); | ||
}); | ||
} else if (submitJustWithReason) { | ||
submitMethod({ reason }).then(dismissModal); | ||
} else { | ||
if (submitMethod) { | ||
submitMethod().then(dismissModal, showError); | ||
} else { | ||
closeModal(); | ||
} | ||
} | ||
}; | ||
|
||
const { TaskMonitorWrapper, ButtonBusyIndicator } = NgReact; | ||
const includeBody = | ||
(isRetry && props.retryBody) || | ||
props.bodyContent || | ||
error.isError || | ||
props.platformHealthOnlyShowOverride || | ||
props.askForReason || | ||
props.submitJustWithReason; | ||
|
||
return ( | ||
<div> | ||
<TaskMonitorWrapper monitor={taskMonitor} /> | ||
<MultiTaskMonitor monitors={taskMonitors} title={props.multiTaskTitle} closeModal={dismissModal} /> | ||
<ModalClose dismiss={dismissModal} /> | ||
<Modal.Header> | ||
<Modal.Title>{props.header}</Modal.Title> | ||
</Modal.Header> | ||
{includeBody && ( | ||
<Modal.Body> | ||
{props.bodyContent} | ||
{props.platformHealthOnlyShowOverride && ( | ||
<PlatformHealthOverride | ||
interestingHealthProviderNames={interestingHealthProviderNames} | ||
showHelpDetails={true} | ||
platformHealthType={props.platformHealthType} | ||
onChange={setInterestingHealthProviderNames} | ||
/> | ||
)} | ||
{error.isError && ( | ||
<div className="alert alert-danger"> | ||
<h4>An error occurred:</h4> | ||
<p>{error.message || 'No details provided.'}</p> | ||
</div> | ||
)} | ||
{isRetry && props.retryBody && <Markdown message={props.retryBody} />} | ||
{((taskMonitor || taskMonitors) && props.askForReason) || | ||
(props.submitJustWithReason && <TaskReason reason={reason} onChange={setReason} />)} | ||
</Modal.Body> | ||
)} | ||
<Modal.Footer> | ||
{!isSubmitting && requiresVerification && ( | ||
<UserVerification | ||
onValidChange={setIsValid} | ||
account={account} | ||
expectedValue={textToVerify} | ||
label={verificationLabel} | ||
/> | ||
)} | ||
<button className="btn btn-default" type="button" onClick={dismissModal}> | ||
{props.cancelButtonText} | ||
</button> | ||
<button className="btn btn-primary" type="button" onClick={submit} disabled={isDisabled}> | ||
{isSubmitting && <ButtonBusyIndicator />} | ||
{props.buttonText} | ||
</button> | ||
</Modal.Footer> | ||
</div> | ||
); | ||
}; |
59 changes: 0 additions & 59 deletions
59
app/scripts/modules/core/src/confirmationModal/confirm.html
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.