Skip to content

Commit

Permalink
fixing code
Browse files Browse the repository at this point in the history
  • Loading branch information
IsmetHamzaj committed Oct 8, 2023
1 parent b40f3cc commit 2575590
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/src/Components/protectedRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { hideLoading, showLoading } from "../redux/alertsSlice";
function ProtectedRoute(props) {

const { user ,reloadUser } = useSelector((state) => state.user)
console.log(user)
const dispatch = useDispatch()
const navigate = useNavigate()

Expand Down
4 changes: 4 additions & 0 deletions client/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ label {
width: max-content !important;
}

.full-width-button {
width: 100% !important;
}

.anchor {
color: black !important;
text-decoration: underline;
Expand Down
24 changes: 23 additions & 1 deletion client/src/pages/Admin/DoctorsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { hideLoading, showLoading } from '../../redux/alertsSlice'
import axios from 'axios'
import Layout from '../../Components/Layout'
import { Table } from 'antd'
import { toast } from 'react-hot-toast'

function DoctorsList() {
const [doctors, setDoctors] = useState([])
Expand All @@ -28,6 +29,27 @@ function DoctorsList() {
}


const changeDoctorStatus = async (record, status) => {

try {
dispatch(showLoading())
const response = await axios.post("/api/admin/change-doctor-status", { doctorId: record._id, userId: record.userId, status: status }, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`
}
})
dispatch(hideLoading())
if (response.data.success) {
toast.success(response.data.message)
getDoctorsData()
}
} catch (error) {
toast.error("Something went wrong")
dispatch(hideLoading())
}
}


useEffect(() => {
getDoctorsData()
}, [])
Expand Down Expand Up @@ -60,7 +82,7 @@ function DoctorsList() {
render: (text, record) => {
return (
<div className='d-flex'>
{record.status === "pending" ? (<h1 className='anchor'>Approve</h1>) : (<h1 className='anchor'>Block</h1>)}
{record.status === "pending" ? (<h1 className='anchor' onClick={() => changeDoctorStatus(record, 'approved')}>Approve</h1>) : (<h1 className='anchor' onClick={() => changeDoctorStatus(record, 'blocked')}>Block</h1>)}
{/* {record.status === "pending" && <h1 className='anchor'>Approve</h1>}
{record.status === "approved" && <h1 className='anchor'>Block</h1>} */}
</div>
Expand Down
14 changes: 7 additions & 7 deletions client/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { hideLoading, showLoading } from '../redux/alertsSlice'
const Login = () => {
const dispatch = useDispatch()
const navigate = useNavigate()
const onFinish = async(values) => {
try{
const onFinish = async (values) => {
try {
dispatch(showLoading())
const response = await axios.post('/api/user/login', values)
dispatch(hideLoading())
if(response.data.success) {
if (response.data.success) {
toast.success(response.data.message)
toast("Redirecting to home page")
localStorage.setItem("token", response.data.data)
navigate("/")
}else {
} else {
dispatch(hideLoading())
toast.error(response.data.message)
}
Expand All @@ -28,7 +28,7 @@ const Login = () => {
toast.error("Something went wrong")
}
}
return(
return (
<div className='auth'>
<div className='register-form card p-3'>
<h1 className='card-title'>Welcome back</h1>
Expand All @@ -37,9 +37,9 @@ const Login = () => {
<Input placeholder='Email' type='email' />
</Form.Item>
<Form.Item label='Password:' name='password'>
<Input placeholder='Password' type='password'/>
<Input placeholder='Password' type='password' />
</Form.Item>
<Button className='primary-button my-2' htmlType='submit'>Log In</Button>
<Button className='primary-button my-2 full-width-button' htmlType='submit'>Log In</Button>
<Link className='anchor mt-2' to='/register'>CLICK HERE TO REGISTER</Link>
</Form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Register() {
<Form.Item label='Password:' name='password'>
<Input placeholder='Password' type='password' />
</Form.Item>
<Button className='primary-button my-2' htmlType='submit'>REGISTER</Button>
<Button className='primary-button my-2 full-width-button' htmlType='submit'>REGISTER</Button>
<Link to='/login' className='anchor mt-2'>CLICK HERE TO LOGIN</Link>
</Form>
</div>
Expand Down
36 changes: 35 additions & 1 deletion routes/adminRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ router.get("/get-all-doctors", authMiddleware, async (req, res) => {
success: true,
data: doctors
})
}
}
catch (error) {
console.log(error)
res.status(500).send({
Expand Down Expand Up @@ -44,4 +44,38 @@ router.get("/get-all-users", authMiddleware, async (req, res) => {
})


router.post("/change-doctor-status", authMiddleware, async (req, res) => {
try {
const { doctorId, status } = req.body
const doctor = await Doctor.findByIdAndUpdate(doctorId, {
status
})
const user = await User.findOne({ _id: doctor.userId })
const unseenNotifications = user.unseenNotifications

unseenNotifications.push({
type: "new-doctor-request-changed",
message: `Your doctor account has been ${status}`,
onClickPath: "/notifications"
})
user.isDoctor = status === "approved" ? true : false
await user.save()
console.log(user.unseenNotifications)
// const doctors = await Doctor.find({})

res.status(200).send({
message: "Doctor status updated successfully",
success: true,
data: doctor
})
} catch (error) {
console.log(error)
res.status(500).send({
message: "Error applying doctor account",
success: false,
error
})
}
})

module.exports = router

0 comments on commit 2575590

Please sign in to comment.