diff --git a/frontend/src/components/settings/arrs/ArrCard.jsx b/frontend/src/components/settings/arrs/ArrCard.jsx new file mode 100644 index 0000000..35e8d5d --- /dev/null +++ b/frontend/src/components/settings/arrs/ArrCard.jsx @@ -0,0 +1,24 @@ +// ArrCard.jsx +import React from 'react'; +import PropTypes from 'prop-types'; + +const ArrCard = ({title, icon: Icon, onClick}) => ( +
+
+ +

+ {title} +

+
+
+); + +ArrCard.propTypes = { + title: PropTypes.string.isRequired, + icon: PropTypes.elementType.isRequired, + onClick: PropTypes.func.isRequired +}; + +export default ArrCard; diff --git a/frontend/src/components/settings/arrs/ArrContainer.jsx b/frontend/src/components/settings/arrs/ArrContainer.jsx new file mode 100644 index 0000000..6a7e33f --- /dev/null +++ b/frontend/src/components/settings/arrs/ArrContainer.jsx @@ -0,0 +1,57 @@ +// ArrContainer.jsx +import React, {useState} from 'react'; +import AddNewCard from '../../ui/AddNewCard'; +import ArrModal from './ArrModal'; + +const ArrContainer = () => { + const [showModal, setShowModal] = useState(false); + const [editingArr, setEditingArr] = useState(null); + + const handleAddArr = () => { + setEditingArr(null); + setShowModal(true); + }; + + const handleEditArr = arr => { + setEditingArr(arr); + setShowModal(true); + }; + + const handleCloseModal = () => { + setShowModal(false); + setEditingArr(null); + }; + + const handleSubmit = arrData => { + if (editingArr) { + console.log('Updating arr:', arrData); + // Implement your update logic here + } else { + console.log('Adding new arr:', arrData); + // Implement your add logic here + } + setShowModal(false); + setEditingArr(null); + }; + + return ( + <> +
+ +
+ + + ); +}; + +export default ArrContainer; diff --git a/frontend/src/components/settings/arrs/ArrModal.jsx b/frontend/src/components/settings/arrs/ArrModal.jsx new file mode 100644 index 0000000..2b13587 --- /dev/null +++ b/frontend/src/components/settings/arrs/ArrModal.jsx @@ -0,0 +1,135 @@ +// ArrModal.js +import React, {useState, useEffect} from 'react'; +import {Plus, TestTube, Loader, Save} from 'lucide-react'; +import Modal from '../../ui/Modal'; + +const ArrModal = ({isOpen, onClose, onSubmit, editingArr}) => { + const [arrType, setArrType] = useState(''); + const [arrName, setArrName] = useState(''); + const [apiKey, setApiKey] = useState(''); + const [isTestingConnection, setIsTestingConnection] = useState(false); + + useEffect(() => { + if (editingArr) { + setArrType(editingArr.type); + setArrName(editingArr.name); + setApiKey(editingArr.apiKey); + } else { + setArrType(''); + setArrName(''); + setApiKey(''); + } + }, [editingArr]); + + const handleTestConnection = async () => { + setIsTestingConnection(true); + try { + const result = await testConnection(arrType, apiKey); + if (result.success) { + alert('Connection successful!'); + } else { + alert('Connection failed: ' + result.error); + } + } catch (error) { + alert('An error occurred while testing the connection.'); + console.error('Error testing connection:', error); + } finally { + setIsTestingConnection(false); + } + }; + + const handleSubmit = e => { + e.preventDefault(); + onSubmit({type: arrType, name: arrName, apiKey}); + }; + + return ( + +
+
+ + +
+
+ + setArrName(e.target.value)} + className='mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50 dark:bg-gray-700 dark:border-gray-600 dark:text-white' + required + /> +
+
+ + setApiKey(e.target.value)} + className='mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50 dark:bg-gray-700 dark:border-gray-600 dark:text-white' + required + /> +
+
+ + +
+
+
+ ); +}; + +export default ArrModal;