Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Delete all closed accounts #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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