From 346f3f951c8c296adafdc269c9d3a35dcf4af9bf Mon Sep 17 00:00:00 2001
From: alexd-bes <129009580+alexd-bes@users.noreply.github.com>
Date: Fri, 21 Jun 2024 08:22:19 +1200
Subject: [PATCH 01/50] Create button
---
.../src/views/Tasks/TasksDashboardPage.tsx | 31 +++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/packages/datatrak-web/src/views/Tasks/TasksDashboardPage.tsx b/packages/datatrak-web/src/views/Tasks/TasksDashboardPage.tsx
index 187be21d47..7c2f03c403 100644
--- a/packages/datatrak-web/src/views/Tasks/TasksDashboardPage.tsx
+++ b/packages/datatrak-web/src/views/Tasks/TasksDashboardPage.tsx
@@ -5,7 +5,8 @@
import React from 'react';
import styled from 'styled-components';
-import { PageContainer as BasePageContainer } from '../../components';
+import { Add } from '@material-ui/icons';
+import { PageContainer as BasePageContainer, Button } from '../../components';
import { TaskPageHeader, TasksTable } from '../../features';
const PageContainer = styled(BasePageContainer)`
@@ -17,10 +18,36 @@ const PageContainer = styled(BasePageContainer)`
padding-inline: 3rem;
`;
+const ButtonContainer = styled.div`
+ margin-inline-start: auto;
+ padding-block-end: 0.5rem;
+`;
+
+const CreateButton = styled(Button).attrs({
+ color: 'primary',
+ variant: 'outlined',
+ size: 'small',
+})`
+ padding-inline-end: 1.2rem;
+ // the icon width creates the illusion of more padding on the left, so adjust the padding to compensate
+ padding-inline-start: 0.9rem;
+`;
+
+const AddIcon = styled(Add)`
+ font-size: 1.2rem;
+ margin-inline-end: 0.2rem;
+`;
+
export const TasksDashboardPage = () => {
return (
-
+
+
+
+ Create Task
+
+
+
);
From beddfbefa3bc8dc768bab9ecc084b85081b1e0e2 Mon Sep 17 00:00:00 2001
From: alexd-bes <129009580+alexd-bes@users.noreply.github.com>
Date: Fri, 21 Jun 2024 08:42:52 +1200
Subject: [PATCH 02/50] Move modal to ui-components
---
.../DataLibrary/component/TransformModal.jsx | 2 +-
.../components/Modal/EditModal.jsx | 9 +-
.../Modal/SaveVisualisationModal.jsx | 2 +-
packages/admin-panel/src/editor/EditModal.jsx | 2 +-
.../src/importExport/ExportModal.jsx | 2 +-
.../src/importExport/ImportModal.jsx | 4 +-
packages/admin-panel/src/library.js | 9 +-
.../admin-panel/src/logsTable/LogsModal.jsx | 2 +-
.../admin-panel/src/qrCode/QrCodeModal.jsx | 2 +-
.../src/surveyResponse/FileQuestionField.jsx | 4 +-
.../admin-panel/src/surveyResponse/Form.jsx | 3 +-
.../ResubmitSurveyResponseModal.jsx | 3 +-
.../src/widgets/ConfirmDeleteModal.jsx | 2 +-
packages/admin-panel/src/widgets/index.js | 7 -
.../AdminPanel/components/RejectButton.jsx | 9 +-
.../src/components}/ConfirmModal.jsx | 15 +-
packages/psss/src/components/index.js | 1 +
.../containers/Modals/ArchiveAlertModal.jsx | 2 +-
.../containers/Modals/DeleteAlertModal.jsx | 4 +-
.../src/components/Modal/ImportModal.jsx | 196 ------------------
.../src/components/Modal/Modal.tsx} | 56 ++---
.../Modal/ModalCenteredContent.tsx} | 0
.../Modal/ModalContentProvider.tsx} | 28 ++-
.../src/components/Modal/ModalHeader.tsx} | 24 +--
.../src/components/Modal/index.js | 7 -
.../src/components/Modal/index.ts} | 0
26 files changed, 82 insertions(+), 313 deletions(-)
rename packages/{ui-components/src/components/Modal => psss/src/components}/ConfirmModal.jsx (91%)
delete mode 100644 packages/ui-components/src/components/Modal/ImportModal.jsx
rename packages/{admin-panel/src/widgets/Modal/Modal.jsx => ui-components/src/components/Modal/Modal.tsx} (64%)
rename packages/{admin-panel/src/widgets/Modal/ModalCenteredContent.jsx => ui-components/src/components/Modal/ModalCenteredContent.tsx} (100%)
rename packages/{admin-panel/src/widgets/Modal/ModalContentProvider.jsx => ui-components/src/components/Modal/ModalContentProvider.tsx} (71%)
rename packages/{admin-panel/src/widgets/Modal/ModalHeader.jsx => ui-components/src/components/Modal/ModalHeader.tsx} (66%)
delete mode 100644 packages/ui-components/src/components/Modal/index.js
rename packages/{admin-panel/src/widgets/Modal/index.js => ui-components/src/components/Modal/index.ts} (100%)
diff --git a/packages/admin-panel/src/VizBuilderApp/components/DataLibrary/component/TransformModal.jsx b/packages/admin-panel/src/VizBuilderApp/components/DataLibrary/component/TransformModal.jsx
index 5da6d3715a..687d2cf931 100644
--- a/packages/admin-panel/src/VizBuilderApp/components/DataLibrary/component/TransformModal.jsx
+++ b/packages/admin-panel/src/VizBuilderApp/components/DataLibrary/component/TransformModal.jsx
@@ -7,7 +7,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Dialog } from '@material-ui/core';
import styled from 'styled-components';
-import { ModalHeader } from '../../../../widgets';
+import { ModalHeader } from '@tupaia/ui-components';
const Wrapper = styled.div`
height: 80vh;
diff --git a/packages/admin-panel/src/VizBuilderApp/components/Modal/EditModal.jsx b/packages/admin-panel/src/VizBuilderApp/components/Modal/EditModal.jsx
index 50754fbf48..7fc17101cb 100644
--- a/packages/admin-panel/src/VizBuilderApp/components/Modal/EditModal.jsx
+++ b/packages/admin-panel/src/VizBuilderApp/components/Modal/EditModal.jsx
@@ -4,11 +4,16 @@
*/
import React, { useState } from 'react';
import { useParams } from 'react-router-dom';
-import { Button, Dialog } from '@tupaia/ui-components';
+import {
+ Button,
+ Dialog,
+ ModalContentProvider,
+ ModalFooter,
+ ModalHeader,
+} from '@tupaia/ui-components';
import { DashboardItemMetadataForm } from '../DashboardItem';
import { MapOverlayMetadataForm } from '../MapOverlay';
import { DASHBOARD_ITEM_OR_MAP_OVERLAY_PARAM } from '../../constants';
-import { ModalContentProvider, ModalFooter, ModalHeader } from '../../../widgets';
export const EditModal = () => {
const { dashboardItemOrMapOverlay } = useParams();
diff --git a/packages/admin-panel/src/VizBuilderApp/components/Modal/SaveVisualisationModal.jsx b/packages/admin-panel/src/VizBuilderApp/components/Modal/SaveVisualisationModal.jsx
index 964c2adb75..50dbdb1c53 100644
--- a/packages/admin-panel/src/VizBuilderApp/components/Modal/SaveVisualisationModal.jsx
+++ b/packages/admin-panel/src/VizBuilderApp/components/Modal/SaveVisualisationModal.jsx
@@ -8,11 +8,11 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Link as RouterLink, useParams } from 'react-router-dom';
import Typography from '@material-ui/core/Typography';
+import { Modal, ModalCenteredContent } from '@tupaia/ui-components';
import { DASHBOARD_ITEM_OR_MAP_OVERLAY_PARAM, MODAL_STATUS } from '../../constants';
import { useVisualisationContext, useVizConfigContext } from '../../context';
import { useSaveDashboardVisualisation, useSaveMapOverlayVisualisation } from '../../api';
import { useVizBuilderBasePath } from '../../utils';
-import { Modal, ModalCenteredContent } from '../../../widgets';
const Heading = styled(Typography).attrs({
variant: 'h3',
diff --git a/packages/admin-panel/src/editor/EditModal.jsx b/packages/admin-panel/src/editor/EditModal.jsx
index 55456c1fa9..9c9684dda6 100644
--- a/packages/admin-panel/src/editor/EditModal.jsx
+++ b/packages/admin-panel/src/editor/EditModal.jsx
@@ -8,10 +8,10 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { dismissEditor } from './actions';
import { UsedBy } from '../usedBy/UsedBy';
-import { Modal } from '../widgets';
import { useEditFiles } from './useEditFiles';
import { FieldsEditor } from './FieldsEditor';
import { withConnectedEditor } from './withConnectedEditor';
+import { Modal } from '@tupaia/ui-components';
export const EditModalComponent = withConnectedEditor(
({
diff --git a/packages/admin-panel/src/importExport/ExportModal.jsx b/packages/admin-panel/src/importExport/ExportModal.jsx
index f660e22943..4981584947 100644
--- a/packages/admin-panel/src/importExport/ExportModal.jsx
+++ b/packages/admin-panel/src/importExport/ExportModal.jsx
@@ -5,7 +5,7 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
-import { Modal } from '../widgets';
+import { Modal } from '@tupaia/ui-components';
import { useApiContext } from '../utilities/ApiProvider';
import { ActionButton } from '../editor';
import { ExportIcon } from '../icons';
diff --git a/packages/admin-panel/src/importExport/ImportModal.jsx b/packages/admin-panel/src/importExport/ImportModal.jsx
index b05be99f58..545a43945a 100644
--- a/packages/admin-panel/src/importExport/ImportModal.jsx
+++ b/packages/admin-panel/src/importExport/ImportModal.jsx
@@ -6,8 +6,8 @@
import React, { useState } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
-import { FileUploadField } from '@tupaia/ui-components';
-import { InputField, Modal } from '../widgets';
+import { FileUploadField, Modal } from '@tupaia/ui-components';
+import { InputField } from '../widgets';
import { useApiContext } from '../utilities/ApiProvider';
import { DATA_CHANGE_ERROR, DATA_CHANGE_REQUEST, DATA_CHANGE_SUCCESS } from '../table/constants';
import { checkVisibilityCriteriaAreMet, labelToId } from '../utilities';
diff --git a/packages/admin-panel/src/library.js b/packages/admin-panel/src/library.js
index 35cf466161..5140ac74a7 100644
--- a/packages/admin-panel/src/library.js
+++ b/packages/admin-panel/src/library.js
@@ -31,14 +31,7 @@ export { PrivateRoute } from './authentication';
export { getHasBESAdminAccess } from './utilities/getHasBESAdminAccess';
export * from './pages/resources';
export { ReduxAutocomplete } from './autocomplete';
-export {
- IconButton,
- ModalContentProvider,
- Modal,
- ModalFooter,
- ModalHeader,
- ModalCenteredContent,
-} from './widgets';
+export { IconButton } from './widgets';
export { AdminPanelDataProviders } from './utilities/AdminPanelProviders';
export { useApiContext } from './utilities/ApiProvider';
export { DataChangeAction, ActionButton } from './editor';
diff --git a/packages/admin-panel/src/logsTable/LogsModal.jsx b/packages/admin-panel/src/logsTable/LogsModal.jsx
index 26aa31c849..2a2dffbb3c 100644
--- a/packages/admin-panel/src/logsTable/LogsModal.jsx
+++ b/packages/admin-panel/src/logsTable/LogsModal.jsx
@@ -6,8 +6,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
+import { Modal } from '@tupaia/ui-components';
import { changeLogsTablePage, closeLogsModal } from './actions';
-import { Modal } from '../widgets';
import { LogsTable } from './LogsTable';
export const LogsModalComponent = ({
diff --git a/packages/admin-panel/src/qrCode/QrCodeModal.jsx b/packages/admin-panel/src/qrCode/QrCodeModal.jsx
index ac4546f5cf..c8f2bff785 100644
--- a/packages/admin-panel/src/qrCode/QrCodeModal.jsx
+++ b/packages/admin-panel/src/qrCode/QrCodeModal.jsx
@@ -6,9 +6,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
+import { Modal } from '@tupaia/ui-components';
import { QrCodeContainer } from './QrCodeContainer';
import { closeQrCodeModal } from './actions';
-import { Modal } from '../widgets';
export const QrCodeModalComponent = ({ isOpen, onDismiss, qrCodeContents, humanReadableId }) => {
return (
diff --git a/packages/admin-panel/src/surveyResponse/FileQuestionField.jsx b/packages/admin-panel/src/surveyResponse/FileQuestionField.jsx
index 043ea5755a..00c6332f2d 100644
--- a/packages/admin-panel/src/surveyResponse/FileQuestionField.jsx
+++ b/packages/admin-panel/src/surveyResponse/FileQuestionField.jsx
@@ -7,13 +7,13 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import generateId from 'uuid/v1';
-import { TextField } from '@tupaia/ui-components';
+import { TextField, Modal } from '@tupaia/ui-components';
import { getUniqueFileNameParts } from '@tupaia/utils';
import EditIcon from '@material-ui/icons/Edit';
import DeleteIcon from '@material-ui/icons/Delete';
import ExportIcon from '@material-ui/icons/GetApp';
import { FileUploadField } from '../widgets/InputField/FileUploadField';
-import { IconButton, Modal } from '../widgets';
+import { IconButton } from '../widgets';
import { useApiContext } from '../utilities/ApiProvider';
const Container = styled.div`
diff --git a/packages/admin-panel/src/surveyResponse/Form.jsx b/packages/admin-panel/src/surveyResponse/Form.jsx
index e69f9dcd61..77fbbd9270 100644
--- a/packages/admin-panel/src/surveyResponse/Form.jsx
+++ b/packages/admin-panel/src/surveyResponse/Form.jsx
@@ -5,10 +5,9 @@
import React, { useState, useCallback, useEffect } from 'react';
import PropTypes from 'prop-types';
-import { Button } from '@tupaia/ui-components';
+import { Button, ModalContentProvider, ModalFooter } from '@tupaia/ui-components';
import { Divider } from '@material-ui/core';
import { useGetExistingData } from './useGetExistingData';
-import { ModalContentProvider, ModalFooter } from '../widgets';
import { useResubmitSurveyResponse } from '../api/mutations/useResubmitSurveyResponse';
import { MODAL_STATUS } from './constants';
import { SurveyScreens } from './SurveyScreens';
diff --git a/packages/admin-panel/src/surveyResponse/ResubmitSurveyResponseModal.jsx b/packages/admin-panel/src/surveyResponse/ResubmitSurveyResponseModal.jsx
index c4c1356c06..46a224f765 100644
--- a/packages/admin-panel/src/surveyResponse/ResubmitSurveyResponseModal.jsx
+++ b/packages/admin-panel/src/surveyResponse/ResubmitSurveyResponseModal.jsx
@@ -6,10 +6,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
-import { Dialog } from '@tupaia/ui-components';
+import { Dialog, ModalHeader } from '@tupaia/ui-components';
import { closeResubmitSurveyModal, onAfterMutate as onAfterMutateAction } from './actions';
import { Form } from './Form';
-import { ModalHeader } from '../widgets';
export const ResubmitSurveyResponseModalComponent = ({
isOpen,
diff --git a/packages/admin-panel/src/widgets/ConfirmDeleteModal.jsx b/packages/admin-panel/src/widgets/ConfirmDeleteModal.jsx
index 45199978ae..87189b2a04 100644
--- a/packages/admin-panel/src/widgets/ConfirmDeleteModal.jsx
+++ b/packages/admin-panel/src/widgets/ConfirmDeleteModal.jsx
@@ -7,7 +7,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography';
import styled from 'styled-components';
-import { Modal, ModalCenteredContent } from './Modal';
+import { Modal, ModalCenteredContent } from '@tupaia/ui-components';
const Heading = styled(Typography).attrs({
variant: 'h3',
diff --git a/packages/admin-panel/src/widgets/index.js b/packages/admin-panel/src/widgets/index.js
index 9a011f25cc..60fa40db7b 100644
--- a/packages/admin-panel/src/widgets/index.js
+++ b/packages/admin-panel/src/widgets/index.js
@@ -8,13 +8,6 @@ export { InputField, JsonEditorInputField } from './InputField';
export { Tabs } from './Tabs';
export { PageHeader } from './PageHeader';
export { PageBody, Footer } from '../layout';
-export {
- ModalContentProvider,
- Modal,
- ModalFooter,
- ModalHeader,
- ModalCenteredContent,
-} from './Modal';
export { JsonEditor, JsonTreeEditor } from './JsonEditor';
export { SecondaryNavbar } from '../layout/navigation/SecondaryNavbar';
export { ConfirmDeleteModal } from './ConfirmDeleteModal';
diff --git a/packages/lesmis/src/views/AdminPanel/components/RejectButton.jsx b/packages/lesmis/src/views/AdminPanel/components/RejectButton.jsx
index 1b7c51f31f..943d9f3352 100644
--- a/packages/lesmis/src/views/AdminPanel/components/RejectButton.jsx
+++ b/packages/lesmis/src/views/AdminPanel/components/RejectButton.jsx
@@ -6,15 +6,10 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Typography } from '@material-ui/core';
-import {
- ColumnActionButton,
- DataChangeAction,
- useApiContext,
- Modal,
- ModalCenteredContent,
-} from '@tupaia/admin-panel';
+import { ColumnActionButton, DataChangeAction, useApiContext } from '@tupaia/admin-panel';
import { Delete } from '@material-ui/icons';
import CircularProgress from '@material-ui/core/CircularProgress';
+import { Modal, ModalCenteredContent } from '@tupaia/ui-components';
import { useRejectSurveyResponseStatus } from '../api';
const ConfirmModalHeading = styled(Typography).attrs({
diff --git a/packages/ui-components/src/components/Modal/ConfirmModal.jsx b/packages/psss/src/components/ConfirmModal.jsx
similarity index 91%
rename from packages/ui-components/src/components/Modal/ConfirmModal.jsx
rename to packages/psss/src/components/ConfirmModal.jsx
index dfeb0b7dd1..92ebddd6d0 100644
--- a/packages/ui-components/src/components/Modal/ConfirmModal.jsx
+++ b/packages/psss/src/components/ConfirmModal.jsx
@@ -8,11 +8,16 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import ReportProblem from '@material-ui/icons/ReportProblem';
import Typography from '@material-ui/core/Typography';
-
-import { Button, OutlinedButton } from '../Button';
-import { Dialog, DialogFooter, DialogHeader, DialogContent } from '../Dialog';
-import { LoadingContainer } from '../Loaders';
-import { Alert } from '../Alert';
+import {
+ Alert,
+ Button,
+ Dialog,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ LoadingContainer,
+ OutlinedButton,
+} from '@tupaia/ui-components';
const DescriptionText = styled(Typography)`
font-size: 1rem;
diff --git a/packages/psss/src/components/index.js b/packages/psss/src/components/index.js
index 772b55918d..60cc90c833 100644
--- a/packages/psss/src/components/index.js
+++ b/packages/psss/src/components/index.js
@@ -17,3 +17,4 @@ export * from './FetchLoader';
export * from './Modal';
export * from './AffectedSitesTab';
export * from './ComingSoon';
+export * from './ConfirmModal';
diff --git a/packages/psss/src/containers/Modals/ArchiveAlertModal.jsx b/packages/psss/src/containers/Modals/ArchiveAlertModal.jsx
index b4684ba0a8..68f31fe4e0 100644
--- a/packages/psss/src/containers/Modals/ArchiveAlertModal.jsx
+++ b/packages/psss/src/containers/Modals/ArchiveAlertModal.jsx
@@ -17,11 +17,11 @@ import {
DialogContent,
DialogFooter,
DialogHeader,
- ConfirmModal,
} from '@tupaia/ui-components';
import { useArchiveAlert } from '../../api/queries';
import { AlertsPanelContext } from '../../context';
+import { ConfirmModal } from '../../components';
const TickIcon = styled(CheckCircle)`
font-size: 2.5rem;
diff --git a/packages/psss/src/containers/Modals/DeleteAlertModal.jsx b/packages/psss/src/containers/Modals/DeleteAlertModal.jsx
index 07464c1459..b90ef9124b 100644
--- a/packages/psss/src/containers/Modals/DeleteAlertModal.jsx
+++ b/packages/psss/src/containers/Modals/DeleteAlertModal.jsx
@@ -5,11 +5,9 @@
import React, { useState, useCallback } from 'react';
import PropTypes from 'prop-types';
-
-import { ConfirmModal } from '@tupaia/ui-components';
-
import { useDeleteAlert } from '../../api/queries';
import { SuccessModal } from './SuccessModal';
+import { ConfirmModal } from '../../components';
const STATUS = {
INITIAL: 'initial',
diff --git a/packages/ui-components/src/components/Modal/ImportModal.jsx b/packages/ui-components/src/components/Modal/ImportModal.jsx
deleted file mode 100644
index 287bfc8243..0000000000
--- a/packages/ui-components/src/components/Modal/ImportModal.jsx
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
- */
-
-import Typography from '@material-ui/core/Typography';
-import PropTypes from 'prop-types';
-import React, { useCallback, useState } from 'react';
-import styled from 'styled-components';
-
-import { SmallAlert } from '../Alert';
-import { Button, OutlinedButton } from '../Button';
-import { Dialog, DialogContent, DialogFooter, DialogHeader } from '../Dialog';
-import { FileUploadField } from '../Inputs';
-import { LoadingContainer } from '../Loaders';
-
-const STATUS = {
- IDLE: 'idle',
- LOADING: 'loading',
- SUCCESS: 'success',
- ERROR: 'error',
-};
-
-const NO_FILE_MESSAGE = 'No file chosen';
-
-const Content = styled(DialogContent)`
- text-align: left;
- min-height: 220px;
-`;
-
-const Heading = styled(Typography)`
- margin-bottom: 18px;
-`;
-
-export const ImportModal = ({
- isOpen,
- title,
- subtitle,
- actionText,
- loadingText,
- loadingHeading,
- showLoadingContainer,
- onSubmit,
- onClose,
-}) => {
- const [status, setStatus] = useState(STATUS.IDLE);
- const [errorMessage, setErrorMessage] = useState(null);
- const [successMessage, setSuccessMessage] = useState(null);
- const [file, setFile] = useState(null);
- const [fileName, setFileName] = useState(NO_FILE_MESSAGE);
-
- const handleSubmit = async event => {
- event.preventDefault();
- setErrorMessage(null);
- setStatus(STATUS.LOADING);
-
- try {
- const { message } = await onSubmit(file);
- if (showLoadingContainer && message) {
- setStatus(STATUS.SUCCESS);
- setSuccessMessage(message);
- } else {
- handleClose();
- }
- } catch (error) {
- setStatus(STATUS.ERROR);
- setErrorMessage(error.message);
- }
- };
-
- const handleClose = async () => {
- onClose();
-
- setStatus(STATUS.IDLE);
- setErrorMessage(null);
- setSuccessMessage(null);
- setFile(null);
- setFileName(NO_FILE_MESSAGE);
- };
-
- const handleDismiss = () => {
- setStatus(STATUS.IDLE);
- setErrorMessage(null);
- setSuccessMessage(null);
- // Deselect file when dismissing an error, this avoids an error when editing selected files
- // @see https://github.com/beyondessential/tupaia-backlog/issues/1211
- setFile(null);
- setFileName(NO_FILE_MESSAGE);
- };
-
- const ContentContainer = showLoadingContainer
- ? ({ children }) => (
-
- {children}
-
- )
- : ({ children }) => <>{children}>;
-
- const renderContent = useCallback(() => {
- switch (status) {
- case STATUS.SUCCESS:
- return
{successMessage}
;
- case STATUS.ERROR:
- return (
- <>
- An error has occurred.
-
- {errorMessage}
-
- >
- );
- default:
- return (
- <>
- {subtitle}
-
- >
- );
- }
- }, [status, successMessage, errorMessage, subtitle, fileName]);
-
- const renderButtons = useCallback(() => {
- switch (status) {
- case STATUS.SUCCESS:
- return ;
- case STATUS.ERROR:
- return (
- <>
- Dismiss
-
- >
- );
- default:
- return (
- <>
-
-
- >
- );
- }
- }, [status, file, handleDismiss, handleClose, handleSubmit]);
-
- return (
-
- );
-};
-
-ImportModal.propTypes = {
- isOpen: PropTypes.bool.isRequired,
- title: PropTypes.string,
- subtitle: PropTypes.string,
- actionText: PropTypes.string,
- loadingText: PropTypes.string,
- loadingHeading: PropTypes.string,
- showLoadingContainer: PropTypes.bool,
- onSubmit: PropTypes.func.isRequired,
- onClose: PropTypes.func.isRequired,
-};
-
-ImportModal.defaultProps = {
- title: 'Import',
- subtitle: '',
- actionText: 'Import',
- loadingText: 'Importing',
- loadingHeading: 'Importing data',
- showLoadingContainer: false,
-};
diff --git a/packages/admin-panel/src/widgets/Modal/Modal.jsx b/packages/ui-components/src/components/Modal/Modal.tsx
similarity index 64%
rename from packages/admin-panel/src/widgets/Modal/Modal.jsx
rename to packages/ui-components/src/components/Modal/Modal.tsx
index 59b48c8982..fe884e9f18 100644
--- a/packages/admin-panel/src/widgets/Modal/Modal.jsx
+++ b/packages/ui-components/src/components/Modal/Modal.tsx
@@ -4,9 +4,9 @@
*/
import React from 'react';
import styled from 'styled-components';
-import PropTypes from 'prop-types';
-import { DialogFooter as BaseDialogFooter, Button } from '@tupaia/ui-components';
-import { Dialog } from '@material-ui/core';
+import { ButtonProps, Dialog, DialogProps } from '@material-ui/core';
+import { DialogFooter as BaseDialogFooter } from '../Dialog';
+import { Button } from '../Button';
import { ModalContentProvider } from './ModalContentProvider';
import { ModalHeader } from './ModalHeader';
@@ -16,6 +16,23 @@ export const ModalFooter = styled(BaseDialogFooter)`
padding-inline: 1.9rem;
`;
+type ButtonT = ButtonProps & {
+ id: string;
+ text: string;
+ component?: React.ElementType;
+ to?: string;
+};
+
+interface ModalProps extends Omit {
+ children: React.ReactNode;
+ isOpen: boolean;
+ onClose: () => void;
+ title: string;
+ isLoading?: boolean;
+ errorMessage?: string;
+ buttons?: ButtonT[];
+}
+
export const Modal = ({
children,
isOpen,
@@ -23,9 +40,9 @@ export const Modal = ({
title,
isLoading,
errorMessage,
- buttons,
+ buttons = [],
...muiDialogProps
-}) => {
+}: ModalProps) => {
return (