-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Decouple form actions from ApplicationForm
Split ApplicationForm into a data hook and view component. Use extracted submit and cancel actions inside Modal's footer. Resolves: #1708 Signed-off-by: Radoslaw Szwajkowski <[email protected]>
- Loading branch information
Showing
5 changed files
with
148 additions
and
40 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
58 changes: 58 additions & 0 deletions
58
client/src/app/pages/applications/components/application-form/application-form-modal.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,58 @@ | ||
import * as React from "react"; | ||
import { Button, ButtonVariant, Modal } from "@patternfly/react-core"; | ||
import { ApplicationForm, useApplicationFormHook } from "./application-form"; | ||
import { Application } from "@app/api/models"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
export interface ApplicationFormModalProps { | ||
application: Application | null; | ||
onClose: () => void; | ||
} | ||
|
||
export const ApplicationFormModal: React.FC<ApplicationFormModalProps> = ({ | ||
application, | ||
onClose, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const formProps = useApplicationFormHook({ application, onClose }); | ||
return ( | ||
<Modal | ||
title={ | ||
application | ||
? t("dialog.title.updateApplication") | ||
: t("dialog.title.newApplication") | ||
} | ||
variant="medium" | ||
isOpen={true} | ||
onClose={onClose} | ||
actions={[ | ||
<Button | ||
key="submit" | ||
id="submit" | ||
aria-label="submit" | ||
variant={ButtonVariant.primary} | ||
isDisabled={formProps.isSubmitDisabled} | ||
onClick={formProps.onSubmit()} | ||
> | ||
{!application ? t("actions.create") : t("actions.save")} | ||
</Button>, | ||
<Button | ||
key="cancel" | ||
id="cancel" | ||
aria-label="cancel" | ||
variant={ButtonVariant.link} | ||
isDisabled={formProps.isCancelDisabled} | ||
onClick={onClose} | ||
> | ||
{t("actions.cancel")} | ||
</Button>, | ||
]} | ||
> | ||
<ApplicationForm | ||
{...formProps} | ||
application={application} | ||
onClose={onClose} | ||
/> | ||
</Modal> | ||
); | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
client/src/app/pages/applications/components/application-form/index.ts
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 |
---|---|---|
@@ -1 +1 @@ | ||
export { ApplicationForm } from "./application-form"; | ||
export { ApplicationFormStandalone as ApplicationForm } from "./application-form"; |