|
| 1 | +import {ButtonGroup} from '@utrecht/button-group-react'; |
| 2 | +import {LinkButton as UtrechtButtonLink} from '@utrecht/component-library-react'; |
| 3 | +import PropTypes from 'prop-types'; |
| 4 | + |
| 5 | +import AbortButton from 'components/AbortButton'; |
| 6 | +import {OFButton} from 'components/Button'; |
| 7 | +import FAIcon from 'components/FAIcon'; |
| 8 | +import {Literal} from 'components/Literal'; |
| 9 | +import Loader from 'components/Loader'; |
| 10 | +import PreviousLink from 'components/PreviousLink'; |
| 11 | +import {SUBMISSION_ALLOWED} from 'components/constants'; |
| 12 | + |
| 13 | +const ButtonsGroup = ({ |
| 14 | + canSubmitStep, |
| 15 | + canSubmitForm, |
| 16 | + canSuspendForm, |
| 17 | + isLastStep, |
| 18 | + isCheckingLogic, |
| 19 | + isAuthenticated, |
| 20 | + hideAbortButton, |
| 21 | + onNavigatePrevPage, |
| 22 | + onFormSave, |
| 23 | + previousPage, |
| 24 | + onDestroySession, |
| 25 | +}) => { |
| 26 | + const showSubmitButton = !(canSubmitForm === SUBMISSION_ALLOWED.noWithoutOverview && isLastStep); |
| 27 | + |
| 28 | + return ( |
| 29 | + <ButtonGroup className="utrecht-button-group--distanced" direction="column"> |
| 30 | + {showSubmitButton && ( |
| 31 | + <OFButton |
| 32 | + type="submit" |
| 33 | + appearance="primary-action-button" |
| 34 | + name="next" |
| 35 | + disabled={!canSubmitStep} |
| 36 | + className="openforms-button-with-icon" |
| 37 | + > |
| 38 | + {isCheckingLogic ? ( |
| 39 | + <Loader modifiers={['centered', 'only-child', 'small', 'gray']} /> |
| 40 | + ) : ( |
| 41 | + <> |
| 42 | + <Literal name="nextText" /> |
| 43 | + <FAIcon icon="arrow-right-long" /> |
| 44 | + </> |
| 45 | + )} |
| 46 | + </OFButton> |
| 47 | + )} |
| 48 | + |
| 49 | + {previousPage && ( |
| 50 | + <PreviousLink to={previousPage} onClick={onNavigatePrevPage} position="end" /> |
| 51 | + )} |
| 52 | + |
| 53 | + {/* TODO: refactor: `const canSuspendForm = onFormSave === undefined` - this does not |
| 54 | + need to be its own prop */} |
| 55 | + {canSuspendForm && ( |
| 56 | + <UtrechtButtonLink |
| 57 | + name="save" |
| 58 | + onClick={onFormSave} |
| 59 | + className="utrecht-link-button--openforms" |
| 60 | + > |
| 61 | + <FAIcon icon="arrow-right-long" /> |
| 62 | + <Literal name="saveText" /> |
| 63 | + </UtrechtButtonLink> |
| 64 | + )} |
| 65 | + |
| 66 | + {!hideAbortButton && ( |
| 67 | + <AbortButton isAuthenticated={isAuthenticated} onDestroySession={onDestroySession} /> |
| 68 | + )} |
| 69 | + </ButtonGroup> |
| 70 | + ); |
| 71 | +}; |
| 72 | + |
| 73 | +ButtonsGroup.propTypes = { |
| 74 | + canSubmitStep: PropTypes.bool.isRequired, |
| 75 | + canSubmitForm: PropTypes.string.isRequired, |
| 76 | + canSuspendForm: PropTypes.bool.isRequired, |
| 77 | + isLastStep: PropTypes.bool.isRequired, |
| 78 | + isCheckingLogic: PropTypes.bool.isRequired, |
| 79 | + isAuthenticated: PropTypes.bool.isRequired, |
| 80 | + hideAbortButton: PropTypes.bool, |
| 81 | + onNavigatePrevPage: PropTypes.func, |
| 82 | + onFormSave: PropTypes.func.isRequired, |
| 83 | + previousPage: PropTypes.string, |
| 84 | + onDestroySession: PropTypes.func.isRequired, |
| 85 | +}; |
| 86 | + |
| 87 | +export default ButtonsGroup; |
0 commit comments