From 71bad5a19f8aea358b3f21dde4f69fd53a870184 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Thu, 4 Jul 2024 02:00:20 -0400 Subject: chore: Refactor ThingsHistory component and add styling improvements --- src/Config.js | 5 ++- src/views/Things/ThingsHistory.jsx | 84 +++++++++++++++++++------------------- src/views/Things/ThingsView.jsx | 17 +++++--- 3 files changed, 59 insertions(+), 47 deletions(-) diff --git a/src/Config.js b/src/Config.js index b99597e..14bf4dc 100644 --- a/src/Config.js +++ b/src/Config.js @@ -1,5 +1,8 @@ /* eslint-env node */ -export const API_URL = import.meta.env.VITE_APP_API_URL // || 'http://localhost:2021' +export const API_URL = + import.meta.env.VITE_APP_API_URL === 'AUTO' + ? `${window.location.hostname}/api` + : import.meta.env.VITE_APP_API_URL export const REDIRECT_URL = import.meta.env.VITE_APP_REDIRECT_URL //|| 'http://localhost:3000' export const GOOGLE_CLIENT_ID = import.meta.env.VITE_APP_GOOGLE_CLIENT_ID export const ENVIROMENT = import.meta.env.VITE_APP_ENVIROMENT diff --git a/src/views/Things/ThingsHistory.jsx b/src/views/Things/ThingsHistory.jsx index 4b32b0e..c043a55 100644 --- a/src/views/Things/ThingsHistory.jsx +++ b/src/views/Things/ThingsHistory.jsx @@ -107,47 +107,49 @@ const ThingsHistory = () => { History: - - {thingsHistory.map((history, index) => ( - <> - - - - - {moment(history.updatedAt).format( - 'ddd MM/DD/yyyy HH:mm:ss', - )} - - {history.state === '1' ? 'Active' : 'Inactive'} - - - - {index < thingsHistory.length - 1 && ( - <> - - {/* time between two completion: */} - {index < thingsHistory.length - 1 && - thingsHistory[index + 1].createdAt && ( - - {formatTimeDifference( - history.createdAt, - thingsHistory[index + 1].createdAt, - )}{' '} - before - - )} - - - )} - - ))} - + + + {thingsHistory.map((history, index) => ( + <> + + + + + {moment(history.updatedAt).format( + 'ddd MM/DD/yyyy HH:mm:ss', + )} + + {history.state === '1' ? 'Active' : 'Inactive'} + + + + {index < thingsHistory.length - 1 && ( + <> + + {/* time between two completion: */} + {index < thingsHistory.length - 1 && + thingsHistory[index + 1].createdAt && ( + + {formatTimeDifference( + history.createdAt, + thingsHistory[index + 1].createdAt, + )}{' '} + before + + )} + + + )} + + ))} + + {/* Load more Button */} { const [confirmModelConfig, setConfirmModelConfig] = useState({}) const [isSnackbarOpen, setIsSnackbarOpen] = useState(false) - const [snackBarMessage, setSnackBarMessage] = useState('') + const [snackbarMessage, setSnackbarMessage] = useState('') + const [snackbarColor, setSnackbarColor] = useState('success') useEffect(() => { // fetch things @@ -222,7 +223,8 @@ const ThingsView = () => { } }) }) - setSnackBarMessage('Thing saved successfully') + setSnackbarMessage('Thing saved successfully') + setSnackbarColor('success') setIsSnackbarOpen(true) } const handleEditClick = thing => { @@ -246,7 +248,12 @@ const ThingsView = () => { ) currentThings.splice(thingIndex, 1) setThings(currentThings) + } else if (response.status === 405) { + setSnackbarMessage('Unable to delete thing with associated tasks') + setSnackbarColor('danger') + setIsSnackbarOpen(true) } + // if method not allwo show snackbar: }) } setConfirmModelConfig({}) @@ -280,7 +287,7 @@ const ThingsView = () => { }) }) } - setSnackBarMessage('Thing state updated successfully') + setSnackbarMessage('Thing state updated successfully') setIsSnackbarOpen(true) } @@ -366,11 +373,11 @@ const ThingsView = () => { }} autoHideDuration={3000} variant='soft' - color='success' + color={snackbarColor} size='lg' invertedColors > - {snackBarMessage} + {snackbarMessage} ) -- cgit