-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
161 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import {useApi} from '../../hooks/useApi'; | ||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; | ||
import {faTrashAlt} from '@fortawesome/free-solid-svg-icons'; | ||
|
||
const InviteManagement = () => { | ||
const { apiCall } = useApi(); | ||
const [invites, setInvites] = useState([]); | ||
|
||
const fetchInvites = async () => { | ||
try { | ||
const response = await apiCall('/users/invites'); | ||
setInvites(response); | ||
} catch (error) { | ||
console.error('Error fetching invites:', error); | ||
} | ||
}; | ||
|
||
const handleWithdrawInvite = async (inviteId, inviteEmail) => { | ||
const isConfirmed = window.confirm(`Are you sure you want to withdraw the invite for: ${inviteEmail}?`); | ||
if (isConfirmed) { | ||
try { | ||
await apiCall(`/users/invite/${inviteId}`, 'DELETE'); | ||
fetchInvites(); // Refresh the invites list after withdrawal | ||
} catch (error) { | ||
console.error('Error withdrawing invite:', error); | ||
} | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchInvites(); | ||
}, []); | ||
|
||
if (invites.length === 0) { | ||
return null; // Hide the component if there are no invites | ||
} | ||
|
||
return ( | ||
<div className="inviteManagementContainer"> | ||
<h3>Not accepted Invites</h3> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Email</th> | ||
<th>Status</th> | ||
<th>Expiration Date</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{invites.map((invite, index) => ( | ||
<tr key={index}> | ||
<td>{invite.email}</td> | ||
<td>{invite.status}</td> | ||
<td>{new Date(invite.expiration_date).toLocaleDateString()}</td> | ||
<td> | ||
<FontAwesomeIcon | ||
icon={faTrashAlt} | ||
onClick={() => handleWithdrawInvite(invite._id, invite.email)} | ||
/> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
<hr/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InviteManagement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters