Skip to content

Commit

Permalink
Delete all closed accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
MaFi050599 committed Aug 15, 2023
1 parent 1847af2 commit 8a35ee9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/firebase/api/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export const uploadProfilePicture = (picture, email) => {
const saveUser = (id, profile) => {
return db.collection('/users').doc(id).set(profile);
};

export const deleteUser = (id) => {
return db.collection('/users').doc(id).delete();
};

export const signOut = () => auth.signOut();

export const sendResetPasswordEmail = ({ email }) => {
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useTenders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';

import {
deleteInvite,
deleteUser,
inviteUser,
streamInvitedUsers,
streamUsers,
Expand Down Expand Up @@ -56,6 +57,10 @@ const useTenders = () => {
return deleteInvite(row);
};

const removeUser = (id) => {
return deleteUser(id);
};

const updateTender = (id, field, value) => {
return updateUser({ id: id, field: field, value: value });
};
Expand All @@ -66,6 +71,7 @@ const useTenders = () => {
addInvite,
removeInvite,
updateTender,
removeUser,
};
};

Expand Down
33 changes: 31 additions & 2 deletions src/pages/Admin/UserManagement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ const StyledButton = styled(Button)`
margin-bottom: ${({ theme }) => theme.baseUnit}px;
`;
const UserManagement = () => {
const { tenderState, invitedTenders, updateTender, addInvite, removeInvite } =
useContext(TendersContext);
const {
tenderState,
invitedTenders,
updateTender,
addInvite,
removeInvite,
removeUser,
} = useContext(TendersContext);
const { studylines } = useContext(AuthContext);
const [isProfileVisible, setIsProfileVisible] = useState(false);
const [searchParam, setSearchParam] = useState('');
Expand Down Expand Up @@ -70,6 +76,17 @@ const UserManagement = () => {
);
};

const onRemoveAllClosedAccounts = () => {
const closedAccounts = tenderState.tenders.filter(
(t) => t.roles.length < 1
);
closedAccounts.forEach((t) => {
removeUser(t.id)
.then(() => message.success(`${t.displayName} has been removed`))
.catch((error) => message.error('An error ocurred: ' + error.message));
});
};

const onInviteDelete = (row) => {
removeInvite(row)
.then(() => message.success('Invite removed'))
Expand All @@ -92,6 +109,18 @@ const UserManagement = () => {
</Space>
<StyledTabs type="card" defaultActiveKey="1">
<StyledTabPane tab="Manage users" key="1">
<StyledButton
type="primary"
onClick={() =>
window.confirm(
'Are you sure you want to delete all closed accounts'
)
? onRemoveAllClosedAccounts()
: console.log('nothing deleted')
}
>
Delete all closed accounts
</StyledButton>
<DataTable
columns={USER_COLUMNS(onUserEdit, studylines)}
data={filterOnSearchParam(tenderState.tenders)}
Expand Down

0 comments on commit 8a35ee9

Please sign in to comment.