({
users,
onUserUpdated,
onUserSelected,
onGroupSelected,
}: {
users: User[];
onUserUpdated: (user: User) => void;
onUserSelected?: (user: User) => void;
onGroupSelected?: (group: Group) => void;
})
| 72 | // ============================================================ |
| 73 | |
| 74 | function UserTable({ |
| 75 | users, |
| 76 | onUserUpdated, |
| 77 | onUserSelected, |
| 78 | onGroupSelected, |
| 79 | }: { |
| 80 | users: User[]; |
| 81 | onUserUpdated: (user: User) => void; |
| 82 | onUserSelected?: (user: User) => void; |
| 83 | onGroupSelected?: (group: Group) => void; |
| 84 | }) { |
| 85 | const { t } = useTranslation(); |
| 86 | const currentUser = useCurrentUser(); |
| 87 | const archiveUser = useAppStore((state) => state.archiveUser); |
| 88 | const restoreUser = useAppStore((state) => state.restoreUser); |
| 89 | const batchGetOrFetchGroups = useAppStore( |
| 90 | (state) => state.batchGetOrFetchGroups |
| 91 | ); |
| 92 | const deleteServiceAccount = useAppStore( |
| 93 | (state) => state.deleteServiceAccount |
| 94 | ); |
| 95 | const undeleteServiceAccount = useAppStore( |
| 96 | (state) => state.undeleteServiceAccount |
| 97 | ); |
| 98 | const deleteWorkloadIdentity = useAppStore( |
| 99 | (state) => state.deleteWorkloadIdentity |
| 100 | ); |
| 101 | const undeleteWorkloadIdentity = useAppStore( |
| 102 | (state) => state.undeleteWorkloadIdentity |
| 103 | ); |
| 104 | |
| 105 | // Batch fetch groups when user list changes |
| 106 | useEffect(() => { |
| 107 | const allGroupNames = users.flatMap((u) => u.groups); |
| 108 | if (allGroupNames.length > 0) { |
| 109 | batchGetOrFetchGroups(allGroupNames); |
| 110 | } |
| 111 | }, [users, batchGetOrFetchGroups]); |
| 112 | |
| 113 | const handleDeactivate = async (user: User) => { |
| 114 | const accountType = getAccountTypeByEmail(user.email); |
| 115 | const fullName = getUserFullNameByType(user); |
| 116 | |
| 117 | const confirmed = window.confirm( |
| 118 | t("settings.members.action.deactivate-confirm-title") |
| 119 | ); |
| 120 | if (!confirmed) return; |
| 121 | |
| 122 | try { |
| 123 | if (accountType === AccountType.SERVICE_ACCOUNT) { |
| 124 | await deleteServiceAccount(fullName); |
| 125 | } else if (accountType === AccountType.WORKLOAD_IDENTITY) { |
| 126 | await deleteWorkloadIdentity(fullName); |
| 127 | } else { |
| 128 | await archiveUser(fullName); |
| 129 | } |
| 130 | |
| 131 | const updated = create(UserSchema, { ...user, state: State.DELETED }); |
nothing calls this directly
no test coverage detected