complete
This commit is contained in:
parent
973783b95a
commit
24dbbd76ce
@ -76,13 +76,13 @@ const App = () => {
|
||||
<Route exact path="/500" name="Page 500" render={(props) => <Page500 {...props} />} />
|
||||
|
||||
|
||||
{/* localStorage.getItem('authToken') ? */}
|
||||
<Route path="/" name="Home" render={(props) => (
|
||||
|
||||
{/* <Route path="/" name="Home" render={(props) => (
|
||||
userdata && userdata?._id ? <DefaultLayout {...props} /> :
|
||||
userdata === false ? <Login {...props} /> : <div></div>
|
||||
)} />
|
||||
{/* < ProtectedRoute path="/" name="Home" render={(props) => <DefaultLayout {...props} />} /> */}
|
||||
)} /> */}
|
||||
|
||||
<Route path="/" name="Home" render={(props) => <DefaultLayout {...props} />} />
|
||||
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
cilChartPie,
|
||||
cilCursor,
|
||||
cilDrop,
|
||||
cilFilterSquare,
|
||||
cilMoney,
|
||||
cilNewspaper,
|
||||
cilNotes,
|
||||
@ -77,6 +78,12 @@ const _nav = [
|
||||
icon: <CIcon icon={cilPuzzle} customClassName="nav-icon" />,
|
||||
to: '/feedback',
|
||||
},
|
||||
{
|
||||
component: CNavItem,
|
||||
name: 'Requirements',
|
||||
icon: <CIcon icon={cilFilterSquare} customClassName="nav-icon" />,
|
||||
to: '/requirement',
|
||||
},
|
||||
{
|
||||
component: CNavItem,
|
||||
name: 'Users',
|
||||
@ -85,6 +92,7 @@ const _nav = [
|
||||
},
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
export default _nav
|
||||
|
@ -53,6 +53,7 @@ export const AppSidebarNav = ({ items }) => {
|
||||
{...rest}
|
||||
>
|
||||
{item.items?.map((item, index) =>
|
||||
|
||||
item.items ? navGroup(item, index) : navItem(item, index),
|
||||
)}
|
||||
</Component>
|
||||
@ -62,7 +63,9 @@ export const AppSidebarNav = ({ items }) => {
|
||||
return (
|
||||
<React.Fragment>
|
||||
{items &&
|
||||
items.map((item, index) => (item.items ? navGroup(item, index) : navItem(item, index)))}
|
||||
items.map((item, index) =>
|
||||
|
||||
(item.items ? navGroup(item, index) : navItem(item, index)))}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import store from './store'
|
||||
import axios from 'axios'
|
||||
|
||||
const setupAxios = () => {
|
||||
//axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
|
||||
axios.defaults.baseURL = 'http://localhost:5000'
|
||||
axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
|
||||
//axios.defaults.baseURL = 'http://localhost:5000'
|
||||
axios.defaults.headers = {
|
||||
'Cache-Control': 'no-cache,no-store',
|
||||
'Pragma': 'no-cache',
|
||||
|
@ -38,6 +38,11 @@ import ViewFeedback from './views/Feedback/ViewFeedback'
|
||||
//cms
|
||||
import Users from './views/Users/users'
|
||||
import ViewUsers from './views/Users/ViewUsers'
|
||||
//Requirement
|
||||
import ViewRequirement from './views/Requirement/ViewRequirement'
|
||||
import Requirement from './views/Requirement/Requirement'
|
||||
import AddRequirement from './views/Requirement/AddRequirement'
|
||||
import EditRequirement from './views/Requirement/EditRequirement'
|
||||
|
||||
// DashBoard
|
||||
const Change_Password = React.lazy(() => import('./views/pages/register/Change_password'))
|
||||
@ -91,11 +96,18 @@ const routes = [
|
||||
//CMS
|
||||
{ path: '/feedback/view/:id', name: 'ViewFeedback', component: ViewFeedback },
|
||||
{ path: '/feedback', name: 'Feedback', component: Feedback },
|
||||
//Requirement
|
||||
{ path: '/requirement/view/:id', name: 'ViewRequirement', component: ViewRequirement },
|
||||
{ path: '/requirement/edit/:id', name: 'EditRequirement', component: EditRequirement },
|
||||
{ path: '/requirement/add/', name: 'AddRequirement', component: AddRequirement },
|
||||
{ path: '/requirement', name: 'Requirement', component: Requirement },
|
||||
|
||||
//Users
|
||||
{ path: '/users/view/:id', name: 'ViewUsers', component: ViewUsers },
|
||||
{ path: '/users', name: 'users', component: Users },
|
||||
|
||||
|
||||
|
||||
//dashboard
|
||||
|
||||
{ path: '/dashboard', name: 'Dashboard', component: Dashboard },
|
||||
|
@ -42,6 +42,10 @@ const AddBanner = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && subTitle && image && section && subSection && startDate && endDate)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -53,22 +57,29 @@ const AddBanner = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.post(
|
||||
`/api/banner/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/banner/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Banner Added Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Banner Added Successfully!", "success");
|
||||
history.goBack();
|
||||
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
CRow,
|
||||
} from '@coreui/react'
|
||||
import CIcon from '@coreui/icons-react'
|
||||
import { cilPencil, cilNotes, cilCalendar } from '@coreui/icons'
|
||||
import { cilPencil, cilNotes, cilCalendar, cilNoteAdd } from '@coreui/icons'
|
||||
const EditBanner = () => {
|
||||
const { id } = useParams();
|
||||
const { token } = isAutheticated();
|
||||
@ -35,6 +35,8 @@ const EditBanner = () => {
|
||||
const [startDate, setStartDate] = useState("");
|
||||
const [endDate, setEndDate] = useState("");
|
||||
|
||||
const [subSection, setSubSection] = useState("");
|
||||
const [category, setCategory] = useState(false);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
//fetch one Offer
|
||||
@ -49,38 +51,51 @@ const EditBanner = () => {
|
||||
setTitle(res.data.banner.title)
|
||||
setSubTitle(res.data.banner.subTitle)
|
||||
setSection(res.data.banner.section)
|
||||
setSubSection(res.data.banner.subSection)
|
||||
setStartDate(new Date(res.data.banner.startDate).toLocaleDateString())
|
||||
setEndDate(new Date(res.data.banner.endDate).toLocaleDateString())
|
||||
|
||||
}, [id]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && subTitle && image && section && subSection && startDate && endDate)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
myForm.set("subTitle", subTitle);
|
||||
myForm.set("section", section);
|
||||
myForm.set("subSection", subSection);
|
||||
myForm.set("startDate", startDate);
|
||||
myForm.set("endDate", endDate);
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.put(
|
||||
`/api/banner/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/banner/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Banner Updated Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Banner Updated Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
setLoading(false);
|
||||
}
|
||||
// console.log(image)
|
||||
|
||||
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
@ -95,6 +110,27 @@ const EditBanner = () => {
|
||||
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const getData = async () => {
|
||||
let res = await axios.get(
|
||||
`/api/category/getAll`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
console.log(res.data)
|
||||
setCategory(res.data.category)
|
||||
}
|
||||
if (section === "category") {
|
||||
getData()
|
||||
} else {
|
||||
setCategory(false)
|
||||
}
|
||||
}, [section])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="bg-light min-vh-70 d-flex flex-row ">
|
||||
@ -141,16 +177,35 @@ const EditBanner = () => {
|
||||
className="form-control input-field"
|
||||
>
|
||||
|
||||
<option value="1">--select--</option>
|
||||
<option value="1">--Select--</option>
|
||||
<option value="home">home</option>
|
||||
<option value="news">news</option>
|
||||
<option value="events">events</option>
|
||||
<option value="offers">offers</option>
|
||||
<option value="category">category</option>
|
||||
<option value="directory">directory</option>
|
||||
<option value="category" >category</option>
|
||||
{/* <option value="6">--select--</option> */}
|
||||
|
||||
</select>
|
||||
{category && <>
|
||||
<CInputGroupText className="ml-2 mt-1">
|
||||
SubSection
|
||||
<CIcon icon={cilNoteAdd} />
|
||||
</CInputGroupText>
|
||||
<select
|
||||
name="subSection"
|
||||
value={subSection}
|
||||
onChange={(e) => setSubSection(e.target.value)}
|
||||
className="form-control input-field mt-1"
|
||||
>
|
||||
<option value="1">--Select SubCategory--</option>
|
||||
{category.map((item, index) => (
|
||||
|
||||
<option value={item.name}>{item.name}</option>
|
||||
))}
|
||||
{/* <option value="6">--select--</option> */}
|
||||
|
||||
|
||||
</select></>}
|
||||
</CInputGroup>
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
|
@ -93,6 +93,7 @@ function ViewBanner() {
|
||||
<img src={`${banner.image?.url}`} width="50" alt="" />
|
||||
</td></tr>
|
||||
<tr><th>Section</th><td>{banner?.section}</td></tr>
|
||||
<tr> <th>Sub Section</th><td>{banner?.subSection}</td></tr>
|
||||
<tr><th>Start Date</th> <td>
|
||||
{new Date(`${banner?.startDate}`).toDateString()}
|
||||
</td></tr>
|
||||
|
@ -47,27 +47,32 @@ const EditCms = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
|
||||
changeState({ loading: true });
|
||||
let res = await axios.put(
|
||||
`/api/restriction/update/${id}`,
|
||||
{
|
||||
...state,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/restriction/update/${id}`,
|
||||
{
|
||||
...state,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
//if (res.status === 200) window.location.reload();
|
||||
// console.log(res.data)
|
||||
// console.log(res.status == 200)
|
||||
if (res.data.success == true) {
|
||||
changeState({ loading: false });
|
||||
swal("Edit CMP-Condition successfully!");
|
||||
history.goBack()
|
||||
}
|
||||
);
|
||||
//if (res.status === 200) window.location.reload();
|
||||
// console.log(res.data)
|
||||
// console.log(res.status == 200)
|
||||
if (res.data.success == true) {
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
changeState({ loading: false });
|
||||
swal("Edit CMP-Condition successfully!");
|
||||
history.goBack()
|
||||
}
|
||||
|
||||
};
|
||||
const onCancel = () => {
|
||||
// window.location = "/comproducts";
|
||||
|
@ -31,6 +31,10 @@ const AddProduct = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(name && image)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("name", name);
|
||||
@ -39,22 +43,29 @@ const AddProduct = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.post(
|
||||
`/api/category/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
// Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/category/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
// Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
//console.log(res.data.data.name)
|
||||
if (res.data) {
|
||||
swal("success!", "Category Added Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
//console.log(res.data.data.name)
|
||||
if (res.data) {
|
||||
swal("success!", "Category Added Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert("something went wrong")
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -43,6 +43,10 @@ const AddProduct = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(name && image)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("name", name);
|
||||
@ -51,23 +55,27 @@ const AddProduct = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.put(
|
||||
`/api/category/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
// Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/category/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
// Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
//console.log(res.data.data.name)
|
||||
if (res.data) {
|
||||
swal("success!", "Category Edited Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
//console.log(res.data.data.name)
|
||||
if (res.data) {
|
||||
swal("success!", "Category Edited Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert("something went wrong")
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
}
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
// console.log(files)
|
||||
|
@ -73,6 +73,12 @@ const Add_Business = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(state.name && state.phone && state.email && state.Bname && state.Sname && state.country && state.city && state.description
|
||||
&& state.category && state.status && image)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
|
||||
const myForm = new FormData();
|
||||
myForm.set('name', state.name)
|
||||
myForm.set('phone', state.phone)
|
||||
@ -92,35 +98,34 @@ const Add_Business = () => {
|
||||
myForm.set('FacebookUrl', state.FacebookUrl)
|
||||
myForm.set('InstagramUrl', state.InstagramUrl)
|
||||
myForm.set("image", image);
|
||||
// if (!(name || description || phone || email || Bname || Sname || city)) {
|
||||
// alert("Please fill required field ");
|
||||
// return;
|
||||
// }
|
||||
// const myForm = new FormData();
|
||||
// myForm.set("image", image);
|
||||
|
||||
|
||||
changeState({ loading: true });
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/directory/create/`,
|
||||
|
||||
let res = await axios.post(
|
||||
`/api/directory/create/`,
|
||||
|
||||
myForm
|
||||
,
|
||||
{
|
||||
headers: {
|
||||
"content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
myForm
|
||||
,
|
||||
{
|
||||
headers: {
|
||||
"content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
//if (res.status === 200) window.location.reload();
|
||||
console.log(res.status == 201)
|
||||
if (res.status == 201) {
|
||||
changeState({ loading: false });
|
||||
swal("Add Business successfully!");
|
||||
history.goBack()
|
||||
}
|
||||
);
|
||||
//if (res.status === 200) window.location.reload();
|
||||
console.log(res.status == 201)
|
||||
if (res.status == 201) {
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
changeState({ loading: false });
|
||||
swal("Add Business successfully!");
|
||||
history.goBack()
|
||||
}
|
||||
|
||||
};
|
||||
const onCancel = () => {
|
||||
// window.location = "/comproducts";
|
||||
|
@ -94,6 +94,11 @@ const EditBisuness = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(state.name && state.phone && state.email && state.Building_Name && state.Street_Name && state.country && state.city && state.description
|
||||
&& state.category && state.status && image)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
myForm.set('name', state.name)
|
||||
myForm.set('phone', state.phone)
|
||||
@ -115,23 +120,28 @@ const EditBisuness = () => {
|
||||
myForm.set("image", image);
|
||||
|
||||
changeState({ loading: true });
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/directory/update/${id}`,
|
||||
myForm,
|
||||
{
|
||||
headers: {
|
||||
"content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
let res = await axios.put(
|
||||
`/api/directory/update/${id}`,
|
||||
myForm,
|
||||
{
|
||||
headers: {
|
||||
"content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
if (res.status == 200) {
|
||||
changeState({ loading: false });
|
||||
swal("Edit Business successfully!");
|
||||
history.goBack()
|
||||
}
|
||||
);
|
||||
|
||||
if (res.status == 200) {
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
changeState({ loading: false });
|
||||
swal("Edit Business successfully!");
|
||||
history.goBack()
|
||||
}
|
||||
|
||||
};
|
||||
const onCancel = () => {
|
||||
history.goBack()
|
||||
|
@ -33,6 +33,10 @@ const AddEvent = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && description && image && location)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -41,22 +45,29 @@ const AddEvent = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.post(
|
||||
`/api/event/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/event/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Added Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Added Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert("Something went Wrong")
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -48,6 +48,10 @@ const EditEvent = () => {
|
||||
}, [id]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && description && image && location)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -56,22 +60,30 @@ const EditEvent = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.put(
|
||||
`/api/event/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/event/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Edit Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Edit Successfully!", "success");
|
||||
history.goBack();
|
||||
|
||||
} catch (error) {
|
||||
alert("Something went Wrong")
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -30,6 +30,10 @@ const AddNews = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && description && image)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -37,22 +41,29 @@ const AddNews = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.post(
|
||||
`/api/news/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/news/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "News Added Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "News Added Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -45,6 +45,10 @@ const EditNews = () => {
|
||||
}, [id]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && description && image)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -52,22 +56,29 @@ const EditNews = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.put(
|
||||
`/api/news/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/news/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "News Edit Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "News Edit Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert(error)
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -62,6 +62,10 @@ const AddOffer = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && description && image && location && sendBisunessName)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -71,22 +75,29 @@ const AddOffer = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.post(
|
||||
`/api/offer/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/offer/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Added Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Added Successfully!", "success");
|
||||
history.goBack();
|
||||
|
||||
} catch (error) {
|
||||
alert("something Went Wrong")
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
@ -71,6 +71,10 @@ const EditOffer = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(title && description && image && location && sendBisunessName)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
@ -80,22 +84,29 @@ const EditOffer = () => {
|
||||
myForm.set("image", image);
|
||||
setLoading({ loading: true });
|
||||
// console.log(image)
|
||||
let res = await axios.put(
|
||||
`/api/offer/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/offer/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Added Successfully!", "success");
|
||||
setLoading(false);
|
||||
history.goBack();
|
||||
}
|
||||
);
|
||||
// console.log(res.data)
|
||||
if (res.data) {
|
||||
swal("success!", "Event Added Successfully!", "success");
|
||||
history.goBack();
|
||||
} catch (error) {
|
||||
alert("something Went Wrong")
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
|
||||
|
||||
};
|
||||
const handleImage = (e) => {
|
||||
const files = e.target.files[0];
|
||||
|
205
src/views/Requirement/AddRequirement.js
Normal file
205
src/views/Requirement/AddRequirement.js
Normal file
@ -0,0 +1,205 @@
|
||||
|
||||
import axios from "axios";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { API } from "../../data";
|
||||
import { isAutheticated } from "../../auth";
|
||||
import ClipLoader from "react-spinners/ClipLoader";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import {
|
||||
CButton,
|
||||
CCard,
|
||||
CCardBody,
|
||||
CCol,
|
||||
CContainer,
|
||||
CForm,
|
||||
CFormInput,
|
||||
CInputGroup,
|
||||
CInputGroupText,
|
||||
CRow,
|
||||
} from '@coreui/react'
|
||||
import CIcon from '@coreui/icons-react'
|
||||
import { cilPencil, cilSettings, cilLockLocked, cilUser, cilBell, cilLocationPin, cilAudioDescription, cilObjectGroup } from '@coreui/icons'
|
||||
const AddRequirement = () => {
|
||||
const token = isAutheticated();
|
||||
// console.log(token)
|
||||
let history = useHistory();
|
||||
|
||||
const [areaOfInterest, setAreaOfInterest] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [title, setTitle] = useState("");
|
||||
const [imagesPreview, setImagesPreview] = useState([]);
|
||||
const [allimage, setAllImage] = useState([]);
|
||||
// const [images, setImages] = useState([]);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleImage = (e) => {
|
||||
|
||||
setAllImage([...allimage, ...e.target.files]);
|
||||
|
||||
// only for file preview------------------------------------
|
||||
const files = Array.from(e.target.files);
|
||||
files.forEach((file) => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = () => {
|
||||
if (reader.readyState === 2) {
|
||||
setImagesPreview((old) => [...old, reader.result]);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file)
|
||||
});
|
||||
// -----------------------------------------------------------------------------
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
myForm.set("description", description);
|
||||
myForm.set("areaOfInterest", areaOfInterest);
|
||||
allimage.forEach((Singleimage) => {
|
||||
myForm.append("image", Singleimage);
|
||||
|
||||
});
|
||||
if (!(title && description && areaOfInterest && allimage[0])) {
|
||||
alert("please fill all fields")
|
||||
return
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
let res = await axios.post(
|
||||
`/api/requirement/create`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (res.data.success === true) {
|
||||
swal("success!", "Requirements Added Successfully!", "success");
|
||||
history.goBack();
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
alert(error)
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const onCancel = () => {
|
||||
history.goBack()
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="bg-light min-vh-70 d-flex flex-row ">
|
||||
<CContainer>
|
||||
<CRow className="align-left w-140">
|
||||
<CCol md={19} lg={27} xl={16}>
|
||||
<CCard className="mx-4">
|
||||
<CCardBody className="p-4">
|
||||
<CForm>
|
||||
<h3 className="mb-4 justify-content-center">Add Requirements</h3>
|
||||
<div>
|
||||
<div>
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
<CIcon icon={cilPencil} />
|
||||
</CInputGroupText>
|
||||
<CFormInput type="text"
|
||||
required
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
value={title}
|
||||
placeholder="Title" />
|
||||
</CInputGroup>
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
<CIcon icon={cilObjectGroup} />
|
||||
</CInputGroupText>
|
||||
<CFormInput type="text"
|
||||
required
|
||||
onChange={(e) => setAreaOfInterest(e.target.value)}
|
||||
value={areaOfInterest}
|
||||
placeholder="Area Of Interest" />
|
||||
</CInputGroup>
|
||||
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
<CIcon icon={cilAudioDescription} />
|
||||
</CInputGroupText>
|
||||
<CFormInput type="text"
|
||||
required
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
value={description}
|
||||
placeholder="Description" />
|
||||
</CInputGroup>
|
||||
|
||||
|
||||
<CInputGroup className="mb-3">
|
||||
|
||||
{/* <CIcon icon={cilLockLocked} /> */}
|
||||
|
||||
<CFormInput
|
||||
type="file"
|
||||
placeholder="image"
|
||||
accept="image/*"
|
||||
name="image"
|
||||
required
|
||||
multiple
|
||||
onChange={handleImage}
|
||||
|
||||
|
||||
/>
|
||||
</CInputGroup>
|
||||
<div><strong className="fs-6 fst-italic">*Please Upload maximum four images</strong></div>
|
||||
|
||||
|
||||
<div id="createProductFormImage" className="w-25 d-flex">
|
||||
|
||||
{imagesPreview.map((image, index) => (
|
||||
<img className=" w-50 p-1 " key={index} src={image} alt="Product Preview" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className=" d-flex">
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
type="button"
|
||||
className="btn mt-1 btn-success btn-login waves-effect waves-light"
|
||||
>
|
||||
<ClipLoader loading={loading} size={18} />
|
||||
{!loading && "Save"}
|
||||
</button>
|
||||
<button
|
||||
onClick={onCancel}
|
||||
type="button"
|
||||
className=" ml-2 mt-1 btn btn-warning btn-cancel waves-effect waves-light"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</CForm>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
</CCol>
|
||||
</CRow>
|
||||
</CContainer>
|
||||
</div>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default AddRequirement
|
220
src/views/Requirement/EditRequirement.js
Normal file
220
src/views/Requirement/EditRequirement.js
Normal file
@ -0,0 +1,220 @@
|
||||
|
||||
|
||||
import axios from "axios";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { API } from "../../data";
|
||||
import { isAutheticated } from "../../auth";
|
||||
import ClipLoader from "react-spinners/ClipLoader";
|
||||
import { useHistory, useParams } from "react-router-dom";
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import {
|
||||
CButton,
|
||||
CCard,
|
||||
CCardBody,
|
||||
CCol,
|
||||
CContainer,
|
||||
CForm,
|
||||
CFormInput,
|
||||
CInputGroup,
|
||||
CInputGroupText,
|
||||
CRow,
|
||||
} from '@coreui/react'
|
||||
import CIcon from '@coreui/icons-react'
|
||||
import { cilPencil, cilSettings, cilLockLocked, cilUser, cilBell, cilLocationPin, cilAudioDescription, cilObjectGroup } from '@coreui/icons'
|
||||
const EditRequirement = () => {
|
||||
const token = isAutheticated();
|
||||
const { id } = useParams()
|
||||
let history = useHistory();
|
||||
const [areaOfInterest, setAreaOfInterest] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [title, setTitle] = useState("");
|
||||
const [imagesPreview, setImagesPreview] = useState([]);
|
||||
const [allimage, setAllImage] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
//fetch one requirement
|
||||
useEffect(async () => {
|
||||
const res = await axios.get(`/api/requirement/getOne/${id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
// console.log(res.data)
|
||||
setTitle(res.data.Requirement.title)
|
||||
setDescription(res.data.Requirement.description)
|
||||
setAreaOfInterest(res.data.Requirement.areaOfInterest)
|
||||
|
||||
|
||||
}, [id]);
|
||||
|
||||
|
||||
const handleImage = (e) => {
|
||||
|
||||
setAllImage([...allimage, ...e.target.files]);
|
||||
|
||||
// only for file preview------------------------------------
|
||||
const files = Array.from(e.target.files);
|
||||
files.forEach((file) => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = () => {
|
||||
if (reader.readyState === 2) {
|
||||
setImagesPreview((old) => [...old, reader.result]);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file)
|
||||
});
|
||||
// -----------------------------------------------------------------------------
|
||||
};
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const myForm = new FormData();
|
||||
|
||||
myForm.set("title", title);
|
||||
myForm.set("description", description);
|
||||
myForm.set("areaOfInterest", areaOfInterest);
|
||||
allimage.forEach((Singleimage) => {
|
||||
myForm.append("image", Singleimage);
|
||||
|
||||
});
|
||||
if (!(title && description && areaOfInterest && allimage[0])) {
|
||||
alert("please fill all fields")
|
||||
return
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
let res = await axios.put(
|
||||
`/api/requirement/update/${id}`, myForm,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": 'multipart/form-data',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (res.data.success === true) {
|
||||
swal("success!", "Requirements Updated Successfully!", "success");
|
||||
history.goBack();
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
alert(error)
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const onCancel = () => {
|
||||
history.goBack()
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="bg-light min-vh-70 d-flex flex-row ">
|
||||
<CContainer>
|
||||
<CRow className="align-left w-140">
|
||||
<CCol md={19} lg={27} xl={16}>
|
||||
<CCard className="mx-4">
|
||||
<CCardBody className="p-4">
|
||||
<CForm>
|
||||
<h3 className="fst-italic mb-4 justify-content-center ">Edit Requirements</h3>
|
||||
<div>
|
||||
<div>
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
<CIcon icon={cilPencil} />
|
||||
</CInputGroupText>
|
||||
<CFormInput type="text"
|
||||
required
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
value={title}
|
||||
placeholder="Title" />
|
||||
</CInputGroup>
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
<CIcon icon={cilObjectGroup} />
|
||||
</CInputGroupText>
|
||||
<CFormInput type="text"
|
||||
required
|
||||
onChange={(e) => setAreaOfInterest(e.target.value)}
|
||||
value={areaOfInterest}
|
||||
placeholder="Area Of Interest" />
|
||||
</CInputGroup>
|
||||
|
||||
<CInputGroup className="mb-3">
|
||||
<CInputGroupText>
|
||||
<CIcon icon={cilAudioDescription} />
|
||||
</CInputGroupText>
|
||||
<CFormInput type="text"
|
||||
required
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
value={description}
|
||||
placeholder="Description" />
|
||||
</CInputGroup>
|
||||
|
||||
|
||||
<CInputGroup className="mb-3">
|
||||
|
||||
{/* <CIcon icon={cilLockLocked} /> */}
|
||||
|
||||
<CFormInput
|
||||
type="file"
|
||||
required
|
||||
placeholder="image"
|
||||
accept="image/*"
|
||||
name="image"
|
||||
|
||||
multiple
|
||||
onChange={handleImage}
|
||||
|
||||
|
||||
/>
|
||||
</CInputGroup>
|
||||
<div><strong className="fs-6 fst-italic">*Please Upload maximum four images</strong></div>
|
||||
|
||||
<div id="createProductFormImage" className="w-25 d-flex">
|
||||
{imagesPreview.map((image, index) => (
|
||||
<img className=" w-50 p-1 " key={index} src={image} alt="Product Preview" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className=" d-flex">
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
type="button"
|
||||
className="btn btn-success btn-login waves-effect waves-light"
|
||||
|
||||
>
|
||||
<ClipLoader loading={loading} size={18} />
|
||||
{!loading && "Save"}
|
||||
</button>
|
||||
<button
|
||||
onClick={onCancel}
|
||||
type="button"
|
||||
className=" ml-2 btn btn-warning btn-cancel waves-effect waves-light"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</CForm>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
</CCol>
|
||||
</CRow>
|
||||
</CContainer>
|
||||
</div>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default EditRequirement
|
122
src/views/Requirement/Requirement.js
Normal file
122
src/views/Requirement/Requirement.js
Normal file
@ -0,0 +1,122 @@
|
||||
|
||||
import axios from "axios";
|
||||
import React, { useEffect, useState, useCallback, useMemo } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import swal from 'sweetalert';
|
||||
// import { API } from "../../data";
|
||||
import { isAutheticated } from "../../auth";
|
||||
import RequirementOpt from "./RequirementOpt";
|
||||
|
||||
function Requirement() {
|
||||
const [requirement, setRequirement] = useState([])
|
||||
|
||||
const token = isAutheticated();
|
||||
// console.log(token)
|
||||
const getRequirement = useCallback(async () => {
|
||||
let res = await axios.get(
|
||||
`/api/requirement/getAll`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
setRequirement(res.data.Requirement)
|
||||
|
||||
}, [token]);
|
||||
|
||||
useEffect(() => {
|
||||
getRequirement();
|
||||
}, [getRequirement]);
|
||||
const handleApprove = async (id) => {
|
||||
let status = window.confirm("Do you want to Approve");
|
||||
if (!status) return;
|
||||
// console.log(email)
|
||||
try {
|
||||
let res = await axios.get(`/api/admin/requirement/approve/${id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
console.log(res.data)
|
||||
getRequirement()
|
||||
if (res.data.success == true) {
|
||||
swal("success!", "Requirement Approved !", "success");
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
swal("Error:!", console.log(error), "error");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className=" main-content">
|
||||
<div className=" my-3 page-content">
|
||||
<div className="container-fluid">
|
||||
{/* <!-- start page title --> */}
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||
<h4 className="mb-3">CMP-Requirements</h4>
|
||||
<Link to="/requirement/add"><button type="button" className="btn btn-info float-end mb-3 ml-4"> + Add Requirements</button></Link>
|
||||
{/* <div className="page-title-right">
|
||||
<ol className="breadcrumb m-0">
|
||||
<li className="breadcrumb-item">
|
||||
<Link to="/dashboard">CMD-App</Link>
|
||||
</li>
|
||||
<li className="breadcrumb-item">CMD-Category</li>
|
||||
</ol>
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* <!-- end page title --> */}
|
||||
|
||||
<div className="row">
|
||||
<div className="col-lg-12">
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="row ml-0 mr-0 mb-10">
|
||||
|
||||
</div>
|
||||
<div className="table-responsive table-shoot">
|
||||
<table className="table table-centered table-nowrap mb-0">
|
||||
<thead className="thead-light">
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Image</th>
|
||||
<th>Area Of Interest</th>
|
||||
<th>Added By</th>
|
||||
<th>Added On</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{requirement && requirement.map((item, index) =>
|
||||
<RequirementOpt key={index} item={item} handleApprove={handleApprove} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
{/* <!-- end table-responsive --> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* <!-- container-fluid --> */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Requirement;
|
132
src/views/Requirement/RequirementOpt.js
Normal file
132
src/views/Requirement/RequirementOpt.js
Normal file
@ -0,0 +1,132 @@
|
||||
import axios from "axios";
|
||||
import React, { useEffect, useState, useCallback, useMemo } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import swal from 'sweetalert';
|
||||
import { isAutheticated } from "../../auth";
|
||||
|
||||
|
||||
const RequirementOpt = ({ item, handleApprove }) => {
|
||||
const [user, setUser] = useState()
|
||||
const [approve, setApprove] = useState(false)
|
||||
const token = isAutheticated();
|
||||
useEffect(async () => {
|
||||
let resp = await axios.get(
|
||||
`/api/v1/admin/user/${item.addedBy}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(resp.data)
|
||||
setUser(resp.data.user)
|
||||
|
||||
///approved
|
||||
const getData = async () => {
|
||||
try {
|
||||
const response = await axios.get(`/api/requirement/getOne/${item._id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
// console.log(response.data)
|
||||
if (response.data.Requirement.approved === true) {
|
||||
setApprove(true)
|
||||
} else {
|
||||
setApprove(false)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
setApprove(false)
|
||||
}
|
||||
}
|
||||
getData()
|
||||
}, [item]);
|
||||
|
||||
|
||||
|
||||
const handleDelete = async (id) => {
|
||||
let status = window.confirm("Do you want to delete");
|
||||
if (!status) return;
|
||||
|
||||
let res = await axios.delete(`/api/requirement/delete/${id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
// console.log(res)
|
||||
if (res.data.success == true) {
|
||||
swal("success!", "Requirement Deleted Successfully!", "success");
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
//change time formate
|
||||
function formatAMPM(date) {
|
||||
var hours = new Date(date).getHours();
|
||||
var minutes = new Date(date).getMinutes();
|
||||
var ampm = hours >= 12 ? 'PM' : 'AM';
|
||||
hours = hours % 12;
|
||||
hours = hours ? hours : 12; // the hour '0' should be '12'
|
||||
minutes = minutes < 10 ? '0' + minutes : minutes;
|
||||
var strTime = hours + ':' + minutes + ' ' + ampm;
|
||||
return strTime;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<tr>
|
||||
<td>{item?.title}</td>
|
||||
<td>
|
||||
<img src={`${item.image[0]?.url}`} width="50" alt="" />
|
||||
</td>
|
||||
<td>{item?.areaOfInterest}</td>
|
||||
<td>{user?.name}</td>
|
||||
<td>
|
||||
{/* {item?.addedOn} */}
|
||||
{new Date(`${item?.createdAt}`).toDateString()}<span> , {`${formatAMPM(item?.createdAt)}`}</span>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
<button
|
||||
disabled={approve}
|
||||
type="button"
|
||||
onClick={() => handleApprove(`${item._id}`)}
|
||||
className={`mt-1 btn btn-${approve ? "success" : "warning"} btn-sm waves-effect waves-light btn-table ml-2`}
|
||||
id="sa-params"
|
||||
>
|
||||
{!approve ? "Approve" : "Approved"}
|
||||
</button>
|
||||
<Link to={`/requirement/view/${item._id}`}>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className=" mx-1 mt-1 btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
||||
>
|
||||
View
|
||||
</button>
|
||||
</Link>
|
||||
<Link to={`/requirement/edit/${item._id}`}>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className=" mx-1 mt-1 btn btn-primary btn-sm waves-effect waves-light btn-table ml-2"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDelete(`${item._id}`)}
|
||||
className="mx-1 mt-1 btn btn-danger btn-sm waves-effect waves-light btn-table ml-2"
|
||||
id="sa-params"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default RequirementOpt
|
142
src/views/Requirement/ViewRequirement.js
Normal file
142
src/views/Requirement/ViewRequirement.js
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
import axios from "axios";
|
||||
import React, { useEffect, useState, useCallback, useMemo } from "react";
|
||||
import swal from 'sweetalert';
|
||||
// import { API } from "../../data";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { isAutheticated } from "../../auth";
|
||||
|
||||
function ViewRequirement() {
|
||||
const [requirement, setRequirement] = useState([])
|
||||
const [allImage, setAllImage] = useState([])
|
||||
const { id } = useParams();
|
||||
// console.log(id)
|
||||
const token = isAutheticated();
|
||||
|
||||
const getUserDetails = useCallback(async () => {
|
||||
|
||||
|
||||
let resp = await axios.get(
|
||||
`/api/requirement/getOne/${id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(resp.data.Requirement.image)
|
||||
setRequirement(resp.data.Requirement)
|
||||
setAllImage(resp.data.Requirement.image)
|
||||
|
||||
|
||||
}, [token]);
|
||||
|
||||
useEffect(() => {
|
||||
getUserDetails();
|
||||
}, [getUserDetails]);
|
||||
|
||||
|
||||
// allImage.map(item => {
|
||||
// console.log(item.url)
|
||||
// })
|
||||
|
||||
|
||||
//change time formate
|
||||
function formatAMPM(date) {
|
||||
var hours = new Date(date).getHours();
|
||||
var minutes = new Date(date).getMinutes();
|
||||
var ampm = hours >= 12 ? 'PM' : 'AM';
|
||||
hours = hours % 12;
|
||||
hours = hours ? hours : 12; // the hour '0' should be '12'
|
||||
minutes = minutes < 10 ? '0' + minutes : minutes;
|
||||
var strTime = hours + ':' + minutes + ' ' + ampm;
|
||||
return strTime;
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className=" main-content">
|
||||
<div className=" my-3 page-content">
|
||||
<div className="container-fluid">
|
||||
{/* <!-- start page title --> */}
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||
<h4 className="mb-3">CMP-User Details</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* <!-- end page title --> */}
|
||||
|
||||
<div className="row">
|
||||
<div className="col-lg-12">
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="row ml-0 mr-0 mb-10">
|
||||
|
||||
</div>
|
||||
<div className="table-responsive table-shoot">
|
||||
<table className="table table-centered table-nowrap mb-0">
|
||||
<thead className="thead-light">
|
||||
|
||||
<tr>
|
||||
<th>User_Id</th>
|
||||
|
||||
<td>{requirement?._id}</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr><th>Title</th>
|
||||
<td>{requirement?.title}</td></tr>
|
||||
|
||||
<tr><th>Area Of Interest</th>
|
||||
<td>{requirement?.areaOfInterest}</td></tr>
|
||||
|
||||
{/* <tr><th>Image</th>
|
||||
|
||||
<td className="d-flex">
|
||||
|
||||
<img src={`${requirement.image[0]?.url}`} width="50" alt="" />
|
||||
</td>
|
||||
|
||||
</tr> */}
|
||||
|
||||
|
||||
{/* <th>Description</th> */}
|
||||
|
||||
|
||||
<tr><th>Description</th>
|
||||
<td>{requirement?.description}</td></tr>
|
||||
|
||||
<tr><th>Added On</th>
|
||||
|
||||
<td>
|
||||
{new Date(`${requirement?.createdAt}`).toDateString()}<span> , {`${formatAMPM(requirement?.createdAt)}`}</span>
|
||||
</td></tr>
|
||||
<tr><th> Updated At</th>
|
||||
<td>
|
||||
{new Date(`${requirement?.updatedAt}`).toDateString()}<span> , {`${formatAMPM(requirement?.updatedAt)}`}</span>
|
||||
</td></tr>
|
||||
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
{/* <!-- end table-responsive --> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* <!-- container-fluid --> */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ViewRequirement;
|
||||
|
@ -34,20 +34,28 @@ const Login = () => {
|
||||
|
||||
const Login = async () => {
|
||||
setLoading({ loading: true })
|
||||
const res = await axios.post("/api/v1/user/login/", auth);
|
||||
if (res.data.success == true) {
|
||||
localStorage.setItem("authToken", res.data.token)
|
||||
history.push('/dashboard')
|
||||
try {
|
||||
const res = await axios.post("/api/v1/user/login/", auth);
|
||||
if (res.data.success == true) {
|
||||
localStorage.setItem("authToken", res.data.token)
|
||||
history.push('/dashboard')
|
||||
setLoading(false);
|
||||
window.location.reload()
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
setLoading(false);
|
||||
alert("Invalid Credential");
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
window.location.reload()
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
alert("Invalid Credentials");
|
||||
setLoading(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-light min-vh-100 d-flex flex-row align-items-center">
|
||||
<CContainer>
|
||||
|
@ -29,6 +29,10 @@ const Register = () => {
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(oldPassword && newPassword && confirmPassword)) {
|
||||
alert("Please fill All required field ");
|
||||
return;
|
||||
}
|
||||
const token = localStorage.getItem("authToken")
|
||||
setLoading({ loading: true })
|
||||
if (newPassword == confirmPassword) {
|
||||
|
Loading…
Reference in New Issue
Block a user