diff --git a/src/Components/ReportSections/ReportSectionEditForm.jsx b/src/Components/ReportSections/ReportSectionEditForm.jsx deleted file mode 100644 index f68ba83b..00000000 --- a/src/Components/ReportSections/ReportSectionEditForm.jsx +++ /dev/null @@ -1,112 +0,0 @@ -import React, { useState } from "react"; -import Button from "../design/Button/Button"; -import ReactQuill from "react-quill"; -import "react-quill/dist/quill.snow.css"; - -// import axios from "axios"; -// import { useHistory } from "react-router-dom"; -// import { useCurrentOrganization } from "../../Contexts/currentOrganizationContext"; -import countWords from "../../Helpers/countWords"; - -const modules = { - toolbar: [ - [{ header: [1, 2, false] }], - ["bold", "italic", "underline", "strike", "blockquote"], - [ - { list: "ordered" }, - { list: "bullet" }, - { indent: "-1" }, - { indent: "+1" }, - ], - ["clean"], - [{ color: [] }], - ], -}; - -const formats = [ - "header", - "bold", - "italic", - "underline", - "strike", - "blockquote", - "list", - "bullet", - "indent", - "color", -]; - -export default function ReportSectionEditForm(props) { - const { onSubmit, onCancel } = props; - const [newTitle, setNewTitle] = useState(props.title); - const [newQuillText, setNewQuillText] = useState(props.quillText); - const [newSortOrder, _setNewSortOrder] = useState(props.sortOrder); - - const handleSubmit = (event) => { - event.preventDefault(); - onSubmit({ - newTitle, - newQuillText, - newSortOrder, - }); - }; - - const handleCancel = (event) => { - event.preventDefault(); - onCancel(); - }; - - return ( -
-
- - setNewTitle(event.target.value)} - required - /> -
- setNewQuillText(value)} - style={{ backgroundColor: "#fefefe", color: "black" }} - /> -
- -

{countWords(newQuillText)}

-
-
- - -
- - ); -} diff --git a/src/Components/ReportSections/ReportSectionsNew.jsx b/src/Components/ReportSections/ReportSectionsNew.jsx deleted file mode 100644 index 4afd543a..00000000 --- a/src/Components/ReportSections/ReportSectionsNew.jsx +++ /dev/null @@ -1,185 +0,0 @@ -import React, { useState, useEffect } from "react"; -import Button from "../design/Button/Button"; -import ReactQuill from "react-quill"; -import "react-quill/dist/quill.snow.css"; -import { useCurrentOrganization } from "../../Contexts/currentOrganizationContext"; -import { createReportSection } from "../../Services/Organizations/Grants/Reports/ReportSectionsService"; -import { getAllBoilerplates } from "../../Services/Organizations/BoilerplatesService"; - -export default function ReportSectionsNew(props) { - const [quillText, setQuillText] = useState(""); - const [title, setTitle] = useState(""); - const [_text, setText] = useState(""); - const [_sortOrder, setSortOrder] = useState(""); - const [_wordcount, setWordcount] = useState(""); - const [boilerplates, setBoilerplates] = useState([]); - const [currentBoilerplate, setCurrentBoilerplate] = useState(""); - const [suggestions, setSuggestions] = useState([]); - const [searchText, setSearchText] = useState(""); - - const { currentOrganization, organizationClient } = useCurrentOrganization(); - - useEffect(() => { - if (currentOrganization.id) { - getAllBoilerplates(organizationClient) - .then((boilerplates) => { - setBoilerplates(boilerplates); - }) - .catch((error) => { - console.error(error); - }); - } - }, [currentOrganization.id, organizationClient]); - - const clearForm = () => { - setQuillText(""); - setTitle(""); - setText(""); - setSortOrder(""); - setWordcount(0); - setCurrentBoilerplate(""); - }; - - const handleSubmit = (event) => { - event.preventDefault(); - const newReportSection = { - reportId: props.reportId, - title: title, - text: quillText, - sort_order: props.sort_number + 1, - wordcount: countWords(quillText), - }; - createReportSection( - organizationClient, - props.grantId, - props.reportId, - newReportSection - ) - .then((reportSection) => { - if (reportSection.data) { - props.updateReportSections(reportSection); - clearForm(); - } - }) - .catch((error) => { - console.error("section creation error", error); - }); - }; - - const handleSelect = (event) => { - let selectedQuillText = quillText; - selectedQuillText += ` ${event.target.value}`; - setQuillText(selectedQuillText); - }; - - const onTextChanged = (event) => { - const value = event.target.value.toLowerCase(); - let suggestions = []; - if (value.length > 0) { - suggestions = boilerplates.filter((boilerplate) => { - return boilerplate.title.toLowerCase().indexOf(value) !== -1; - }); - } - setSuggestions(suggestions); - setSearchText(value); - }; - - const suggestionSelected = (value) => { - let addQuillText = quillText; - addQuillText += value.text; - setSearchText(""); - setSuggestions([]); - setQuillText(addQuillText); - }; - - const renderSuggestions = () => { - if (suggestions.length === 0) { - return null; - } - return ( -
- {suggestions.map((boilerplate) => ( -
  • suggestionSelected(boilerplate)} - > - {boilerplate.title}, {boilerplate.wordcount} words -
  • - ))} -
    - ); - }; - - const countWords = (string) => { - if (string) { - return string.split(" ").length; - } else { - return 0; - } - }; - - return ( -
    -
    -

    New Report Section:

    -
    -
    -
    -
    - - setTitle(event.target.value)} - required - /> -
    -
    - -
    - - - {renderSuggestions()} -
    - - - {boilerplates.map((boilerplate) => { - return ( - - ); - })} - -
    - - setQuillText(value)} - /> -
    - -

    {countWords(quillText)}

    -
    -
    - -
    - -
    -
    - ); -} diff --git a/src/Components/ReportSections/ReportSectionsShow.jsx b/src/Components/ReportSections/ReportSectionsShow.jsx deleted file mode 100644 index 3c307d90..00000000 --- a/src/Components/ReportSections/ReportSectionsShow.jsx +++ /dev/null @@ -1,138 +0,0 @@ -import React, { useState, useEffect } from "react"; -import Button from "../design/Button/Button"; -import "react-quill/dist/quill.snow.css"; -import { useCurrentOrganization } from "../../Contexts/currentOrganizationContext"; -import ReportSectionEditForm from "./ReportSectionEditForm"; -import countWords from "../../Helpers/countWords"; -import { - getReportSection, - updateReportSection, - // deleteReportSection, -} from "../../Services/Organizations/Grants/Reports/ReportSectionsService"; - -export default function ReportSectionsShow(props) { - const [quillText, setQuillText] = useState(""); - const [_id, setId] = useState(""); - const [title, setTitle] = useState(""); - const [_text, setText] = useState(""); - const [sortOrder, setSortOrder] = useState(""); - const [_wordcount, setWordcount] = useState(""); - const [_reportId, setReportId] = useState(""); - const [isHidden, setIsHidden] = useState(true); - const [loading, setLoading] = useState(true); - const [_newQuillText, setNewQuillText] = useState(""); - const [_newTitle, setNewTitle] = useState(""); - const [_newSortOrder, setNewSortOrder] = useState(""); - - const { currentOrganization, organizationClient } = useCurrentOrganization(); - - const [_show, setShow] = useState(false); - const handleClose = () => setShow(false); - - useEffect(() => { - if (currentOrganization.id) { - const grantId = props.grantId; - const reportId = props.reportId; - const reportSectionId = props.reportSectionId; - getReportSection(organizationClient, grantId, reportId, reportSectionId) - .then((reportSection) => { - setId(reportSection.id); - setTitle(reportSection.title); - setText(reportSection.text); - setQuillText(reportSection.text); - setSortOrder(reportSection.sort_order); - setWordcount(reportSection.wordcount); - setReportId(reportSection.reportId); - setLoading(false); - setNewTitle(reportSection.title); - setNewQuillText(reportSection.text); - setNewSortOrder(reportSection.sort_order); - }) - .catch((error) => { - console.error(error); - }); - } - }, [ - currentOrganization.id, - organizationClient, - props.grantId, - props.reportId, - props.reportSectionId, - ]); - - const toggleHidden = () => { - setIsHidden(!isHidden); - }; - - const handleSubmit = ({ newTitle, newQuillText, newSortOrder }) => { - const grantId = props.grantId; - const reportId = props.reportId; - const reportSectionId = props.reportSectionId; - updateReportSection( - organizationClient, - grantId, - reportId, - reportSectionId, - { - title: newTitle, - text: newQuillText, - sort_order: newSortOrder, - wordcount: countWords(newQuillText), - reportId: reportId, - }, - { headers: { Authorization: `Bearer ${localStorage.token}` } } - ) - .then((reportSection) => { - props.editReportSections(reportSection); - toggleHidden(); - }) - .catch((error) => { - console.error("report section update error", error); - }); - }; - - const handleCancel = () => { - handleClose(); - }; - - if (loading) { - return

    Loading....

    ; - } - return ( -
    -
    -
    -
    {title}
    -

    -

    wordcount: {countWords(quillText)}

    -

    sort order: {sortOrder}

    -
    -
    -
    -
    -
    - {isHidden ? ( - - ) : ( - - )} -
    -
    - {!isHidden ? ( -
    -
    - -
    -
    - ) : null} -
    -
    -
    - ); -} diff --git a/src/Components/ReportSections/ReportSectionsUpdateFinal.jsx b/src/Components/ReportSections/ReportSectionsUpdateFinal.jsx deleted file mode 100644 index 52f3622e..00000000 --- a/src/Components/ReportSections/ReportSectionsUpdateFinal.jsx +++ /dev/null @@ -1,151 +0,0 @@ -import React, { useState, useEffect } from "react"; -import Button from "../design/Button/Button"; -import ReactQuill from "react-quill"; -import "react-quill/dist/quill.snow.css"; -import { useCurrentOrganization } from "../Contexts/currentOrganizationContext"; -import { updateReportSection } from "../Services/Organizations/Grants/Reports/ReportSectionsService"; -import { - deleteGrantSection, - getGrantSection, -} from "../Services/Organizations/Grants/GrantSectionsService"; - -export default function ReportSectionsUpdateFinal(props) { - const [quillText, setQuillText] = useState(""); - const [title, setTitle] = useState(""); - const [isHidden, setIsHidden] = useState(true); - const [_wordcount, setWordcount] = useState(""); - const [_reportId, setReportId] = useState(""); - const [_sort_order, setSortOrder] = useState(""); - const [loading, setLoading] = useState(true); - - const toggleHidden = () => { - setIsHidden(!isHidden); - }; - - const { currentOrganization, organizationClient } = useCurrentOrganization(); - - useEffect(() => { - if (currentOrganization.id) { - getGrantSection( - organizationClient, - props.grantId, - props.reportId, - props.reportSectionId - ) - .then((reportSection) => { - setTitle(reportSection.title); - setQuillText(reportSection.text); - setWordcount(reportSection.wordcount); - setSortOrder(reportSection.sort_order); - setReportId(reportSection.reportId); - setLoading(false); - }) - .catch((error) => console.error(error)); - } - }, [ - currentOrganization.id, - organizationClient, - props.grantId, - props.reportId, - props.reportSectionId, - ]); - - const handleSubmit = (event) => { - event.preventDefault(); - updateReportSection( - organizationClient, - props.grantId, - props.reportId, - props.reportSectionId, - { - title: title, - text: quillText, - sort_order: props.section_sort_order, - wordcount: countWords(quillText), - }, - { headers: { Authorization: `Bearer ${localStorage.token}` } } - ) - .then((reportSection) => { - if (reportSection) { - toggleHidden(); - props.updateReportSections(reportSection); - } - }) - .catch((error) => { - console.error("section update error", error); - }); - }; - - const handleReportSectionDelete = () => { - const grantId = props.match.params.grantId; - const reportId = props.match.params.reportId; - const reportSectionId = props.match.params.reportSectionId; - deleteGrantSection( - organizationClient, - grantId, - reportId, - reportSectionId - ).catch((error) => { - console.error(error); - }); - }; - - const countWords = (string) => { - if (string) { - return string.split(" ").length; - } else { - return 0; - } - }; - - if (loading) { - return

    Loading....

    ; - } - - return ( -
    -
    -
    {props.report_section_title}
    -
    -
    - -
    -
    -
    - {!isHidden ? ( -
    -
    -
    -
    - - setTitle(event.target.value)} - required - /> -
    - setQuillText(value)} - /> -
    - -

    {countWords(quillText)}

    -
    -
    - - - -
    - -
    -
    - ) : null} -
    -
    - ); -} diff --git a/src/Components/Reports/ReportEditForm.jsx b/src/Components/Reports/ReportEditForm.jsx deleted file mode 100644 index d8fd94ad..00000000 --- a/src/Components/Reports/ReportEditForm.jsx +++ /dev/null @@ -1,86 +0,0 @@ -import React, { useState } from "react"; -import Button from "../design/Button/Button"; - -export default function ReportEditForm(props) { - const { onSubmit, onCancel } = props; - const [newTitle, setNewTitle] = useState(props.title); - const [newDeadline, setNewDeadline] = useState(props.deadline); - const [newSubmitted, setNewSubmitted] = useState(props.submitted); - - const handleSubmit = (event) => { - event.preventDefault(); - onSubmit({ - newTitle, - newDeadline, - newSubmitted, - }); - }; - - const handleCancel = (event) => { - event.preventDefault(); - onCancel(); - }; - - return ( -
    -
    - - setNewTitle(event.target.value)} - required - /> -
    -
    - - setNewDeadline(event.target.value)} - required - /> -
    -
    - - setNewSubmitted(event.target.checked)} - /> -
    -
    -
    - - -
    -
    -
    - ); -} diff --git a/src/Components/Reports/ReportsNew.jsx b/src/Components/Reports/ReportsNew.jsx deleted file mode 100644 index 7b870387..00000000 --- a/src/Components/Reports/ReportsNew.jsx +++ /dev/null @@ -1,85 +0,0 @@ -import React, { useState } from "react"; -import Button from "../design/Button/Button"; -import { useCurrentOrganization } from "../../Contexts/currentOrganizationContext"; -import { createGrantReport } from "../../Services/Organizations/Grants/GrantReportsService"; - -export default function ReportsNew(props) { - const [deadline, setDeadline] = useState(""); - const [submitted, _setSubmitted] = useState(false); - const [isHidden, setIsHidden] = useState(true); - const [title, setTitle] = useState(`Report for ${props.grant_title}`); - - const { organizationClient } = useCurrentOrganization(); - - const clearForm = () => { - setDeadline(""); - }; - - const toggleHidden = () => { - setIsHidden(!isHidden); - }; - - const handleSubmit = (event) => { - event.preventDefault(); - const newReport = { - grantId: props.grantId, - title: title, - deadline: deadline, - submitted: submitted, - }; - createGrantReport(organizationClient, props.grantId, newReport) - .then((report) => { - if (report) { - toggleHidden(); - props.updateReports(report); - clearForm(); - } - }) - .catch((error) => { - console.error("report creation error", error); - }); - }; - - return ( -
    - {isHidden ? ( - - ) : ( - - )} -
    -
    - {!isHidden ? ( -
    -
    -
    -
    - - setTitle(event.target.value)} - required - /> -
    -
    - - setDeadline(event.target.value)} - required - /> -
    -
    - -
    -
    -
    -
    - ) : null} -
    - ); -} diff --git a/src/Components/Reports/ReportsShow.css b/src/Components/Reports/ReportsShow.css deleted file mode 100644 index 619f22b8..00000000 --- a/src/Components/Reports/ReportsShow.css +++ /dev/null @@ -1,31 +0,0 @@ -.reports-show { - display: flex; - width: 100%; - } - - .reports-show__content { - flex: 1; - } - - .reports-show__section-list { - list-style: none; - padding-left: 0; - margin: 0; - padding: 0; - } - - .reports-show__sections-container { - padding-top: 3rem; - } - - .reports-show__welcome-alert { - border-radius: 4px; - padding: .8rem 1.4rem; - background-color: var(--primary-text-10); - font-size: var(--font-size-large-1); - } - - .reports-show__paste-boilerplate-popout { - width: 36%; - order: 1; - } \ No newline at end of file diff --git a/src/Components/Reports/ReportsShow.jsx b/src/Components/Reports/ReportsShow.jsx deleted file mode 100644 index 612cd219..00000000 --- a/src/Components/Reports/ReportsShow.jsx +++ /dev/null @@ -1,211 +0,0 @@ -import React, { useState, useEffect, useCallback, useMemo } from "react"; -import { MdAddCircle } from "react-icons/md"; -import { useParams } from "react-router-dom"; -import Button from "../design/Button/Button"; -import Modal from "../design/Modal/Modal"; -import Container from "../design/Container/Container"; -import Hero from "../design/Hero/Hero"; -import { useCurrentOrganization } from "../../Contexts/currentOrganizationContext"; -import * as GrantReportsService from "../../Services/Organizations/Grants/GrantReportsService"; -import { - createReportSection, - updateReportSection, -} from "../../Services/Organizations/Grants/Reports/ReportSectionsService"; -import countSectionWords from "../../Helpers/countSectionWords"; -import countWords from "../../Helpers/countWords"; -import SectionsShow from "../Sections/SectionsShow"; -import SectionForm from "../Sections/SectionForm"; -import SortableElement from "../Elements/SortableElement"; -import StoreSectionAsBoilerplate from "../Sections/StoreSectionAsBoilerplate"; -import "./ReportsShow.css"; -// import { PasteBoilerplateContentPopoutContext } from "../PasteBoilerplateContentPopout/PasteBoilerplateContentPopoutContext"; -// import PasteBoilerplateContentPopout from "../PasteBoilerplateContentPopout/PasteBoilerplateContentPopout"; - -export default function ReportsShow() { - const [report, setReport] = useState(null); - const [loading, setLoading] = useState(true); - const [errors, setErrors] = useState([]); - const [newReportSectionId, setNewReportSectionId] = useState(null); - const [editingReportSectionId, setEditingReportSectionId] = useState(null); - const { currentOrganization, organizationClient } = useCurrentOrganization(); - const totalWordCount = useMemo( - () => - report?.reportSections.reduce( - (total, reportSection) => total + countSectionWords(reportSection), - 0 - ), - [report.reportSections] - ); - - const { grantId, reportId } = useParams(); - // const { isOpen } = useContext(PasteBoilerplateContentPopoutContext); - - const [sectionToStoreAsBoilerplate, setSectionToStoreAsBoilerplate] = - useState(null); - - const getGrantReport = useCallback(() => { - if (!organizationClient) { - return; - } - GrantReportsService.getGrantReport(organizationClient, grantId, reportId) - .then((report) => setReport(report)) - .catch((error) => setErrors([error])) - .finally(() => setLoading(false)); - }, [organizationClient, grantId, reportId]); - - const handleCreateReportSection = ({ - newReportSectionFields, - precedingReportSection, - }) => { - createReportSection(organizationClient, grantId, reportId, { - title: newReportSectionFields.title, - text: newReportSectionFields.html, - grantId, - reportId, - sort_order: precedingReportSection - ? precedingReportSection.sortOrder + 1 - : 0, - wordcount: countWords(newReportSectionFields.text), - }).then(() => { - alert("Report Section created!"); - setNewReportSectionId(null); - return getGrantReport(); - }); - }; - - const handleEditReportSection = (newReportSectionFields) => { - updateReportSection( - organizationClient, - grantId, - newReportSectionFields.id, - { - title: newReportSectionFields.title, - text: newReportSectionFields.html, - wordcount: countWords(newReportSectionFields.text), - } - ).then(() => { - alert("Report Section edited!"); - setEditingReportSectionId(null); - return getGrantReport(); - }); - }; - - useEffect(() => { - getGrantReport(); - }, [getGrantReport]); - - if (errors.length) { - console.error(errors); - return

    Error! {errors.map((error) => error.message)}

    ; - } else if (loading) { - return

    Loading....

    ; - } - - const noReportSectionsContent = newReportSectionId ? ( - - handleCreateReportSection({ newReportSectionFields }) - } - onCancel={() => setNewReportSectionId(null)} - /> - ) : ( - <> -

    - Welcome to your grant! Get started by clicking the Add Section Button - below. -

    - - - ); - - return ( -
    - {/* {isOpen && ( -
    - -
    - )} */} -
    - - - {report.reportSections.length ? ( -
      - {report.reportSections.map((reportSection) => ( - - {editingReportSectionId === reportSection.id ? ( - setEditingReportSectionId(null)} - section={reportSection} - /> - ) : ( - - )} - {newReportSectionId === reportSection.id && ( - - handleCreateReportSection({ - newReportSectionFields, - precedingReportSection: reportSection, - }) - } - onCancel={() => setNewReportSectionId(null)} - /> - )} - - - ))} -
    - ) : ( - noReportSectionsContent - )} -
    -
    - - setSectionToStoreAsBoilerplate(null)} - /> - -
    - ); -} diff --git a/src/Components/design/Sidebar/Sidebar.stories.jsx b/src/Components/design/Sidebar/Sidebar.stories.jsx index c0adcce2..593b037d 100644 --- a/src/Components/design/Sidebar/Sidebar.stories.jsx +++ b/src/Components/design/Sidebar/Sidebar.stories.jsx @@ -16,7 +16,6 @@ export const Sidebar = (props) => ( Dashboard - Reports Grants Boilerplates diff --git a/src/routes/OrganizationRoutes.jsx b/src/routes/OrganizationRoutes.jsx index 7b22e45d..032c0801 100644 --- a/src/routes/OrganizationRoutes.jsx +++ b/src/routes/OrganizationRoutes.jsx @@ -18,8 +18,6 @@ import GrantShow from "../Components/Grants/GrantsShow"; import GrantShowOverview from "../Components/Grants/GrantShowOverview"; import GrantsIndex from "../Components/Grants/GrantsIndex"; import GrantsNew from "../Components/Grants/GrantsNew"; -import ReportsNew from "../Components/Reports/ReportsNew"; -import ReportsShow from "../Components/Reports/ReportsShow"; import RedirectToDashboard from "../Components/Helpers/RedirectToDashboard"; import UserIndexPage from "../pages/UserIndex/UserIndexPage"; import { @@ -131,17 +129,6 @@ export default function OrganizationRoutes() { path="/organizations/:organizationId/grants-new" component={GrantsNew} /> - -