-
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.
moved createrequest buttons to their own cmp
- Loading branch information
Showing
2 changed files
with
100 additions
and
79 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...sets/semantic-ui/js/oarepo_requests_ui/record-requests/components/CreateRequestButton.jsx
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,88 @@ | ||
import React from "react"; | ||
import { Button, Confirm } from "semantic-ui-react"; | ||
import { RequestModal, CreateRequestModalContent } from "."; | ||
import { | ||
DirectCreateAndSubmit, | ||
ConfirmModalContextProvider, | ||
} from "@js/oarepo_requests_common"; | ||
import PropTypes from "prop-types"; | ||
|
||
export const CreateRequestButton = ({ | ||
requestType, | ||
isMutating, | ||
buttonIconProps, | ||
header, | ||
}) => { | ||
const { dangerous, has_form: hasForm } = requestType; | ||
const needsDialog = dangerous || hasForm; | ||
|
||
if (!hasForm && dangerous) { | ||
return ( | ||
<ConfirmModalContextProvider requestOrRequestType={requestType}> | ||
{({ confirmDialogProps }) => ( | ||
<> | ||
<DirectCreateAndSubmit | ||
requestType={requestType} | ||
requireConfirmation={dangerous} | ||
isMutating={isMutating} | ||
/> | ||
<Confirm | ||
{...confirmDialogProps} | ||
className="requests dangerous-action-confirmation-modal" | ||
/> | ||
</> | ||
)} | ||
</ConfirmModalContextProvider> | ||
); | ||
} | ||
|
||
if (!hasForm && !dangerous) { | ||
return ( | ||
<ConfirmModalContextProvider requestOrRequestType={requestType}> | ||
{({ confirmDialogProps }) => ( | ||
<> | ||
<DirectCreateAndSubmit | ||
requestType={requestType} | ||
requireConfirmation={false} | ||
isMutating={isMutating} | ||
/> | ||
<Confirm | ||
{...confirmDialogProps} | ||
className="requests dangerous-action-confirmation-modal" | ||
/> | ||
</> | ||
)} | ||
</ConfirmModalContextProvider> | ||
); | ||
} | ||
|
||
if (needsDialog) { | ||
return ( | ||
<RequestModal | ||
requestType={requestType} | ||
header={header} | ||
requestCreationModal | ||
trigger={ | ||
<Button | ||
className={`requests request-create-button ${requestType.type_id}`} | ||
fluid | ||
title={header} | ||
content={header} | ||
disabled={isMutating > 0} | ||
{...buttonIconProps} | ||
/> | ||
} | ||
ContentComponent={CreateRequestModalContent} | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
CreateRequestButton.propTypes = { | ||
requestType: PropTypes.object, | ||
isMutating: PropTypes.number.isRequired, | ||
buttonIconProps: PropTypes.object, | ||
header: PropTypes.string.isRequired, | ||
}; |
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