import { Alert, AlertIcon, Grid, GridItem, Spinner, Stack, Tab, TabList, TabPanel, TabPanels, Table, TableContainer, Tabs, Tbody, Td, Th, Thead, Tr, } from '@chakra-ui/react' import { useEffect, useMemo, useState } from 'react' import { useSelector } from 'react-redux' import { fetchReceivedSMSList, selectDeviceList, selectReceivedSMSList, } from '../../store/deviceSlice' import { useAppDispatch } from '../../store/hooks' import { selectAuthUser } from '../../store/authSlice' export default function ReceiveSMS() { return ( <> ) } const ReceiveSMSNotifications = () => { return ( You can now receive SMS and view them in the dashboard, or retreive them via the API To receive SMS, you need to have an active device that has receive SMS option enabled (Turn on the switch in the app) Webhooks will be available soon 😉 ) } const ReceivedSMSList = () => { const dispatch = useAppDispatch() const [tabIndex, setTabIndex] = useState(0) const { loading: receivedSMSListLoading, data: receivedSMSListData } = useSelector(selectReceivedSMSList) const deviceList = useSelector(selectDeviceList) const authUser = useSelector(selectAuthUser) const activeDeviceId = useMemo(() => { return deviceList[tabIndex]?._id }, [tabIndex, deviceList]) useEffect(() => { if (authUser && activeDeviceId) { dispatch(fetchReceivedSMSList(activeDeviceId)) } }, [dispatch, authUser, activeDeviceId]) if (!receivedSMSListLoading && (!deviceList || deviceList.length == 0)) { return ( You dont have any devices yet. Please register a device to receive SMS ) } return ( <> {deviceList.map(({ _id, brand, model }) => ( {`${brand} ${model}`} ))} {deviceList.map(({ _id, brand, model }) => ( {receivedSMSListLoading && ( )} {!receivedSMSListLoading && receivedSMSListData.length == 0 && ( )} {!receivedSMSListLoading && receivedSMSListData.length > 0 && receivedSMSListData.map( ({ _id, sender, message, receivedAt }) => ( ) )}
sender message received at
No SMS received
{sender} {message} {new Date(receivedAt).toLocaleString('en-US', { month: 'long', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, })}
))}
) }