From dcc0d608cbe5d41fe43352272ad4af41130f069a Mon Sep 17 00:00:00 2001 From: dedenbangkit Date: Wed, 7 Feb 2024 18:50:48 +0700 Subject: [PATCH] Cleanup unused pages --- frontend/src/App.js | 12 -- frontend/src/pages/index.js | 2 - .../pages/questionnaires/Questionnaires.jsx | 188 ----------------- .../questionnaires/QuestionnairesAdmin.jsx | 193 ------------------ frontend/src/pages/questionnaires/style.scss | 43 ---- 5 files changed, 438 deletions(-) delete mode 100644 frontend/src/pages/questionnaires/Questionnaires.jsx delete mode 100644 frontend/src/pages/questionnaires/QuestionnairesAdmin.jsx delete mode 100644 frontend/src/pages/questionnaires/style.scss diff --git a/frontend/src/App.js b/frontend/src/App.js index ddedaf949..b4ee18234 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -9,8 +9,6 @@ import { AddUser, Forms, ManageData, - Questionnaires, - QuestionnairesAdmin, Approvals, ApproversTree, Profile, @@ -192,16 +190,6 @@ const RouteList = () => { path="approvals" element={} /> - } - /> - - } - /> } diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index 6a90eb794..9ecf48ba6 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -6,8 +6,6 @@ export { default as ControlCenter } from "./control-center/ControlCenter"; export { default as Users } from "./users/Users"; export { default as AddUser } from "./add-user/AddUser"; export { default as ManageData } from "./manage-data/ManageData"; -export { default as Questionnaires } from "./questionnaires/Questionnaires"; -export { default as QuestionnairesAdmin } from "./questionnaires/QuestionnairesAdmin"; export { default as Approvals } from "./approvals/Approvals"; export { default as ApproversTree } from "./approvers-tree/ApproversTree"; export { default as Profile } from "./profile/Profile"; diff --git a/frontend/src/pages/questionnaires/Questionnaires.jsx b/frontend/src/pages/questionnaires/Questionnaires.jsx deleted file mode 100644 index fc5ec4e68..000000000 --- a/frontend/src/pages/questionnaires/Questionnaires.jsx +++ /dev/null @@ -1,188 +0,0 @@ -import React, { useMemo, useEffect, useState } from "react"; -import "./style.scss"; -import { - Row, - Col, - Button, - Table, - ConfigProvider, - Checkbox, - Empty, - Space, -} from "antd"; -import { api, store, uiText } from "../../lib"; -import { Breadcrumbs } from "../../components"; -import { reloadData } from "../../util/form"; -import { useNotification } from "../../util/hooks"; - -const Questionnaires = () => { - const { forms, user } = store.useState((s) => s); - const [dataset, setDataset] = useState([]); - const [loading, setLoading] = useState(false); - const { notify } = useNotification(); - - const { language } = store.useState((s) => s); - - const { active: activeLang } = language; - const text = useMemo(() => { - return uiText[activeLang]; - }, [activeLang]); - - const pagePath = [ - { - title: text.controlCenter, - link: "/control-center", - }, - { - title: text.approvalsTitle, - link: "/control-center/approvals", - }, - { - title: text.manageQnApproval, - }, - ]; - - useEffect(() => { - if (forms.length) { - setDataset([...forms]); - } - }, [forms]); - - const columns = [ - { - title: "Questionnaire", - dataIndex: "name", - key: "name", - }, - { - title: "Questionnaire Description", - dataIndex: "description", - render: (cell) => cell || -, - }, - { - title: "National", - render: (row) => ( - { - handleChecked(row.id, 2); - }} - /> - ), - }, - { - title: "County", - render: (row) => ( - { - handleChecked(row.id, 1); - }} - /> - ), - }, - ]; - - const handleChecked = (id, val) => { - const pos = dataset.findIndex((d) => d.id === id); - if (pos !== -1) { - const cloned = JSON.parse(JSON.stringify(dataset)); - cloned[pos].type = val; - setDataset(cloned); - } - }; - - const handleSubmit = () => { - const data = dataset.map((d) => ({ - form_id: d.id, - type: d.type, - })); - setLoading(true); - api - .post("form/type", data) - .then(() => { - setLoading(false); - notify({ - type: "success", - message: "Questionnaires updated", - }); - reloadData(user, dataset); - }) - .catch(() => { - notify({ - type: "error", - message: "Could not update Questionnaires", - }); - setLoading(false); - }); - }; - - const handleChange = () => { - // setCurrentPage(e.current); - }; - - const isPristine = useMemo(() => { - return JSON.stringify(dataset) === JSON.stringify(forms); - }, [dataset, forms]); - - return ( -
-
- - - - - - - - - - - -
-
-
-
- }> - - - - - - - ); -}; - -export default React.memo(Questionnaires); diff --git a/frontend/src/pages/questionnaires/QuestionnairesAdmin.jsx b/frontend/src/pages/questionnaires/QuestionnairesAdmin.jsx deleted file mode 100644 index 4339deae1..000000000 --- a/frontend/src/pages/questionnaires/QuestionnairesAdmin.jsx +++ /dev/null @@ -1,193 +0,0 @@ -import React, { useMemo, useState, useEffect } from "react"; -import "./style.scss"; -import { - Row, - Col, - Table, - ConfigProvider, - Empty, - Checkbox, - Space, - Button, -} from "antd"; -import { api, store } from "../../lib"; -import { Breadcrumbs } from "../../components"; -import { reloadData } from "../../util/form"; -import { useNotification } from "../../util/hooks"; - -const pagePath = [ - { - title: "Control Center", - link: "/control-center", - }, - { - title: "Approvals", - link: "/control-center/approvals", - }, - { - title: "Manage Questionnaires Approvals", - }, -]; - -const QuestionnairesAdmin = () => { - const { forms, levels, user } = store.useState((s) => s); - const [loading, setLoading] = useState(true); - const [saving, setSaving] = useState(false); - const [dataset, setDataset] = useState([]); - const [dataOriginal, setDataOriginal] = useState(""); - const { notify } = useNotification(); - - const columns = useMemo(() => { - const handleChecked = (id, val) => { - const pos = dataset.findIndex((d) => d.form_id === id); - if (pos !== -1) { - const cloned = JSON.parse(JSON.stringify(dataset)); - const exists = dataset[pos].levels?.includes(val); - if (exists) { - cloned[pos].levels = cloned[pos].levels.filter((i) => i !== val); - } else { - cloned[pos].levels.push(val); - } - setDataset(cloned); - } - }; - return [ - { - title: "Questionnaire", - dataIndex: "form_id", - render: (cell) => forms.find((f) => f.id === cell)?.name || "", - }, - { - title: "Questionnaire Description", - dataIndex: "description", - render: (cell) => cell || -, - }, - ].concat( - levels - .filter((lv) => lv.level !== 0) - .map((level) => { - return { - title: level.name, - key: `lvl-${level.level}`, - render: (row) => ( - { - handleChecked(row.form_id, level.level); - }} - /> - ), - }; - }) - ); - }, [levels, forms, dataset]); - - useEffect(() => { - if (forms.length) { - setLoading(true); - api - .get("form/approval-level") - .then((res) => { - setDataset(res.data); - setDataOriginal(JSON.stringify(res.data)); - setLoading(false); - }) - .catch((err) => { - console.error(err); - setLoading(false); - }); - } - }, [forms]); - - const handleChange = () => { - // setCurrentPage(e.current); - }; - - const handleSubmit = () => { - const data = dataset.map((d) => ({ - form_id: d.form_id, - level_id: d.levels, - })); - setSaving(true); - api - .put("form/approval", data) - .then(() => { - setSaving(false); - notify({ - type: "success", - message: "Questionnaires updated", - }); - reloadData(user); - }) - .catch(() => { - notify({ - type: "error", - message: "Could not update Questionnaires", - }); - setSaving(false); - }); - }; - - const isPristine = useMemo(() => { - return JSON.stringify(dataset) === dataOriginal; - }, [dataset, dataOriginal]); - - return ( -
-
- -
- - - - - - - - - - -
-
-
- }> -
- - - - - - ); -}; - -export default React.memo(QuestionnairesAdmin); diff --git a/frontend/src/pages/questionnaires/style.scss b/frontend/src/pages/questionnaires/style.scss deleted file mode 100644 index 4da3029a5..000000000 --- a/frontend/src/pages/questionnaires/style.scss +++ /dev/null @@ -1,43 +0,0 @@ -@import "../../variables"; - -#root { - #questionnaires { - .ant-table { - th, - td { - text-align: center; - } - th { - font-weight: 900; - font-size: 15px; - color: #323132; - } - tr td:nth-child(2) span { - color: #c2c2c7; - } - } - } - #approvers { - .ant-table { - .ant-table-cell > .ant-select { - width: 100%; - .ant-select-selector { - border: 0 none; - .ant-select-selection-item:before { - display: inline-block; - width: 0; - height: 0; - vertical-align: middle; - margin-right: 10px; - content: ""; - width: 0; - height: 0; - border-style: solid; - border-width: 5px 4px 0 4px; - border-color: #4d4d4d transparent transparent transparent; - } - } - } - } - } -}