From 3871ec89f7f367649bfdb1b6f48efd3db417fa00 Mon Sep 17 00:00:00 2001 From: Mohammad Sajad Pourajam Date: Thu, 19 Feb 2026 15:07:21 +0330 Subject: [PATCH] Add Sensor Hub tab to account settings, integrating new SensorHubTab and related components for sensor management. Updated layout and added error handling in the sensor form. --- .../(private)/pages/account-settings/page.tsx | 4 +- src/views/pages/account-settings/index.tsx | 9 ++- .../sensor-hub/SensorHubTabContent.tsx | 79 +++++++++++++++++++ .../account-settings/sensor-hub/index.tsx | 1 + src/views/sensorHub/FormSensorHub.tsx | 40 ++++++++-- 5 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 src/views/pages/account-settings/sensor-hub/SensorHubTabContent.tsx create mode 100644 src/views/pages/account-settings/sensor-hub/index.tsx diff --git a/src/app/(dashboard)/(private)/pages/account-settings/page.tsx b/src/app/(dashboard)/(private)/pages/account-settings/page.tsx index e308578..cdae347 100644 --- a/src/app/(dashboard)/(private)/pages/account-settings/page.tsx +++ b/src/app/(dashboard)/(private)/pages/account-settings/page.tsx @@ -12,6 +12,7 @@ const SecurityTab = dynamic(() => import('@views/pages/account-settings/security const BillingPlansTab = dynamic(() => import('@views/pages/account-settings/billing-plans')) const NotificationsTab = dynamic(() => import('@views/pages/account-settings/notifications')) const ConnectionsTab = dynamic(() => import('@views/pages/account-settings/connections')) +const SensorHubTab = dynamic(() => import('@views/pages/account-settings/sensor-hub')) // Vars const tabContentList = (): { [key: string]: ReactElement } => ({ @@ -19,7 +20,8 @@ const tabContentList = (): { [key: string]: ReactElement } => ({ security: , 'billing-plans': , notifications: , - connections: + connections: , + 'sensor-hub': }) const AccountSettingsPage = () => { diff --git a/src/views/pages/account-settings/index.tsx b/src/views/pages/account-settings/index.tsx index ba22ea7..0735009 100644 --- a/src/views/pages/account-settings/index.tsx +++ b/src/views/pages/account-settings/index.tsx @@ -24,10 +24,11 @@ const AccountSettings = ({ tabContentList }: { tabContentList: { [key: string]: return ( - {/* + } iconPosition='start' value='account' /> - } iconPosition='start' value='security' /> + } iconPosition='start' value='sensor-hub' /> + {/* } iconPosition='start' value='security' /> } @@ -40,9 +41,9 @@ const AccountSettings = ({ tabContentList }: { tabContentList: { [key: string]: iconPosition='start' value='notifications' /> - } iconPosition='start' value='connections' /> + } iconPosition='start' value='connections' /> */} - */} + {tabContentList[activeTab]} diff --git a/src/views/pages/account-settings/sensor-hub/SensorHubTabContent.tsx b/src/views/pages/account-settings/sensor-hub/SensorHubTabContent.tsx new file mode 100644 index 0000000..8cf19b6 --- /dev/null +++ b/src/views/pages/account-settings/sensor-hub/SensorHubTabContent.tsx @@ -0,0 +1,79 @@ +'use client' + +// React Imports +import { useState } from 'react' + +// MUI Imports +import Grid from '@mui/material/Grid2' +import Button from '@mui/material/Button' +import Typography from '@mui/material/Typography' +import Card from '@mui/material/Card' +import CardContent from '@mui/material/CardContent' +import Fade from '@mui/material/Fade' + +// Hook Imports +import { useSensorHub } from '@/hooks/useSensorHub' + +// API Imports +import type { Sensor } from '@/libs/api/services/sensorHubService' + +// Component Imports +import SensorHubTable from '@views/sensorHub/SensorHubTable' +import OptionSensorHub from '@views/sensorHub/OptionSensorHub' +import FormSensorHub from '@views/sensorHub/FormSensorHub' + +const transitionTimeout = { enter: 300, exit: 200 } + +const SensorHubTabContent = () => { + const [showAddForm, setShowAddForm] = useState(false) + const { setSensorHub } = useSensorHub() + + const handleBack = () => setShowAddForm(false) + + const handleConfirm = (sensor: Sensor) => { + setSensorHub({ id: sensor.uuid_sensor, ...sensor }) + } + + return ( + + + + + + +
+ {showAddForm ? ( + + ) : ( +
+
+
+ + انتخاب سنسور + + + سنسور مورد نظر را انتخاب کنید یا سنسور جدید اضافه کنید + +
+ +
+ +
+ )} +
+
+
+
+
+
+ ) +} + +export default SensorHubTabContent diff --git a/src/views/pages/account-settings/sensor-hub/index.tsx b/src/views/pages/account-settings/sensor-hub/index.tsx new file mode 100644 index 0000000..bb9ef31 --- /dev/null +++ b/src/views/pages/account-settings/sensor-hub/index.tsx @@ -0,0 +1 @@ +export { default } from './SensorHubTabContent' diff --git a/src/views/sensorHub/FormSensorHub.tsx b/src/views/sensorHub/FormSensorHub.tsx index 476c29e..b4d2e84 100644 --- a/src/views/sensorHub/FormSensorHub.tsx +++ b/src/views/sensorHub/FormSensorHub.tsx @@ -6,7 +6,11 @@ import { useState } from 'react' // MUI Imports import Grid from '@mui/material/Grid2' import Button from '@mui/material/Button' -import Typography from '@mui/material/Typography' +import CircularProgress from '@mui/material/CircularProgress' +import Alert from '@mui/material/Alert' + +// API Imports +import { sensorHubService } from '@/libs/api' // Component Imports import CustomTextField from '@core/components/mui/TextField' @@ -18,10 +22,22 @@ type FormSensorHubProps = { const FormSensorHub = ({ onBack }: FormSensorHubProps) => { const [name, setName] = useState('') const [uuidSensor, setUuidSensor] = useState('') + const [loading, setLoading] = useState(false) + const [error, setError] = useState(null) - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() - // TODO: Call API to add sensor + setError(null) + setLoading(true) + try { + await sensorHubService.addSensor({ name, uuid_sensor: uuidSensor }) + onBack() + } catch (err: unknown) { + const message = err && typeof err === 'object' && 'message' in err ? String((err as { message: string }).message) : 'خطا در ذخیره سنسور' + setError(message) + } finally { + setLoading(false) + } } return ( @@ -40,6 +56,13 @@ const FormSensorHub = ({ onBack }: FormSensorHubProps) => {
+ {error && ( + + setError(null)}> + {error} + + + )} { /> - -