diff --git a/frontend/src/components/ActivateConnectionModal.tsx b/frontend/src/components/ActivateConnectionModal.tsx deleted file mode 100644 index 4c72195..0000000 --- a/frontend/src/components/ActivateConnectionModal.tsx +++ /dev/null @@ -1,215 +0,0 @@ -// import React, { useEffect, useState, useRef } from 'react'; -// import { Button } from 'primereact/button'; -// import { Toast } from 'primereact/toast'; -// import { api } from '../services/axios'; -// import { Dialog } from 'primereact/dialog'; -// import { useNavigate } from 'react-router-dom'; -// import { useSettingsStore } from '../state/stores/useSettingsStore'; - -// type UserInfo = { -// role: string; -// tenantId: string | number; -// }; - -// const ActivateConnectionModal = () => { -// const [loading, setLoading] = useState(false); -// const [showDialog, setShowDialog] = useState(false); -// const toast = useRef(null); -// const [fetched, setFetched] = useState(false); -// const [systemName, setSystemName] = useState(''); -// const tenantId = localStorage.getItem('tenantId'); -// const systemId = localStorage.getItem('systemId'); - -// const navigate = useNavigate(); - -// const [userInfo, setUserInfo] = useState({ -// role: '', -// tenantId: -1, -// }); - -// const [messageShown, setMessageShown] = useState(false); - -// const { setConnectionId } = useSettingsStore(); - -// useEffect(() => { -// // TODO: similar logic used in other components, refactor into user context/state/hook -// const storedUser = localStorage.getItem('user'); -// const storedSystemName = localStorage.getItem('systemName'); - -// if (storedUser) { -// const parsedUser = JSON.parse(storedUser); - -// let role = parsedUser.roles?.includes('admin') -// ? 'admin' -// : parsedUser.roles?.includes('user') -// ? 'user' -// : ''; - -// let tenantId = -// role === 'admin' ? localStorage.getItem('tenantId') || -1 : -1; - -// let userInfo: UserInfo = { -// role: role, -// tenantId: tenantId, -// }; - -// setUserInfo(userInfo); -// } - -// if (storedSystemName) { -// setSystemName(storedSystemName); -// } -// }, []); - -// useEffect(() => { -// if (userInfo.role && userInfo.tenantId !== undefined && !fetched) { -// fetchConnection(); -// } -// }, [userInfo]); - -// const fetchConnection = async () => { -// setLoading(true); -// try { -// let response: any; - -// if (userInfo.role === 'user') { -// response = await api('get', `/connections?systemName=${systemName}`); -// } else if (userInfo.role === 'admin' && userInfo.tenantId) { -// response = await api( -// 'get', -// `/connections?systemName=${systemName}&tenantId=${userInfo.tenantId}`, -// ); -// } else { -// throw new Error('Invalid user role or missing tenantId'); -// } - -// const connections = response.data.data; - -// // Localstorage saves undefined as string -// if (tenantId === 'undefined' || systemId === 'undefined') { -// navigate('/systems'); -// } - -// if (!connections || connections.length === 0) { -// setShowDialog(true); -// } else if (userInfo.role === 'user') { -// setUserInfo((prevUserInfo) => ({ -// ...prevUserInfo, -// tenantId: connections[0].tenant_fleks_id, -// })); -// } -// const connectionId = connections[0].id; -// localStorage.setItem('connectionId', connectionId); -// setConnectionId(connectionId); -// navigate(`/dashboard/${systemName}`); -// setLoading(false); -// setFetched(true); -// } catch (error) { -// console.error('Error:', error); -// setLoading(false); -// if (!messageShown) { -// setMessageShown(true); -// } -// } -// }; - -// const handleActivateClick = async () => { -// setLoading(true); -// const systemId = localStorage.getItem('systemId') || null; - -// try { -// let postResponse: any; -// let requestBody: any = { -// system_id: Number(systemId), -// }; - -// if (!systemId) { -// throw new Error('Missing systemId'); -// } - -// if (userInfo.role === 'admin' && userInfo.tenantId) { -// requestBody.tenant_id = userInfo.tenantId; -// } - -// postResponse = await api('post', '/connections', requestBody); - -// if (postResponse.status === 201) { -// const connectionId = postResponse.data.id; -// localStorage.setItem('connectionId', connectionId); -// setConnectionId(connectionId); - -// navigate(`/dashboard/${systemName}`); - -// setLoading(false); -// setShowDialog(false); -// toast.current.show({ -// severity: 'success', -// summary: 'Success', -// detail: 'Connection established successfully.', -// life: 3000, -// }); -// } else { -// setLoading(false); -// toast.current.show({ -// severity: 'error', -// summary: 'Error', -// detail: 'Failed to establish connection.', -// life: 3000, -// }); -// } -// } catch (error) { -// if (error.message === 'Missing systemId') { -// toast.current.show({ -// severity: 'error', -// summary: 'Error', -// detail: 'Missing system information. Please verify.', -// life: 3000, -// }); -// } else { -// console.error('Error:', error); -// } -// } -// }; - -// const handleCancelClick = () => { -// setShowDialog(false); -// navigate('/systems'); -// }; - -// return ( -//
-//
-//
-// setShowDialog(false)} -// header="Activate Connection" -// footer={ -//
-//
-// } -// > -// {loading ? ( -//

Performing the post request, please wait...

-// ) : ( -//

Are you sure you want to activate the connection?

-// )} -//
-//
-//
-//
-// ); -// }; -// export default ActivateConnectionModal; diff --git a/frontend/src/components/CanvasEndpoints/CanvasDataTable.tsx b/frontend/src/components/CanvasEndpoints/CanvasDataTable.tsx deleted file mode 100644 index 31f9908..0000000 --- a/frontend/src/components/CanvasEndpoints/CanvasDataTable.tsx +++ /dev/null @@ -1,372 +0,0 @@ -import React from 'react'; -import { DataTable } from 'primereact/datatable'; -import { Column } from 'primereact/column'; -import { Card } from 'primereact/card'; - -interface CanvasData { - [key: string]: any; -} - -interface CanvasDataTableProps { - data: CanvasData[]; - loading: boolean; - error: string | null; -} - -const CanvasDataTable: React.FC = ({ - data, - loading, - errorimport { Column } from 'primereact/column'; - import { FilterMatchMode, FilterOperator } from 'primereact/api'; - import { useEffect, useRef, useState } from 'react'; - import { api } from '../../services/api.ts'; - - import TableGroupHeader from '../../shared/components/_V1/TableGroupHeader.tsx'; - import TableGroup from '../../shared/components/_V1/TableGroup.tsx'; - - import { Toast } from 'primereact/toast'; - import ConfirmModal from '../../shared/components/modals/ConfirmModal.tsx'; - import CreateVoucherModal from './CreateVoucherModal.tsx'; - // import EditVoucherModal from './AddVoucherCodeModal.tsx'; - import LoadingPage from '../../shared/components/_V1/LoadingPage.tsx'; - import DetailModal from './DetailModal.tsx'; - import AddVoucherCodeModal, { AddVoucherCodeModalProps } from './AddVoucherCodeModal.tsx'; - import { Voucher, useVoucherStore } from '../../state/stores/Mews/useMewsVoucherStore.ts'; - import { TSizeOptionValue } from '../../types/DataTable.types.ts'; - import Button from '../../shared/components/_V2/Button.tsx'; - - export default function VoucherTableGroup() { - const { createVoucher, fetchVouchers, updateVoucher, vouchers, addVoucherCode } = - useVoucherStore(); - - const [filters, setFilters] = useState(null); - const [globalFilterValue, setGlobalFilterValue] = useState(''); - - const [showCreateVoucherModal, setShowCreateVoucherModal] = useState(false); - const [showConfirmDeleteModal, setShowConfirmDeleteModal] = useState(false); - - const [showAddCodeModal, setShowAddCodeModal] = useState(false); - const [currentVoucherForCode, setCurrentVoucherForCode] = useState(null); - - const [detailModalVisible, setDetailModalVisible] = useState(false); - const [detailContent, setDetailContent] = useState([]); - const [detailTitle, setDetailTitle] = useState(''); - - const [selectedVouchers, setSelectedVouchers] = useState(null); - - const toast = useRef(null); - - const [isLoading, setIsLoading] = useState(false); - - // Change table row size - const sizeOptions: { label: string; value: TSizeOptionValue }[] = [ - { label: 'Small', value: 'small' }, - { label: 'Normal', value: 'normal' }, - { label: 'Large', value: 'large' }, - ]; - - const [size, setSize] = useState(sizeOptions[0].value); - - useEffect(() => { - initFilters(); - // fetchVouchers; - handleRefresh(); - }, []); - - const showToastMessage = (options) => { - toast.current?.show(options); - }; - - const initFilters = () => { - setFilters({ - global: { value: null, matchMode: FilterMatchMode.CONTAINS }, - representative: { value: null, matchMode: FilterMatchMode.IN }, - createdAt: { - operator: FilterOperator.AND, - constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }], - }, - }); - setGlobalFilterValue(''); - }; - - const clearFilter = () => { - initFilters(); - }; - - const onGlobalFilterChange = (e: { target: { value: any } }) => { - const value = e.target.value; - // @ts-ignore - let _filters = { ...filters }; - _filters['global'].value = value; - setFilters(_filters); - setGlobalFilterValue(value); - }; - - // TODO: refresh data - const handleRefresh = async () => { - setIsLoading(true); - await fetchVouchers(); - setIsLoading(false); - }; - - const formatDate = (value: string | number | Date) => { - const date = new Date(value); - return date.toLocaleDateString('en-US', { - day: '2-digit', - month: '2-digit', - year: 'numeric', - }); - }; - - const dateBodyTemplate = (rowData: { createdAt: string | number | Date }) => { - return formatDate(rowData.createdAt); - }; - - const actionButtons = () => { - return ( -
- - {/* */} -
- ); - }; - - const editButton = (rowData: Voucher) => { - return ; - }; - - const openDetailModal = (content, title) => { - setDetailContent(content); - setDetailTitle(title); - setDetailModalVisible(true); - }; - - const closeDetailModal = () => { - setDetailModalVisible(false); - }; - - const handleCreateVoucher = async (newVoucher: Voucher) => { - await createVoucher(newVoucher); - handleRefresh(); - setShowCreateVoucherModal(false); - }; - - const handleDeleteSelectedVouchers = () => { - const URL = '/neppeURL'; - const body = selectedVouchers.map((voucher) => { - return { - id: voucher.id, - }; - }); - api('delete', URL, body); - }; - - const voucherRatesBodyTemplate = (rowData) => { - if (rowData?.voucherCodes.length < 1) { - return ''; - } - const details = rowData.rates.map((rate) => `Name: ${rate.name}, Type: ${rate.type}`); - return ( -