Skip to content

Commit

Permalink
Merge pull request #3088 from hollaex/develop-fe
Browse files Browse the repository at this point in the history
User Deletion By Admin
  • Loading branch information
abeikverdi authored Nov 14, 2024
2 parents b3aae6c + f865233 commit 75497ab
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
9 changes: 6 additions & 3 deletions server/utils/hollaex-tools-lib/tools/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const fetchP2PDeals = async (opts = {
}
});
} else {
const p2pDeals = await client.getAsync(`p2p-deals${opts.user_id}`);
const p2pDeals = await client.getAsync(`p2p-deals${opts.user_id || 'all'}`);

if (p2pDeals) return JSON.parse(p2pDeals);
else {
Expand All @@ -138,7 +138,7 @@ const fetchP2PDeals = async (opts = {
}
}

await client.setexAsync(`p2p-deals${opts.user_id}`, 30, JSON.stringify(deals));
await client.setexAsync(`p2p-deals${opts.user_id || 'all'}`, 30, JSON.stringify(deals));

return deals;
}
Expand Down Expand Up @@ -352,6 +352,7 @@ const updateP2PDeal = async (data) => {
}
});
await client.delAsync(`p2p-deals${merchant_id}`);
await client.delAsync(`p2p-dealsall`);
await getModel('p2pDeal').update({ status }, { where : { id : edited_ids }});
return { message : 'success' };
}
Expand Down Expand Up @@ -410,7 +411,7 @@ const updateP2PDeal = async (data) => {
};

await client.delAsync(`p2p-deals${merchant_id}`);

await client.delAsync(`p2p-dealsall`);
return p2pDeal.update(data, {
fields: [
'merchant_id',
Expand Down Expand Up @@ -446,6 +447,8 @@ const deleteP2PDeal = async (removed_ids, user_id) => {
};

await client.delAsync(`p2p-deals${user_id}`);
await client.delAsync(`p2p-dealsall`);

const promises = deals.map(async (deal) => {
return await deal.destroy();
});
Expand Down
2 changes: 1 addition & 1 deletion server/utils/hollaex-tools-lib/tools/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3403,7 +3403,7 @@ const getPaymentDetails = async (user_id, opts = {
const query = {
where: {
created_at: timeframe,
user_id,
...(user_id && { user_id }),
...(opts.is_p2p && { is_p2p: opts.is_p2p }),
...(opts.is_fiat_control && { is_fiat_control: opts.is_fiat_control }),
...(opts.status && { status: opts.status })
Expand Down
9 changes: 9 additions & 0 deletions web/src/containers/Admin/User/AboutData.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ const AboutData = ({
freezeAccount,
verifyEmail,
recoverUser,
deleteUser,
onChangeSuccess,
allIcons = {},
userTiers,
Expand Down Expand Up @@ -639,6 +640,14 @@ const AboutData = ({
<Fragment>
<div className="about-info-content">
<div>Account is active</div>
<div
className="info-link"
onClick={() => {
deleteUser();
}}
>
Delete user
</div>
</div>
<ReactSVG
src={STATIC_ICONS.VERIFICATION_ICON}
Expand Down
33 changes: 33 additions & 0 deletions web/src/containers/Admin/User/DeleteConfirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { Button, Modal } from 'antd';
import { ReactSVG } from 'react-svg';
import { STATIC_ICONS } from 'config/icons';

const DeletionConfirmation = ({ userData = {}, onConfirm, ...rest }) => (
<Modal footer={null} width={350} {...rest}>
<div>
<div className="d-flex mb-2">
<div>
<ReactSVG src={STATIC_ICONS.USER_EMAIL} className={'about-icon'} />
</div>
<h3 className="ml-3 pt-2" style={{ color: '#ffffff' }}>
User Delete
</h3>
</div>
<div className="mb-4">
<div className="mb-3">
<span className="bold">Email:</span>
<span className="pl-2">{userData.email}</span>
</div>
<div>Are you sure you want to delete this user?</div>
</div>
<div>
<Button className="green-btn w-100" onClick={onConfirm}>
Confirm
</Button>
</div>
</div>
</Modal>
);

export default DeletionConfirmation;
41 changes: 40 additions & 1 deletion web/src/containers/Admin/User/UserContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import {
activateUser,
verifyUser,
recoverUser,
deleteUser,
requestTiers,
} from './actions';
import UserMetaForm from './UserMetaForm';
import PaymentMethods from './PaymentMethods';
import DeletionConfirmation from './DeleteConfirmation';

// import Flagger from '../Flaguser';
// import Notes from './Notes';
Expand All @@ -45,6 +47,7 @@ class UserContent extends Component {
state = {
showVerifyEmailModal: false,
showRecoverModal: false,
showDeleteModal: false,
userTiers: {},
};

Expand Down Expand Up @@ -218,6 +221,24 @@ class UserContent extends Component {
});
};

handleDeleteUser = () => {
const { userInformation = {}, refreshData } = this.props;
const postValues = {
user_id: parseInt(userInformation.id, 10),
};

deleteUser(postValues)
.then((res) => {
refreshData({ ...postValues, activated: false });
this.setState({ showDeleteModal: false });
})
.catch((err) => {
const _error =
err.data && err.data.message ? err.data.message : err.message;
message.error(_error);
});
};

openVerifyEmailModal = () => {
this.setState({
showVerifyEmailModal: true,
Expand All @@ -230,6 +251,12 @@ class UserContent extends Component {
});
};

openDeleteUserModel = () => {
this.setState({
showDeleteModal: true,
});
};

renderTabBar = (props, DefaultTabBar) => {
if (this.props.isConfigure) return <div></div>;
return <DefaultTabBar {...props} />;
Expand All @@ -252,7 +279,12 @@ class UserContent extends Component {
referral_history_config,
} = this.props;

const { showVerifyEmailModal, showRecoverModal, userTiers } = this.state;
const {
showVerifyEmailModal,
showRecoverModal,
showDeleteModal,
userTiers,
} = this.state;

const {
id,
Expand Down Expand Up @@ -354,6 +386,7 @@ class UserContent extends Component {
freezeAccount={this.freezeAccount}
verifyEmail={this.openVerifyEmailModal}
recoverUser={this.openRecoverUserModel}
deleteUser={this.openDeleteUserModel}
kycPluginName={kycPluginName}
requestUserData={requestUserData}
refreshAllData={refreshAllData}
Expand Down Expand Up @@ -470,6 +503,12 @@ class UserContent extends Component {
onConfirm={this.handleRecoverUser}
userData={userInformation}
/>
<DeletionConfirmation
visible={showDeleteModal}
onCancel={() => this.setState({ showRecoverModal: false })}
onConfirm={this.handleDeleteUser}
userData={userInformation}
/>
</div>
);
}
Expand Down
9 changes: 9 additions & 0 deletions web/src/containers/Admin/User/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ export const recoverUser = (values) => {
return requestAuthenticated('/admin/user/restore', options);
};

export const deleteUser = (values) => {
const options = {
method: 'DELETE',
body: JSON.stringify(values),
};

return requestAuthenticated('/admin/user', options);
};

export const performVerificationLevelUpdate = (values) => {
const options = {
method: 'POST',
Expand Down

0 comments on commit 75497ab

Please sign in to comment.