Skip to content

Commit eeefd31

Browse files
committed
Simplify approval actions and recreate Auto Link on last-link delete
1 parent 6ef8e90 commit eeefd31

3 files changed

Lines changed: 42 additions & 60 deletions

File tree

src/components/Sidebar.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
fetchResourceChanges,
2222
fetchUserById,
2323
updateUserRole,
24-
updateUserApproval,
2524
type CollaboratorDirectoryUser,
2625
type CloudUser,
2726
type ResourceChange,
@@ -1346,22 +1345,6 @@ export function Sidebar() {
13461345
}
13471346
};
13481347

1349-
const toggleProfileApproval = async () => {
1350-
if (!profilePopupUser) return;
1351-
setProfilePopupBusy(true);
1352-
setProfilePopupStatus("");
1353-
try {
1354-
const updated = await updateUserApproval(profilePopupUser.id, !profilePopupUser.isApproved);
1355-
setProfilePopupUser(updated);
1356-
setProfilePopupStatus(`${updated.isApproved ? "Approved" : "Set pending"} ${updated.username}.`);
1357-
} catch (error) {
1358-
const message = getUiErrorMessage(error);
1359-
setProfilePopupStatus(`Approval update failed: ${message}`);
1360-
} finally {
1361-
setProfilePopupBusy(false);
1362-
}
1363-
};
1364-
13651348
return (
13661349
<aside className="sidebar-panel">
13671350
<UserAdminPanel />
@@ -1650,7 +1633,7 @@ export function Sidebar() {
16501633
</button>
16511634
<button
16521635
className="inline-action"
1653-
disabled={links.length <= 1}
1636+
disabled={!links.length}
16541637
onClick={() => deleteLink(selectedLink.id)}
16551638
type="button"
16561639
>
@@ -2073,9 +2056,16 @@ export function Sidebar() {
20732056
<option value="admin">Admin</option>
20742057
</select>
20752058
</label>
2076-
<button className="inline-action" disabled={profilePopupBusy} onClick={() => void toggleProfileApproval()} type="button">
2077-
{profilePopupUser.isApproved ? "Set Pending" : "Approve Access"}
2078-
</button>
2059+
{!profilePopupUser.isApproved ? (
2060+
<button
2061+
className="inline-action"
2062+
disabled={profilePopupBusy}
2063+
onClick={() => void changeProfileRole("user")}
2064+
type="button"
2065+
>
2066+
Approve Access
2067+
</button>
2068+
) : null}
20792069
</div>
20802070
{profilePopupStatus ? <p className="field-help">{profilePopupStatus}</p> : null}
20812071
</div>

src/components/UserAdminPanel.tsx

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -377,38 +377,6 @@ export function UserAdminPanel() {
377377
}
378378
};
379379

380-
const toggleApproval = async (user: CloudUser) => {
381-
setBusy(true);
382-
setStatus("");
383-
try {
384-
await updateUserRole(user.id, user.isApproved ? "pending" : "user");
385-
await refreshAdminData();
386-
setStatus(`${user.isApproved ? "Revoked" : "Granted"} access for ${user.username}.`);
387-
} catch (error) {
388-
const message = getUiErrorMessage(error);
389-
setStatus(`Approval update failed: ${message}`);
390-
} finally {
391-
setBusy(false);
392-
}
393-
};
394-
395-
const rejectUser = async (user: CloudUser) => {
396-
setBusy(true);
397-
setStatus("");
398-
try {
399-
await updateUserRole(user.id, "pending");
400-
await refreshAdminData();
401-
setStatus(
402-
`${user.isApproved ? "Revoked access for" : "Set pending access for"} ${user.username}.`,
403-
);
404-
} catch (error) {
405-
const message = getUiErrorMessage(error);
406-
setStatus(`Reject failed: ${message}`);
407-
} finally {
408-
setBusy(false);
409-
}
410-
};
411-
412380
const deleteUserAccount = async (user: CloudUser) => {
413381
const confirmed = window.confirm(`Delete user ${user.username}? This will remove owned records.`);
414382
if (!confirmed) return;
@@ -1002,12 +970,15 @@ export function UserAdminPanel() {
1002970
<option disabled={!canAssignManagedRole(managedUser, "admin")} value="admin">Admin</option>
1003971
</select>
1004972
</label>
1005-
<button className="inline-action" onClick={() => void toggleApproval(managedUser)} type="button">
1006-
{managedUser.isApproved ? "Set Pending" : "Approve Access"}
1007-
</button>
1008-
<button className="inline-action" onClick={() => void rejectUser(managedUser)} type="button">
1009-
Set Pending
1010-
</button>
973+
{!managedUser.isApproved ? (
974+
<button
975+
className="inline-action"
976+
onClick={() => void updateRole(managedUser, "user")}
977+
type="button"
978+
>
979+
Approve Access
980+
</button>
981+
) : null}
1011982
<button className="inline-action" onClick={() => void deleteUserAccount(managedUser)} type="button">
1012983
Delete User
1013984
</button>

src/store/appStore.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,28 @@ export const useAppStore = create<AppState>((set, get) => ({
646646
deleteLink: (linkId) => {
647647
set((state) => {
648648
const remaining = state.links.filter((link) => link.id !== linkId);
649-
if (!remaining.length) return state;
649+
if (!remaining.length) {
650+
if (state.sites.length < 2) return state;
651+
const base = state.links[0];
652+
const selectedNetwork = state.networks.find((network) => network.id === state.selectedNetworkId);
653+
const inheritedFrequencyMHz =
654+
selectedNetwork?.frequencyOverrideMHz ?? selectedNetwork?.frequencyMHz ?? base?.frequencyMHz ?? 869.618;
655+
const fallbackLink: Link = {
656+
id: makeId("lnk"),
657+
name: "Auto Link",
658+
fromSiteId: state.sites[0].id,
659+
toSiteId: state.sites[1].id,
660+
frequencyMHz: inheritedFrequencyMHz,
661+
txPowerDbm: base?.txPowerDbm ?? 22,
662+
txGainDbi: base?.txGainDbi ?? 2,
663+
rxGainDbi: base?.rxGainDbi ?? 2,
664+
cableLossDb: base?.cableLossDb ?? 1,
665+
};
666+
return {
667+
links: [fallbackLink],
668+
selectedLinkId: fallbackLink.id,
669+
};
670+
}
650671
return {
651672
links: remaining,
652673
selectedLinkId:

0 commit comments

Comments
 (0)