Skip to content

Commit

Permalink
clean up modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ciyer committed Jan 14, 2025
1 parent 413588c commit 162d42e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.modalBody {
max-height: 75vh;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
import cx from "classnames";
import { useCallback, useEffect, useState } from "react";

import { FileEarmarkText, Pencil } from "react-bootstrap-icons";
import { FileEarmarkText, Pencil, XLg } from "react-bootstrap-icons";
import {
Button,
Card,
CardBody,
CardHeader,
Form,
Modal,
ModalBody,
ModalHeader,
ModalFooter,
Expand All @@ -37,8 +36,9 @@ import { RtkOrNotebooksError } from "../../../../components/errors/RtkErrorAlert
import TextAreaInput from "../../../../components/form-field/TextAreaInput.tsx";
import { Loader } from "../../../../components/Loader";
import LazyRenkuMarkdown from "../../../../components/markdown/LazyRenkuMarkdown";
import ScrollableModal from "../../../../components/modal/ScrollableModal";

import styles from "../../../dataConnectorsV2/components/DataConnectorModal/DataConnectorModal.module.scss";
import styles from "./Documentation.module.scss";
import PermissionsGuard from "../../../permissionsV2/PermissionsGuard";
import { Project } from "../../../projectsV2/api/projectV2.api";
import { usePatchProjectsByProjectIdMutation } from "../../../projectsV2/api/projectV2.enhanced-api";
Expand Down Expand Up @@ -117,12 +117,12 @@ interface DocumentationModalProps extends DocumentationProps {
function DocumentationModal({
isOpen,
project,
toggle: originalToggle,
toggle,
}: DocumentationModalProps) {
const [updateProject, result] = usePatchProjectsByProjectIdMutation();
const { isSuccess, isLoading, error } = result;

const { control, handleSubmit, getValues, register } =
const { control, handleSubmit, getValues, register, reset } =
useForm<DocumentationForm>({
defaultValues: {
documentation: project.documentation || "",
Expand All @@ -139,24 +139,27 @@ function DocumentationModal({
[project.etag, project.id, updateProject]
);

const toggle = () => {
result.reset();
originalToggle();
};
useEffect(() => {
if (!isOpen) {
reset();
result.reset();
}
}, [isOpen, reset, result]);

useEffect(() => {
if (result.isSuccess) {
toggle();
}
}, [result.isSuccess, toggle]);

const documentationField = register("documentation");
return (
<Modal
<ScrollableModal
backdrop="static"
centered
className={styles.modal}
data-cy="project-documentation-modal"
fullscreen="lg"
id={"project-documentation-modal"}
isOpen={isOpen}
scrollable
size="lg"
unmountOnClose={false}
toggle={toggle}
>
<ModalHeader toggle={toggle} data-cy="project-documentation-modal-header">
Expand All @@ -166,7 +169,10 @@ function DocumentationModal({
</div>
</ModalHeader>
<Form noValidate onSubmit={handleSubmit(onSubmit)}>
<ModalBody data-cy="project-documentation-modal-body">
<ModalBody
data-cy="project-documentation-modal-body"
className={styles.modalBody}
>
<div className="mb-3">
<TextAreaInput<DocumentationForm>
control={control}
Expand All @@ -185,13 +191,13 @@ function DocumentationModal({
data-cy="project-documentation-modal-footer"
>
<Button
color="outline-danger"
color="outline-primary"
className="me-2"
onClick={() => {
toggle();
}}
>
Discard
<XLg className={cx("bi", "me-1")} /> Close
</Button>
<Button color="primary" disabled={isLoading} type="submit">
{isLoading ? (
Expand All @@ -203,6 +209,6 @@ function DocumentationModal({
</Button>
</ModalFooter>
</Form>
</Modal>
</ScrollableModal>
);
}

0 comments on commit 162d42e

Please sign in to comment.