fixes when no ip addresses enabled

This commit is contained in:
Ishaan Jaff 2024-07-09 16:15:05 -07:00
parent e966d9fd0f
commit f7002ecd08

View file

@ -93,6 +93,8 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
isLocal ? "http://localhost:4000" : "" isLocal ? "http://localhost:4000" : ""
); );
const all_ip_address_allowed = "All IP Addresses Allowed";
let nonSssoUrl; let nonSssoUrl;
try { try {
nonSssoUrl = window.location.origin; nonSssoUrl = window.location.origin;
@ -105,14 +107,14 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
try { try {
if (accessToken) { if (accessToken) {
const data = await getAllowedIPs(accessToken); const data = await getAllowedIPs(accessToken);
setAllowedIPs(data.length > 0 ? data : ["All IP Addresses"]); setAllowedIPs(data && data.length > 0 ? data : [all_ip_address_allowed]);
} else { } else {
setAllowedIPs(["All IP Addresses"]); setAllowedIPs([all_ip_address_allowed]);
} }
} catch (error) { } catch (error) {
console.error("Error fetching allowed IPs:", error); console.error("Error fetching allowed IPs:", error);
message.error("Failed to fetch allowed IPs"); message.error(`Failed to fetch allowed IPs ${error}`);
setAllowedIPs(["All IP Addresses"]); setAllowedIPs([all_ip_address_allowed]);
} finally { } finally {
setIsAllowedIPModalVisible(true); setIsAllowedIPModalVisible(true);
} }
@ -129,7 +131,7 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
} }
} catch (error) { } catch (error) {
console.error("Error adding IP:", error); console.error("Error adding IP:", error);
message.error('Failed to add IP address'); message.error(`Failed to add IP address ${error}`);
} finally { } finally {
setIsAddIPModalVisible(false); setIsAddIPModalVisible(false);
} }
@ -146,11 +148,11 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
await deleteAllowedIP(accessToken, ipToDelete); await deleteAllowedIP(accessToken, ipToDelete);
// Fetch the updated list of IPs // Fetch the updated list of IPs
const updatedIPs = await getAllowedIPs(accessToken); const updatedIPs = await getAllowedIPs(accessToken);
setAllowedIPs(updatedIPs.length > 0 ? updatedIPs : ["All IP Addresses"]); setAllowedIPs(updatedIPs.length > 0 ? updatedIPs : [all_ip_address_allowed]);
message.success('IP address deleted successfully'); message.success('IP address deleted successfully');
} catch (error) { } catch (error) {
console.error("Error deleting IP:", error); console.error("Error deleting IP:", error);
message.error('Failed to delete IP address'); message.error(`Failed to delete IP address ${error}`);
} finally { } finally {
setIsDeleteIPModalVisible(false); setIsDeleteIPModalVisible(false);
setIPToDelete(null); setIPToDelete(null);
@ -731,16 +733,18 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{allowedIPs.map((ip, index) => ( {allowedIPs.map((ip, index) => (
<TableRow key={index}> <TableRow key={index}>
<TableCell>{ip}</TableCell> <TableCell>{ip}</TableCell>
<TableCell className="text-right"> <TableCell className="text-right">
<Button onClick={() => handleDeleteIP(ip)} color="red" size="xs"> {ip !== all_ip_address_allowed && (
Delete <Button onClick={() => handleDeleteIP(ip)} color="red" size="xs">
</Button> Delete
</TableCell> </Button>
</TableRow> )}
))} </TableCell>
</TableRow>
))}
</TableBody> </TableBody>
</Table> </Table>
</Modal> </Modal>