Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeBAY committed Dec 19, 2024
1 parent f887eed commit e1ecd07
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 82 deletions.
11 changes: 4 additions & 7 deletions canopeum_frontend/src/components/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,18 @@ const MainLayout = () => {
const { t: translate } = useTranslation()
const { getErrorMessage } = useErrorHandling()


// Try authenticating user on app start if token was saved in storage
useEffect(() => {
const runInitAuth = async () => initAuth()

runInitAuth().catch((error: unknown) => {
const errorMessage = getErrorMessage(
error,
translate('auth.user-token-not-found')
translate('auth.user-token-not-found'),
)
console.error(errorMessage);
});
}, []);


console.error(errorMessage)

Check warning on line 70 in canopeum_frontend/src/components/MainLayout.tsx

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

Unexpected console statement
})
}, [])

Check warning on line 72 in canopeum_frontend/src/components/MainLayout.tsx

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

React Hook useEffect has missing dependencies: 'getErrorMessage', 'initAuth', and 'translate'. Either include them or remove the dependency array

return (
<Routes>
Expand Down
4 changes: 2 additions & 2 deletions canopeum_frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const Navbar = () => {
changeLanguage(newLanguage).catch((error: unknown) => {
const errorMessage = getErrorMessage(
error,
translate('errors.change-language-failed')
translate('errors.change-language-failed'),
)
openAlertSnackbar(errorMessage, { severity: 'error' })
openAlertSnackbar(errorMessage, { severity: 'error' })
})
}

Expand Down
17 changes: 10 additions & 7 deletions canopeum_frontend/src/components/analytics/BatchActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ const BatchActions = ({ onEdit, onDelete, batchDetail }: Props) => {
translate('analyticsSite.delete-batch.success', { batchName: batchDetail.name }),
)
onDelete()

}

const handleConfirmDeleteClose = (proceed: boolean) => {
setConfirmDeleteOpen(false)
if (proceed) deleteBatch().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('analyticsSite.delete-batch.error',
{ batchName: batchDetail.name })),
{ severity: 'error' },
if (proceed) {
deleteBatch().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(
error,
translate('analyticsSite.delete-batch.error', { batchName: batchDetail.name }),
),
{ severity: 'error' },
)
)
)
}
}

return (
Expand Down
17 changes: 10 additions & 7 deletions canopeum_frontend/src/components/analytics/BatchTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ const BatchTable = (props: Props) => {
<BatchActions
batchDetail={batch}
onDelete={() => setBatches(previous => previous.filter(b => b.id !== batch.id))}
onEdit={() => fetchBatch(props.siteId).catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, t('errors.fetch-batch-failed',
{ batchName: batch.name })),
{ severity: 'error' },
)
)}
onEdit={() =>
fetchBatch(props.siteId).catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(
error,
t('errors.fetch-batch-failed', { batchName: batch.name }),
),
{ severity: 'error' },
)
)}
/>
</div>
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ const FertilizersSelector = ({ onChange, fertilizers }: Props) => {
setOptions(fertilizerOptions)
}
fetchFertilizers().catch((error: unknown) =>
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-fertilizers-failed')),
{ severity: 'error' })
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-fertilizers-failed')), {
severity: 'error',
})
)
}, [])

Check warning on line 53 in canopeum_frontend/src/components/analytics/FertilizersSelector.tsx

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

React Hook useEffect has missing dependencies: 'getApiClient', 'getErrorMessage', 'openAlertSnackbar', 'translate', and 'translateValue'. Either include them or remove the dependency array

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const MulchLayersSelector = ({ onChange, mulchLayers }: Props) => {
}
fetchMulchLayers().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-mulch-layers-failed'))
getErrorMessage(error, translate('errors.fetch-mulch-layers-failed')),
)
)
}, [])

Check warning on line 53 in canopeum_frontend/src/components/analytics/MulchLayersSelector.tsx

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

React Hook useEffect has missing dependencies: 'getApiClient', 'getErrorMessage', 'openAlertSnackbar', 'translate', and 'translateValue'. Either include them or remove the dependency array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ const SiteSummaryActions = ({ siteSummary, admins, onSiteChange, onSiteEdit }: P
return
}

deleteSite().catch((error: unknown)=>
deleteSite().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.delete-site-failed'))
getErrorMessage(error, translate('errors.delete-site-failed')),
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SupportSpeciesSelector = ({ onChange, species }: Props) => {
}
fetchTreeSpecies().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-support-species-failed'))
getErrorMessage(error, translate('errors.fetch-support-species-failed')),
)
)
}, [])

Check warning on line 51 in canopeum_frontend/src/components/analytics/SupportSpeciesSelector.tsx

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

React Hook useEffect has missing dependencies: 'getApiClient', 'getErrorMessage', 'openAlertSnackbar', 'translate', and 'translateValue'. Either include them or remove the dependency array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TreeSpeciesSelector = (
}
fetchTreeSpecies().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-tree-species-failed'))
getErrorMessage(error, translate('errors.fetch-tree-species-failed')),
)
)
}, [setAvailableSpecies, setOptions])

Check warning on line 54 in canopeum_frontend/src/components/analytics/TreeSpeciesSelector.tsx

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

React Hook useEffect has missing dependencies: 'getApiClient', 'getErrorMessage', 'openAlertSnackbar', 'translate', and 'translateValue'. Either include them or remove the dependency array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ const SiteModal = ({ open, handleClose, siteId }: Props) => {
const fetchSiteTypes = async () =>
setAvailableSiteTypes(await getApiClient().siteClient.types())


fetchSiteTypes().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, t('errors.fetch-site-types-failed'))
getErrorMessage(error, t('errors.fetch-site-types-failed')),
)
)
}, [])
Expand All @@ -110,7 +109,7 @@ const SiteModal = ({ open, handleClose, siteId }: Props) => {

fetchSite().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, t('errors.fetch-site-failed'))
getErrorMessage(error, t('errors.fetch-site-failed')),
)
)
}, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material'
import { useCallback, useContext, useEffect, useState } from 'react'
import { useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'

import { SnackbarContext } from '@components/context/SnackbarContext'
Expand Down Expand Up @@ -38,7 +38,7 @@ const AdminInvitationDialog = ({ open, handleClose }: Props) => {

fetchAllSites().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-all-sites-failed'))
getErrorMessage(error, translate('errors.fetch-all-sites-failed')),
)
)
}, [])
Expand Down Expand Up @@ -94,7 +94,7 @@ const AdminInvitationDialog = ({ open, handleClose }: Props) => {
)
.catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.copy-to-clipboard-failed'))
getErrorMessage(error, translate('errors.copy-to-clipboard-failed')),
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions canopeum_frontend/src/components/settings/ManageAdmins.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect, useState } from 'react'
import { useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'

import { SnackbarContext } from '@components/context/SnackbarContext'
Expand Down Expand Up @@ -32,7 +32,7 @@ const ManageAdmins = () => {

fetchSiteAdmins().catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-support-species-failed'))
getErrorMessage(error, translate('errors.fetch-support-species-failed')),
)
)
}, [setSiteAdminList, setIsLoadingAdmins])
Expand Down
20 changes: 10 additions & 10 deletions canopeum_frontend/src/components/social/PostCommentsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ const PostCommentsDialog = ({ open, postId, siteId, handleClose }: Props) => {
const fetchComments = async () => setComments(await getApiClient().commentClient.all(postId))

fetchComments()
.then(() => setCommentsLoaded(true))
.catch((error: unknown) => {
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-comments-failed')),
{ severity: 'error' })
setCommentsLoaded(false)
})


.then(() => setCommentsLoaded(true))
.catch((error: unknown) => {
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-comments-failed')), {
severity: 'error',
})
setCommentsLoaded(false)
})
}, [postId, open, commentsLoaded, getApiClient])

useEffect(() => {
Expand Down Expand Up @@ -140,8 +139,9 @@ const PostCommentsDialog = ({ open, postId, siteId, handleClose }: Props) => {
if (!proceedWithDelete || !commentToDelete) return

deleteComment(commentToDelete).catch((error: unknown) =>
openAlertSnackbar(getErrorMessage(error, translate('errors.delete-comment-failed')),
{ severity: 'error' })
openAlertSnackbar(getErrorMessage(error, translate('errors.delete-comment-failed')), {
severity: 'error',
})
)
}

Expand Down
15 changes: 8 additions & 7 deletions canopeum_frontend/src/components/social/SharePostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ const SharePostDialog = ({ onClose, open, post }: Props) => {
if (!shareUrl) return

navigator.clipboard.writeText(shareUrl)
.then(() =>
openAlertSnackbar(`${translate('generic.copied-clipboard')}!`, { severity: 'info' }))
.catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.copy-to-clibboard-failed')), { severity: 'error' }
.then(() =>
openAlertSnackbar(`${translate('generic.copied-clipboard')}!`, { severity: 'info' })
)
.catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.copy-to-clibboard-failed')),
{ severity: 'error' },
)
)
)

}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const SiteContactModal = ({ contact, isOpen, handleClose }: Props) => {
const { openAlertSnackbar } = useContext(SnackbarContext)
const { getErrorMessage } = useErrorHandling()


const handleSubmitSiteContact = () =>
getApiClient().contactClient.update(contact.id, editedContact as PatchedContact).then(
() => {
Expand All @@ -49,7 +48,8 @@ const SiteContactModal = ({ contact, isOpen, handleClose }: Props) => {
},
).catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, t('social.contact.feedback.edit-error')), { severity: 'error' }
getErrorMessage(error, t('social.contact.feedback.edit-error')),
{ severity: 'error' },
)
)

Expand Down
14 changes: 5 additions & 9 deletions canopeum_frontend/src/hooks/PostsInfiniteScrollingHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,8 @@ const usePostsInfiniteScrolling = () => {
return
}

fetchPostsPage().then(() =>
isMounted.current = true
)
.catch(() =>
isMounted.current = false
)

fetchPostsPage().then(() => isMounted.current = true)
.catch(() => isMounted.current = false)
}, [fetchPostsPage, siteIds])

// The scrollable container should be the parent container with overflow y auto/scroll
Expand All @@ -101,8 +96,9 @@ const usePostsInfiniteScrolling = () => {

setIsLoadingMore(true)
fetchPostsPage().catch((error: unknown) =>
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-posts-failed')),
{ severity: 'error' })
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-posts-failed')), {
severity: 'error',
})
)
}

Expand Down
2 changes: 1 addition & 1 deletion canopeum_frontend/src/locale/fr/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type Shape from '../en/auth'

export default {
'user-token-not-found': 'Token de l\'usager absent du stockage',
'user-token-not-found': "Token de l'usager absent du stockage",
'keep-password': 'Garder le même mot de passe',
'change-password': 'Change de mot de passe',
'log-in-header-text': 'Connectez-vous à votre compte',
Expand Down
5 changes: 2 additions & 3 deletions canopeum_frontend/src/locale/fr/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
'fetch-fertilizers-failed': 'Erreur: le chargement des engrais a échoué',
'fetch-mulch-layers-failed': 'Erreur: le chargement des couches de paillis a échoué',
'fetch-support-species-failed': 'Erreur: le chargement des espèces de support a échoué',
'fetch-tree-species-failed': 'Erreur: le chargement des espèces d\'arbres a échoué',
'fetch-tree-species-failed': "Erreur: le chargement des espèces d'arbres a échoué",
'fetch-site-types-failed': 'Erreur: le chargement des types de sites a échoué',
'fetch-site-failed': 'Erreur: le chargement du site a échoué',
'fetch-site-data-failed': 'Erreur: le chargement des données du site a échoué',
Expand All @@ -24,6 +24,5 @@ export default {
'fetch-posts-failed': 'Erreur: le chargement des publications a échoué',
'fetch-post-failed': 'Erreur: le chargement de la publication a échoué',
'fetch-admins-failed': 'Erreur: le chargement des administrateurs a échoué',
'fetch-user-invitation-failed': 'Erreur: le chargement de l\'invitation de utilisateur a échoué',

'fetch-user-invitation-failed': "Erreur: le chargement de l'invitation de utilisateur a échoué",
} satisfies typeof Shape
10 changes: 6 additions & 4 deletions canopeum_frontend/src/pages/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,19 @@ const Analytics = () => {
if (currentUser?.role !== 'MegaAdmin') return

fetchAdmins().catch((error: unknown) =>
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-admins-failed')),
{ severity: 'error' })
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-admins-failed')), {
severity: 'error',
})
)
}, [currentUser?.role, fetchAdmins])

useEffect(() => {
const fetchSites = async () => setSiteSummaries(await getApiClient().summaryClient.all())

fetchSites().catch((error: unknown) =>
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-fertilizers-failed')),
{ severity: 'error' })
openAlertSnackbar(getErrorMessage(error, translate('errors.fetch-fertilizers-failed')), {
severity: 'error',
})
)
}, [getApiClient, setSiteSummaries])

Expand Down
9 changes: 6 additions & 3 deletions canopeum_frontend/src/pages/AnalyticsSite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const AnalyticsSite = () => {

fetchSite(siteIdNumber).catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-site-failed')), { severity: 'error' }
getErrorMessage(error, translate('errors.fetch-site-failed')),
{ severity: 'error' },
)
)
}, [fetchSite, siteIdFromParams])
Expand Down Expand Up @@ -103,12 +104,14 @@ const AnalyticsSite = () => {
<CreateBatchModal
handleClose={reason => {
setIsCreateBatchOpen(false)
if (reason === 'create')
if (reason === 'create') {
fetchSite(siteSummary.id).catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-site-failed')), { severity: 'error' }
getErrorMessage(error, translate('errors.fetch-site-failed')),
{ severity: 'error' },
)
)
}
}}
open={isCreateBatchOpen}
site={siteSummary}
Expand Down
3 changes: 2 additions & 1 deletion canopeum_frontend/src/pages/PostDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const PostDetailsPage = () => {

fetchPost(postIdNumber).catch((error: unknown) =>
openAlertSnackbar(
getErrorMessage(error, translate('errors.fetch-post-failed')), { severity: 'error' }
getErrorMessage(error, translate('errors.fetch-post-failed')),
{ severity: 'error' },
)
)
setPostId(postIdNumber)
Expand Down
Loading

0 comments on commit e1ecd07

Please sign in to comment.