Skip to content

Commit

Permalink
fix of accept/reject
Browse files Browse the repository at this point in the history
  • Loading branch information
rajubugude committed Mar 20, 2024
1 parent 8ff64f8 commit 089c43c
Showing 1 changed file with 55 additions and 47 deletions.
102 changes: 55 additions & 47 deletions src/Components/JoinRequests/JoinRequests.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import React, { useState, useEffect } from 'react';
import axios from '../../Utils/axios';
import Loader from '../Loader/Loader';
import { TECollapse } from 'tw-elements-react';
import { SlUser } from 'react-icons/sl';
import { useGlobalContext } from '../../Context/StateContext';
import { FaChevronUp } from 'react-icons/fa';
import { FaChevronDown } from 'react-icons/fa';
import React, { useState, useEffect } from "react";
import axios from "../../Utils/axios";
import Loader from "../Loader/Loader";
import { TECollapse } from "tw-elements-react";
import { SlUser } from "react-icons/sl";
import { useGlobalContext } from "../../Context/StateContext";
import { FaChevronUp } from "react-icons/fa";
import { FaChevronDown } from "react-icons/fa";

const JoinRequests = ({ community }) => {
const { user, token } = useGlobalContext();
const [loading, setLoading] = useState(false);
const [requests, setRequests] = useState([]);
const [activeElement, setActiveElement] = useState('');
const [activeElement, setActiveElement] = useState("");
const [sortedRequests, setSortedRequests] = useState([]);
const [show, setShow] = useState(false);
const [addModalData, setAddModalData] = useState(null);
const [addModalData, setAddModalData] = useState({
request: null,
community: null,
index: null,
id: null
});
const [reject, setReject] = useState(false);
const [rejectModalData, setRejectModalData] = useState(null);
const [showdown, setShowdown] = useState({ ind: null, bool: true });
Expand Down Expand Up @@ -90,7 +95,7 @@ const JoinRequests = ({ community }) => {
<div className="w-full">
<div className="w-full flex flex-row items-center justify-between mb-3">
<input
style={{ border: '2px solid #cbd5e0' }}
style={{ border: "2px solid #cbd5e0" }}
type="text"
onChange={handleChange}
className="w-5/6 md:w-1/2 p-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-green-600 focus:border-transparent"
Expand All @@ -100,15 +105,15 @@ const JoinRequests = ({ community }) => {
<span className="text-gray-600 text-sm font-semibold mr-2">Sort By :</span>
<button
className="px-2 py-2 mr-3 bg-green-200 rounded-xl"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={() => {
handleRank();
}}>
Reputation
</button>
<button
className="px-1 py-1 bg-green-200 rounded-xl"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={() => {
handleDate();
}}>
Expand All @@ -129,10 +134,10 @@ const JoinRequests = ({ community }) => {
key={index}
className={` group relative flex w-full items-center rounded-t-[15px] border-0 bg-white px-2 py-1 md:px-5 md:py-4 text-left text-base text-neutral-800 transition [overflow-anchor:none] hover:z-[2] focus:z-[3] focus:outline-none`}
type="button"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
aria-expanded="true"
aria-controls="collapseOne">
{request.profile_pic_url.includes('None') ? (
{request.profile_pic_url.includes("None") ? (
<SlUser className="w-4 h-4 mr-2" />
) : (
<img
Expand Down Expand Up @@ -164,7 +169,7 @@ const JoinRequests = ({ community }) => {
<div className=" w-full px-2 py-1 md:px-5 md:py-4 bg-green-50">
<div className="flex flex-row items-center">
<div className="flex flex-col items-center mr-6">
{request.profile_pic_url.includes('None') ? (
{request.profile_pic_url.includes("None") ? (
<SlUser className="w-6 h-6 md:w-10 md:h-10 md:w-20 md:h-20 mr-3" />
) : (
<img
Expand Down Expand Up @@ -198,20 +203,22 @@ const JoinRequests = ({ community }) => {
<div className="flex justify-center bg-green-50 p-2">
<button
className="px-2 py-1 mr-3 bg-green-600 rounded-xl text-white"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={() => {
setShow(true);
setAddModalData({
request: request,
community: community,
index: index
index: index,
id: request.id
});
console.log(addModalData);
}}>
Accept
</button>
<button
className="px-2 py-1 bg-red-600 rounded-xl text-white"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={() => {
setReject(true);
setRejectModalData({
Expand All @@ -224,6 +231,29 @@ const JoinRequests = ({ community }) => {
</button>
</div>
</TECollapse>
{show && addModalData && request.id === addModalData.id && (
<AcceptModal
setShow={setShow}
request={addModalData.request}
community={community}
index={addModalData.index}
onDelete={onDelete}
loading={loading}
setLoading={setLoading}
/>
)}

{reject && (
<RejectModal
setReject={setReject}
request={rejectModalData.request}
community={community}
index={rejectModalData.index}
onDelete={onDelete}
loading={loading}
setLoading={setLoading}
/>
)}
</div>
</div>
))
Expand All @@ -232,28 +262,6 @@ const JoinRequests = ({ community }) => {
No Members Found
</div>
)}
{show && (
<AcceptModal
setShow={setShow}
request={addModalData.request}
community={community}
index={addModalData.index}
onDelete={onDelete}
loading={loading}
setLoading={setLoading}
/>
)}
{reject && (
<RejectModal
setReject={setReject}
request={rejectModalData.request}
community={community}
index={rejectModalData.index}
onDelete={onDelete}
loading={loading}
setLoading={setLoading}
/>
)}
</div>
)}
</div>
Expand All @@ -277,7 +285,7 @@ const AcceptModal = ({ setShow, request, community, index, onDelete, loading, se
};
const res = await axios.post(
`/api/community/${community}/approve_request/`,
{ user: request.user_id, status: 'approved' },
{ user: request.user_id, status: "approved" },
config
);

Expand All @@ -301,13 +309,13 @@ const AcceptModal = ({ setShow, request, community, index, onDelete, loading, se
<div className="w-full flex flex-row items-center justify-center">
<button
className="text-sm font-semibold text-white p-1 px-2 mr-2 md:mr-5 rounded-lg bg-green-600 flex"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={handleAccept}>
Yes
</button>
<button
className="text-sm font-semibold text-white p-1 px-2 rounded-lg bg-red-600 flex ml-2"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={() => {
setShow(false);
}}>
Expand Down Expand Up @@ -335,7 +343,7 @@ const RejectModal = ({ setReject, request, community, index, onDelete, loading,
};
const res = await axios.post(
`/api/community/${community}/approve_request/`,
{ user: request.user_id, status: 'rejected' },
{ user: request.user_id, status: "rejected" },
config
);

Expand All @@ -359,13 +367,13 @@ const RejectModal = ({ setReject, request, community, index, onDelete, loading,
<div className="w-full flex flex-row items-center justify-center">
<button
className="text-sm font-semibold text-white p-1 px-2 mr-2 rounded-lg bg-green-600 flex"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={handleReject}>
Yes
</button>
<button
className="text-sm font-semibold text-white p-1 px-2 rounded-lg bg-red-600 flex ml-2"
style={{ cursor: 'pointer' }}
style={{ cursor: "pointer" }}
onClick={() => {
setReject(false);
}}>
Expand Down

0 comments on commit 089c43c

Please sign in to comment.