Skip to content

Commit

Permalink
Merge pull request #298 from SchoodEIP/final_debug_fixes
Browse files Browse the repository at this point in the history
Final debug fixes
  • Loading branch information
Exiels authored Dec 6, 2024
2 parents ebb960a + fdf83f6 commit 509c68a
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 229 deletions.
9 changes: 8 additions & 1 deletion src/Components/Accounts/Adm/admAccountsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import deleteButton from '../../../assets/deleteIcon.png'
import suspendButton from '../../../assets/suspendIcon.png'
import restoreButton from '../../../assets/restoreIcon.png'

export default function AdmAccountsTable () {
export default function AdmAccountsTable ({ handleUpdateContent, isUpdated }) {

Check warning on line 12 in src/Components/Accounts/Adm/admAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const [accountList, setAccountList] = useState([]) // list of accounts
const [isPopupOpen, setIsPopupOpen] = useState(false)
const [userId, setUserId] = useState('')
Expand All @@ -35,6 +35,13 @@ export default function AdmAccountsTable () {
}
}

useEffect(() => {
if (isUpdated) {
getAccountList()
handleUpdateContent()
}
}, [isUpdated])

async function getSuspendedAccountList (list) {
const baseUrl = process.env.REACT_APP_BACKEND_URL + '/user/getDisabled'
const token = sessionStorage.getItem('token')
Expand Down
34 changes: 24 additions & 10 deletions src/Components/Accounts/SchoolAdm/schoolAccountsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import suspendButton from '../../../assets/suspendIcon.png'
import restoreButton from '../../../assets/restoreIcon.png'
import Select from 'react-select'

export default function SchoolAccountsTable ({ status }) {
export default function SchoolAccountsTable ({ isUpdated, handleUpdateContent, status }) {
const [teacherList, setTeacherList] = useState([])
const [studentList, setStudentList] = useState([])
const [selectedUser, setSelectedUser] = useState(null)
Expand Down Expand Up @@ -47,12 +47,15 @@ export default function SchoolAccountsTable ({ status }) {
disconnect()
} else {
const data = await resp.json()
const array = [...accounts, ...data]

const teacherAccounts = array.filter(account => account.role.name === 'teacher')
const studentAccounts = array.filter(account => account.role.name === 'student')
setTeacherList(teacherAccounts)
setStudentList(studentAccounts)
if (data.message !== 'Access Forbidden') {
const array = [...accounts, ...data]

const teacherAccounts = array.filter(account => account.role.name === 'teacher')
const studentAccounts = array.filter(account => account.role.name === 'student')
setTeacherList(teacherAccounts)
setStudentList(studentAccounts)
}
}
}

Expand Down Expand Up @@ -100,6 +103,13 @@ export default function SchoolAccountsTable ({ status }) {
})
}

useEffect(() => {
if (isUpdated) {
getAccountList()
handleUpdateContent()
}
}, [isUpdated])

const showClasses = (classes) => {
if (!Array.isArray(classes)) {
return ''
Expand Down Expand Up @@ -195,7 +205,11 @@ export default function SchoolAccountsTable ({ status }) {

studentClass.map(classe => { return callAction(classe, '/updateStudent') })
}
if (!classError) { toast.success('Le profil a été mis à jour avec succès.') }
if (!classError) {
toast.success('Le profil a été mis à jour avec succès.')

Check warning on line 209 in src/Components/Accounts/SchoolAdm/schoolAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
handleUpdateContent()

Check warning on line 210 in src/Components/Accounts/SchoolAdm/schoolAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
openEditing()

Check warning on line 211 in src/Components/Accounts/SchoolAdm/schoolAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 212 in src/Components/Accounts/SchoolAdm/schoolAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 212 in src/Components/Accounts/SchoolAdm/schoolAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 213 in src/Components/Accounts/SchoolAdm/schoolAccountsTable.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const handleUpdate = async (e) => {
Expand Down Expand Up @@ -315,7 +329,7 @@ export default function SchoolAccountsTable ({ status }) {
<div className='popup-modal-container' style={{ alignItems: 'center' }}>
<button className='close-btn' onClick={close}><img src={cross} alt='Close' /></button>
<div className='editProfileForm'>
<h2>Modifier Profil</h2>
<h2>Modifier le profil</h2>
<form className='form-profile-modif' onSubmit={handleUpdate}>
<div>
<label className='input-label' htmlFor='firstname'>Prénom:
Expand Down Expand Up @@ -407,7 +421,7 @@ export default function SchoolAccountsTable ({ status }) {
<td title={`${data.firstname} ${data.lastname}`}>{data.lastname}</td>
<td title={`${data.email}`}>{data.email}</td>
<td>{showClasses(data.classes)}</td>
{status && <td><button style={{ fontFamily: 'Inter' }} onClick={(e) => { e.stopPropagation(); handleEditClick(data) }} title='Modifier le profil'>Modifier</button></td>}
{status && <td>{data.active && <button style={{ fontFamily: 'Inter' }} onClick={(e) => { e.stopPropagation(); handleEditClick(data) }} title='Modifier le profil'>Modifier</button>}</td>}
{status &&
<td>
{
Expand Down Expand Up @@ -451,7 +465,7 @@ export default function SchoolAccountsTable ({ status }) {
<td title={`${data.firstname} ${data.lastname}`}>{data.lastname}</td>
<td title={`${data.email}`}>{data.email}</td>
<td>{showClasses(data.classes)}</td>
{status && <td><button style={{ fontFamily: 'Inter' }} onClick={(e) => { e.stopPropagation(); handleEditClick(data) }} title='Modifier le Profil'>Modifier</button></td>}
{status && <td>{data.active && <button style={{ fontFamily: 'Inter' }} onClick={(e) => { e.stopPropagation(); handleEditClick(data) }} title='Modifier le profil'>Modifier</button>}</td>}
{status &&
<td>
{
Expand Down
82 changes: 42 additions & 40 deletions src/Components/Aides/aides.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import phoneIcon from '../../assets/phoneIcon.png'
import mailIcon from '../../assets/mailIcon.png'
import { toast } from 'react-toastify'

export default function AidePage () {
export default function AidePage ({ updateContent, handleUpdateContent }) {
const [categories, setCategories] = useState([])
const [contacts, setContacts] = useState([])
const [chosenContact, setChosenContact] = useState([])
Expand All @@ -18,49 +18,51 @@ export default function AidePage () {
useEffect(() => {
const categoryUrl = process.env.REACT_APP_BACKEND_URL + '/user/helpNumbersCategories'
const helpNumbersUrl = process.env.REACT_APP_BACKEND_URL + '/user/helpNumbers'

fetch(categoryUrl, {
method: 'GET',
headers: {
'x-auth-token': sessionStorage.getItem('token'),
'Content-Type': 'application/json'
}
}).then(response => {
if (response.status === 401) {
disconnect()
}
return response.json()
})
.then(data => {
setCategories(data)
const filterID = data.filter((category) => category.name === 'Autres')
if (filterID.length !== 0) {
setDefaultID(filterID[0]._id)
setSelectedCat(filterID[0]._id)
if (updateContent) {
fetch(categoryUrl, {
method: 'GET',
headers: {
'x-auth-token': sessionStorage.getItem('token'),
'Content-Type': 'application/json'
}
}).then(response => {
if (response.status === 401) {
disconnect()
}
return response.json()
})
.catch(error => toast.error(error.message))
.then(data => {
setCategories(data)
const filterID = data.filter((category) => category.name === 'Autres')
if (filterID.length !== 0) {
setDefaultID(filterID[0]._id)
setSelectedCat(filterID[0]._id)
}
})
.catch(error => toast.error(error.message))

fetch(helpNumbersUrl, {
method: 'GET',
headers: {
'x-auth-token': sessionStorage.getItem('token'),
'Content-Type': 'application/json'
}
}).then(response => {
if (response.status === 401) {
disconnect()
}
return response.json()
})
.then(data => {
setContacts(data)
setFilteredContacts(data)
setChosenContact(data[0])
setSelectedContact(data[0]._id)
fetch(helpNumbersUrl, {
method: 'GET',
headers: {
'x-auth-token': sessionStorage.getItem('token'),
'Content-Type': 'application/json'
}
}).then(response => {
if (response.status === 401) {
disconnect()
}
return response.json()
})
.catch(error => toast.error('Erreur ' + error.status + ': ' + error.message))
}, [])
.then(data => {
setContacts(data)
setFilteredContacts(data)
setChosenContact(data[0])
setSelectedContact(data[0]._id)
})
.catch(error => toast.error('Erreur ' + error.status + ': ' + error.message))
handleUpdateContent()

Check warning on line 63 in src/Components/Aides/aides.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 64 in src/Components/Aides/aides.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 64 in src/Components/Aides/aides.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}, [updateContent])

Check warning on line 65 in src/Components/Aides/aides.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const filterContactsByCategory = (category) => {
const filtered = contacts.filter((contact) => category !== defaultID ? contact.helpNumbersCategory === category : contact)
Expand Down
27 changes: 8 additions & 19 deletions src/Components/ChatRoom/chatRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import '../../css/Components/Popup/popup.scss'
import cross from '../../assets/Cross.png'
import { disconnect } from '../../functions/disconnect'
import UserProfile from '../../Components/userProfile/userProfile'
import { toast } from 'react-toastify'

const Messages = () => {
const [conversations, setConversations] = useState([])
const [currentConversation, setCurrentConversation] = useState('')
const [notification, setNotification] = useState({ visible: false, message: '', type: '' })
const { send, chats } = useContext(WebsocketContext) // eslint-disable-line
const inputFile = useRef(null)

Expand Down Expand Up @@ -143,13 +143,6 @@ const Messages = () => {
return () => clearInterval(intervalId)
}, [currentConversation])

const openNotification = (message, type) => {
setNotification({ visible: true, message, type })
setTimeout(() => {
setNotification({ visible: false, message: '', type: '' })
}, 3000) // La notification sera visible pendant 3 secondes
}

const sendMessage = async () => {
if (newMessage.trim() === '' && !file) {
return
Expand Down Expand Up @@ -291,10 +284,10 @@ const Messages = () => {
}

send('createChat', { ids: selectedContacts.filter((id) => id !== userId) })
openNotification('Une nouvelle conversation a été créée avec succès', 'success')
toast.success('Une nouvelle conversation a été créée avec succès')
fetchConversations()
} catch (error) /* istanbul ignore next */ {
openNotification('Erreur lors de la création de la conversation', 'error')
toast.error('Erreur lors de la création de la conversation')
setError('Erreur lors de la création de la conversation')
}
}
Expand Down Expand Up @@ -322,11 +315,11 @@ const Messages = () => {
throw new Error('Erreur lors de l\'ajout des participants.')
}

openNotification('Participants ajoutés avec succès', 'success')
toast.success('Participants ajoutés avec succès')
fetchConversations() // Met à jour les conversations
} catch (error) {
console.error('Erreur lors de l\'ajout des participants :', error)
openNotification('Erreur lors de l\'ajout des participants', 'error')
toast.error('Erreur lors de l\'ajout des participants')
} finally {
setShowAddParticipantsPopup(false) // Ferme la popup après l'ajout
}
Expand All @@ -351,12 +344,12 @@ const Messages = () => {
throw new Error('Erreur lors du départ de la conversation.')
}

openNotification('Vous avez quitté la conversation.', 'success')
toast.success('Vous avez quitté la conversation.')
setCurrentConversation('') // Réinitialiser la conversation actuelle
fetchConversations() // Mettre à jour la liste des conversations après avoir quitté
} catch (error) {
console.error('Erreur lors du départ de la conversation :', error)
openNotification('Erreur lors du départ de la conversation.', 'error')
toast.error('Erreur lors du départ de la conversation.')
} finally {
// clearNotification() // Efface la notification après un certain temps
setShowLeaveConversationPopup(false) // Ferme la popup après avoir quitté
Expand Down Expand Up @@ -404,10 +397,6 @@ const Messages = () => {
openCreateConversationPopup={openCreateConversationPopup}
/>
<div className='chat'>
{notification.visible &&
<div className={`notification ${notification.type}`}>
{notification.message}
</div>}
{currentConversation
? (
<div className='chat-content'>
Expand Down Expand Up @@ -492,7 +481,7 @@ const Messages = () => {
</div>
)
: (
<div>Aucune conversation sélectionnée.</div>
<div style={{ marginTop: '20px', marginLeft: '20px' }}>Aucune conversation sélectionnée.</div>
)}
</div>
<Popup open={showCreateConversationPopup} onClose={openCreateConversationPopup} modal contentStyle={{ width: '400px' }}>
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Popup/alertCreation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const AlertCreationPopupContent = () => {
}

return (
<>
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px', alignSelf: 'center' }}>
{
roleProfile === 'teacher'
? null
Expand Down Expand Up @@ -211,8 +211,8 @@ const AlertCreationPopupContent = () => {
<span className='label-content'>Fichier joint</span>
<input style={{ fontFamily: 'Inter' }} id='file-input' data-testid='alert-file-input' type='file' onChange={(e) => setFile(e.target.files[0])} />
</label>
<button className='popup-btn' onClick={handleAlertSubmit}>Créer l'Alerte</button>
</>
<button style={{ alignSelf: 'center' }} className='popup-btn' onClick={handleAlertSubmit}>Créer l'Alerte</button>
</div>
)

Check warning on line 216 in src/Components/Popup/alertCreation.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 217 in src/Components/Popup/alertCreation.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Expand Down
7 changes: 4 additions & 3 deletions src/Components/Popup/alertDeletion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import '../../css/pages/createAlerts.scss'

const AlertDeletionPopupContent = ({ onClose, chosenAlert, handleDeleteAlert }) => {
return (
<>
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px', alignSelf: 'center' }}>
<h3 style={{ alignSelf: 'center' }}>Supprimer l'alerte</h3>
<p>Êtes-vous certain(e) de vouloir supprimer cette alerte ?</p>
<p>Cette action sera irréversible.</p>
<button className='popup-btn' onClick={() => handleDeleteAlert(chosenAlert.id, onClose)}>Supprimer l'Alerte</button>
</>
<button style={{ alignSelf: 'center' }} className='popup-btn' onClick={() => handleDeleteAlert(chosenAlert.id, onClose)}>Supprimer l'Alerte</button>

Check warning on line 11 in src/Components/Popup/alertDeletion.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 11 in src/Components/Popup/alertDeletion.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
</div>
)

Check warning on line 13 in src/Components/Popup/alertDeletion.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 14 in src/Components/Popup/alertDeletion.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Expand Down
10 changes: 6 additions & 4 deletions src/Components/Popup/alertModification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '../../css/pages/createAlerts.scss'
import { toast } from 'react-toastify'
import { disconnect } from '../../functions/disconnect'

const AlertModificationPopupContent = ({ onClose, chosenAlert, handleEditAlert }) => {
const AlertModificationPopupContent = ({ onClose, chosenAlert, handleEditAlert, handleUpdateContent }) => {
const [editedAlert, setEditedAlert] = useState(chosenAlert)
const [file, setFile] = useState(null)

Expand All @@ -31,6 +31,7 @@ const AlertModificationPopupContent = ({ onClose, chosenAlert, handleEditAlert }
if (response.status === 401) {
disconnect()
}
handleUpdateContent()
toast.success('Fichier envoyé avec l\'alerte avec succès')
})
.catch((error) => /* istanbul ignore next */ {
Expand All @@ -44,7 +45,8 @@ const AlertModificationPopupContent = ({ onClose, chosenAlert, handleEditAlert }
}

return (
<>
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px', alignSelf: 'center' }}>
<h3 style={{ alignSelf: 'center' }}>Modifier l'alerte</h3>
<label className='input-label'>
<span className='label-content'>Titre <span style={{ color: 'red' }}>*</span></span>
<input type='text' name='title' placeholder='Titre' value={editedAlert.title} onChange={handleEditChange} />
Expand All @@ -57,8 +59,8 @@ const AlertModificationPopupContent = ({ onClose, chosenAlert, handleEditAlert }
<span className='label-content'>Fichier joint</span>
<input id='file-input' data-testid='alert-file-input' type='file' onChange={(e) => setFile(e.target.files[0])} />
</label>
<button className='popup-btn' onClick={() => editAlert()}>Modifier l'Alerte</button>
</>
<button style={{ alignSelf: 'center' }} className='popup-btn' onClick={() => editAlert()}>Modifier l'Alerte</button>

Check warning on line 62 in src/Components/Popup/alertModification.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 62 in src/Components/Popup/alertModification.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
</div>
)

Check warning on line 64 in src/Components/Popup/alertModification.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 65 in src/Components/Popup/alertModification.jsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Expand Down
Loading

0 comments on commit 509c68a

Please sign in to comment.