summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrohan09-raj <rajrohan1914@gmail.com>2022-08-26 09:13:22 +0530
committerrohan09-raj <rajrohan1914@gmail.com>2022-08-26 09:14:13 +0530
commit794d996eac6ff8d5cd174bd73b6731806fe362e8 (patch)
treedb4fdac631ae9dbe44c3ac79fe54c9335fc28f91
parent2fae816ce7e95a3a99c8442debc49285898328d8 (diff)
message modal and api fix
-rw-r--r--admin/src/pages/EnrollmentRequests/EnrollmentRequests.jsx39
-rw-r--r--admin/src/pages/UpdateRequests/UpdateRequests.jsx6
-rw-r--r--admin/src/services/apiservice.js4
-rw-r--r--server/controllers/message.js13
-rw-r--r--server/controllers/users.js5
-rw-r--r--server/routes/message.js1
6 files changed, 54 insertions, 14 deletions
diff --git a/admin/src/pages/EnrollmentRequests/EnrollmentRequests.jsx b/admin/src/pages/EnrollmentRequests/EnrollmentRequests.jsx
index 4ae5a85..bd2b17b 100644
--- a/admin/src/pages/EnrollmentRequests/EnrollmentRequests.jsx
+++ b/admin/src/pages/EnrollmentRequests/EnrollmentRequests.jsx
@@ -11,17 +11,18 @@ import {useQuery, useMutation} from 'react-query';
import {useNavigate} from 'react-router-dom';
import BackButton from '../../components/BackButton/BackButton';
import {sendMessage} from '../../services/apiservice';
+import Spinner from '../../components/Spinner/Spinner';
import styles from './EnrollmentRequests.module.css';
+import MessageModal from '../../components/Modal/MessageModal';
const EnrollmentRequests = () => {
const navigate = useNavigate();
- const {data, refetch} = useQuery('unverified', getUnverifiedUsers);
- const deleteUse = useMutation((id) => deleteUser(id), {
- onSuccess: () => {
- refetch();
- },
- });
+ const [open, setOpen] = React.useState(false);
+ const [message, setMessage] = React.useState('');
+ const {data, refetch, isLoading} = useQuery('unverified', getUnverifiedUsers);
+
+ const deleteUse = useMutation((payload) => deleteUser(payload));
const updateUse = useMutation((id) => updateUser(id, {verified: true}), {
onSuccess: () => {
@@ -33,6 +34,23 @@ const EnrollmentRequests = () => {
sendMessage(payload);
});
+ const handleModalClick = (item) => {
+ deleteUse.mutate(item._id, {
+ onSuccess: () => {
+ setConfirm.mutate({
+ mobile: `+91${item.mobile}`,
+ message: message,
+ });
+ setOpen(false);
+ refetch();
+ },
+ });
+ };
+
+ if (isLoading) {
+ return <Spinner heading='Admin' />;
+ }
+
return (
<div className={styles.unverified_users}>
<Header subheading='Admin' />
@@ -52,9 +70,16 @@ const EnrollmentRequests = () => {
title='Reject'
color='red'
onClick={() => {
- deleteUse.mutate(item._id);
+ setOpen(true);
}}
/>
+ <MessageModal
+ title='Reason for Reject'
+ open={open}
+ setOpen={setOpen}
+ onChange={(e) => setMessage(e.target.value)}
+ onClick={() => handleModalClick(item)}
+ />
</div>
))
) : (
diff --git a/admin/src/pages/UpdateRequests/UpdateRequests.jsx b/admin/src/pages/UpdateRequests/UpdateRequests.jsx
index 91629bd..7888e7f 100644
--- a/admin/src/pages/UpdateRequests/UpdateRequests.jsx
+++ b/admin/src/pages/UpdateRequests/UpdateRequests.jsx
@@ -4,7 +4,7 @@ import Button from '../../components/Button/Button';
import Header from '../../components/Header/Header';
import {
deleteUser,
- getUnverifiedUsers,
+ getUpdatingUsers,
updateUser,
} from '../../services/apiservice';
import {useQuery, useMutation} from 'react-query';
@@ -16,8 +16,8 @@ import Spinner from '../../components/Spinner/Spinner';
const UpdateRequests = () => {
const navigate = useNavigate();
const {data, isLoading, isError, refetch} = useQuery(
- 'unverified',
- getUnverifiedUsers
+ 'updating',
+ getUpdatingUsers
);
const deleteUse = useMutation((id) => deleteUser(id), {
onSuccess: () => {
diff --git a/admin/src/services/apiservice.js b/admin/src/services/apiservice.js
index 2075239..d72a5fb 100644
--- a/admin/src/services/apiservice.js
+++ b/admin/src/services/apiservice.js
@@ -24,12 +24,12 @@ export const deleteUser = async (id) => {
return response;
};
-export const updatingUsers = async () => {
+export const getUpdatingUsers = async () => {
const response = await apiClient.get(`/users/updating`);
return response;
};
export const sendMessage = async (payload) => {
- const response = await apiClient.post('/message', payload);
+ const response = await apiClient.post('/messages', payload);
return response;
};
diff --git a/server/controllers/message.js b/server/controllers/message.js
index 37de7d2..8061c7a 100644
--- a/server/controllers/message.js
+++ b/server/controllers/message.js
@@ -26,4 +26,15 @@ const sendMessage = async (req, res) => {
}
};
-export default {sendOTP, sendMessage};
+const sendMessages = async (req, res) => {
+ const {mobile, message} = req.body;
+
+ try {
+ sendSMS(mobile, message);
+ res.status(200).json({message: 'Message sent successfully'});
+ } catch (error) {
+ res.status(404).json({message: error});
+ }
+};
+
+export default {sendOTP, sendMessage, sendMessages};
diff --git a/server/controllers/users.js b/server/controllers/users.js
index 0d2088b..12d98a4 100644
--- a/server/controllers/users.js
+++ b/server/controllers/users.js
@@ -121,7 +121,10 @@ const deleteUser = async (req, res) => {
const getUpdatingUsers = async (req, res) => {
try {
- const updatingUsers = await UserDetails.find({isUpdating: true});
+ const updatingUsers = await UserDetails.find({
+ isUpdating: true,
+ verified: true,
+ });
return res.status(200).json(updatingUsers);
} catch (error) {
res.status(404).json({message: error.message});
diff --git a/server/routes/message.js b/server/routes/message.js
index 0062838..0ebb7db 100644
--- a/server/routes/message.js
+++ b/server/routes/message.js
@@ -5,5 +5,6 @@ const router = Express.Router();
router.post('/otp', message.sendOTP);
router.post('/message', message.sendMessage);
+router.post('/messages', message.sendMessages);
export default router;