self directory

This commit is contained in:
pawan-dot 2022-10-28 15:17:20 +05:30
parent 6f6a884c54
commit 1064b3c505
15 changed files with 259 additions and 100 deletions

View File

@ -37,7 +37,7 @@ const App = () => {
setUserData(false)
} else {
try {
console.log('requesting user data from server')
// console.log('requesting user data from server')
let response = await axios.get(`/api/v1/user/details`, {
headers: {
Authorization: `Bearer ${token}`,

View File

@ -32,7 +32,7 @@ const _nav = [
{
component: CNavItem,
name: 'Category',
name: 'Categories',
icon: <CIcon icon={cilPencil} customClassName="nav-icon" />,
to: '/category',
},
@ -63,7 +63,7 @@ const _nav = [
{
component: CNavItem,
name: 'Banners',
name: 'Home Page Banners',
icon: <CIcon icon={cilNotes} customClassName="nav-icon" />,
to: '/banner',
},

View File

@ -27,12 +27,12 @@ const AddBanner = () => {
const [image, setImage] = useState("");
const [title, setTitle] = useState("");
const [subTitle, setSubTitle] = useState("");
const [section, setSection] = useState("");
// const [section, setSection] = useState("");
const [startDate, setStartDate] = useState(new Date());
const [endDate, setEndDate] = useState(new Date());
const [subSection, setSubSection] = useState("");
const [category, setCategory] = useState(false);
// const [subSection, setSubSection] = useState("");
// const [category, setCategory] = useState(false);
@ -42,16 +42,16 @@ const AddBanner = () => {
const handleSubmit = async () => {
if (!(title && subTitle && image && section && subSection && startDate && endDate)) {
if (!(title && image && startDate && endDate)) {
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
myForm.set("title", title);
myForm.set("subTitle", subTitle);
myForm.set("section", section);
myForm.set("subSection", subSection);
// myForm.set("subTitle", subTitle);
// myForm.set("section", section);
// myForm.set("subSection", subSection);
myForm.set("startDate", startDate);
myForm.set("endDate", endDate);
myForm.set("image", image);
@ -94,25 +94,25 @@ const AddBanner = () => {
};
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])
// 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 (
<>
@ -136,7 +136,7 @@ const AddBanner = () => {
value={title}
placeholder="Title" />
</CInputGroup>
<CInputGroup className="mb-3">
{/* <CInputGroup className="mb-3">
<CInputGroupText>
<CIcon icon={cilPencil} />
</CInputGroupText>
@ -145,9 +145,9 @@ const AddBanner = () => {
onChange={(e) => setSubTitle(e.target.value)}
value={subTitle}
placeholder="sub title" />
</CInputGroup>
</CInputGroup> */}
<CInputGroup className="mb-3">
{/* <CInputGroup className="mb-3">
<CInputGroupText >
Section
<CIcon icon={cilNotes} />
@ -167,7 +167,7 @@ const AddBanner = () => {
<option value="offers">offers</option>
<option value="category" >category</option>
{/* <option value="6">--select--</option> */}
</select>
@ -187,11 +187,11 @@ const AddBanner = () => {
<option key={index} value={item.name}>{item.name}</option>
))}
{/* <option value="6">--select--</option> */}
</select></>}
</CInputGroup>
</CInputGroup> */}
<CInputGroup className="mb-3">
<CInputGroupText>
Start Date*

View File

@ -69,7 +69,7 @@ function banner() {
<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-BANNER</h4>
<h4 className="mb-3">Home Page Banners</h4>
<Link to="/addbanner"><button type="button" className="btn btn-info float-end mb-3 ml-4"> + Add Banner</button></Link>
{/* <div className="page-title-right">
<ol className="breadcrumb m-0">
@ -97,8 +97,8 @@ function banner() {
<tr>
<th>Title</th>
<th>Image</th>
<th>Section</th>
<th>Sub Section</th>
{/* <th>Section</th>
<th>Sub Section</th> */}
<th>Status</th>
<th>Added On</th>
<th>Action</th>
@ -112,8 +112,8 @@ function banner() {
<img src={`${item?.image.url}`} width="50" alt="" /></td>
<td>{item?.section}</td>
<th>{item?.subSection}</th>
{/* <td>{item?.section}</td>
<th>{item?.subSection}</th> */}
<td>
<span
className={`badge rounded-pill bg-${new Date(`${item?.endDate}`) > new Date() ? "success" : "danger"

View File

@ -29,14 +29,16 @@ const EditBanner = () => {
let history = useHistory();
const [image, setImage] = useState("");
const [title, setTitle] = useState("");
const [subTitle, setSubTitle] = useState("");
const [section, setSection] = useState("");
// const [subTitle, setSubTitle] = useState("");
const [imagesPreview, setImagesPreview] = useState();
// const [section, setSection] = useState("");
const [startDate, setStartDate] = useState("");
const [endDate, setEndDate] = useState("");
const [subSection, setSubSection] = useState("");
const [category, setCategory] = useState(false);
// const [subSection, setSubSection] = useState("");
// const [category, setCategory] = useState(false);
const [loading, setLoading] = useState(false);
//fetch one Offer
@ -46,28 +48,29 @@ const EditBanner = () => {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data.banner)
// console.log(res.data.banner.startDate)
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())
// setSubTitle(res.data.banner.subTitle)
// setSection(res.data.banner.section)
// setSubSection(res.data.banner.subSection)
setImagesPreview(res.data.banner.image.url)
setStartDate(res.data.banner.startDate)
setEndDate(res.data.banner.endDate)
}, [id]);
const handleSubmit = async () => {
if (!(title && subTitle && image && section && subSection && startDate && endDate)) {
if (!(title && startDate && endDate)) {
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
myForm.set("title", title);
myForm.set("subTitle", subTitle);
myForm.set("section", section);
myForm.set("subSection", subSection);
// myForm.set("subTitle", subTitle);
// myForm.set("section", section);
// myForm.set("subSection", subSection);
myForm.set("startDate", startDate);
myForm.set("endDate", endDate);
myForm.set("image", image);
@ -97,13 +100,31 @@ const EditBanner = () => {
};
// const handleImage = (e) => {
// const files = e.target.files[0];
// // console.log(files)
// setImage(files);
// };
// //
const handleImage = (e) => {
const files = e.target.files[0];
// console.log(files)
setImage(files);
// only for file preview------------------------------------
const Reader = new FileReader();
Reader.readAsDataURL(files);
Reader.onload = () => {
if (Reader.readyState === 2) {
setImagesPreview(Reader.result);
}
};
// -----------------------------------------------------------------------------
};
//
const onCancel = () => {
// window.location = "/comproducts";
history.goBack()
@ -111,25 +132,25 @@ 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])
// 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 (
<>
@ -153,7 +174,7 @@ const EditBanner = () => {
value={title}
placeholder="Title" />
</CInputGroup>
<CInputGroup className="mb-3">
{/* <CInputGroup className="mb-3">
<CInputGroupText>
<CIcon icon={cilPencil} />
</CInputGroupText>
@ -162,9 +183,9 @@ const EditBanner = () => {
onChange={(e) => setSubTitle(e.target.value)}
value={subTitle}
placeholder="sub title" />
</CInputGroup>
</CInputGroup> */}
<CInputGroup className="mb-3">
{/* <CInputGroup className="mb-3">
<CInputGroupText>
<CIcon icon={cilNotes} />
@ -183,7 +204,7 @@ const EditBanner = () => {
<option value="events">events</option>
<option value="offers">offers</option>
<option value="category" >category</option>
{/* <option value="6">--select--</option> */}
</select>
{category && <>
@ -202,11 +223,11 @@ const EditBanner = () => {
<option key={index} value={item.name}>{item.name}</option>
))}
{/* <option value="6">--select--</option> */}
</select></>}
</CInputGroup>
</CInputGroup> */}
<CInputGroup className="mb-3">
<CInputGroupText>
Start Date*
@ -258,6 +279,12 @@ const EditBanner = () => {
/>
</CInputGroup>
<div id="createProductFormImage" className="w-50 d-flex">
{imagesPreview && <img className=" w-50 p-1 " src={imagesPreview} alt="Product Preview" />}
</div>
</div>
<div className=" d-flex">

View File

@ -59,7 +59,7 @@ function ViewBanner() {
<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-BANNER</h4>
<h4 className="mb-3">Home Page Banner</h4>
<Link to="/addbanner"><button type="button" className="btn btn-info float-end mb-3 ml-4"> + Add New Banner</button></Link>
{/* <div className="page-title-right">
<ol className="breadcrumb m-0">
@ -92,8 +92,8 @@ function ViewBanner() {
<tr> <th>Image</th> <td>
<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>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>

View File

@ -96,7 +96,7 @@ function Products() {
<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-Category</h4>
<h4 className="mb-3">Categories</h4>
<Link to="/addCategory"><button type="button" className="btn btn-info float-end mb-3 ml-4"> + Add Category</button></Link>
{/* <div className="page-title-right">
<ol className="breadcrumb m-0">

View File

@ -29,7 +29,9 @@ const AddProduct = () => {
// console.log(id)
const [image, setImage] = useState("");
const [name, setName] = useState("");
const [imagesPreview, setImagesPreview] = useState();
const [ctegoryBannerImage, setCtegoryBannerImage] = useState("");
const [ctegoryBannerImagePreview, setCtegoryBannerImagePreview] = useState("");
const [loading, setLoading] = useState(false);
useEffect(async () => {
@ -39,7 +41,9 @@ const AddProduct = () => {
},
});
// setImage(res.data.category.image.url)
setImagesPreview(res.data.category.image.url)
setCtegoryBannerImagePreview(res.data.category.category_banner.url)
setName(res.data.category.name)
}, [id]);
@ -83,10 +87,42 @@ const AddProduct = () => {
}
const handleImage = (e) => {
const files = e.target.files[0];
// console.log(files)
setImage(files);
// only for file preview------------------------------------
const Reader = new FileReader();
Reader.readAsDataURL(files);
Reader.onload = () => {
if (Reader.readyState === 2) {
setImagesPreview(Reader.result);
}
};
// -----------------------------------------------------------------------------
};
const handleBannerImage = (e) => {
const files = e.target.files[0];
// console.log(files)
setCtegoryBannerImage(files);
// only for file preview------------------------------------
const Reader = new FileReader();
Reader.readAsDataURL(files);
Reader.onload = () => {
if (Reader.readyState === 2) {
setCtegoryBannerImagePreview(Reader.result);
}
};
// -----------------------------------------------------------------------------
};
//
const onCancel = () => {
history.goBack()
@ -102,7 +138,7 @@ const AddProduct = () => {
<CCard className="mr-4 mx-4">
<CCardBody className="p-4">
<CForm>
<h3 className="mb-4 justify-content-center">Edit {name} Category</h3>
<h3 className="mb-4 justify-content-center">Edit Category</h3>
<div>
<div>
<CInputGroup className="mb-3">
@ -118,7 +154,7 @@ const AddProduct = () => {
<div>category image *</div>
<CInputGroup className="mb-3 mt-2">
<CInputGroup className="mb-1 mt-2">
{/* <CIcon icon={cilLockLocked} /> */}
@ -132,8 +168,13 @@ const AddProduct = () => {
/>
</CInputGroup>
<div id="createProductFormImage" className="w-50 d-flex">
{imagesPreview && <img className=" w-25 p-1 " src={imagesPreview} alt="Product Preview" />}
</div>
<div>category Banner image *</div>
<CInputGroup className="mb-3 mt-2">
<CInputGroup className="mb-1 mt-2">
@ -142,14 +183,22 @@ const AddProduct = () => {
placeholder="image"
accept="image/*"
required
onChange={(e) => setCtegoryBannerImage(e.target.files[0])}
onChange={handleBannerImage}
/>
</CInputGroup>
<div id="createProductFormImage" className="w-50 d-flex">
{ctegoryBannerImagePreview && <img className=" w-25 p-1 " src={ctegoryBannerImagePreview} alt="Product Preview" />}
</div>
</div>
<div className=" d-flex">
<div className="mt-3 d-flex">
<button
onClick={handleSubmit}
type="button"

View File

@ -3,10 +3,12 @@ import React, { useEffect, useState, useCallback, useMemo } from "react";
import { Link } from "react-router-dom";
// import { API } from "../../data";
import { isAutheticated } from "../../auth";
import Pagination from "./Pagination";
const Bisuness = () => {
const [bisuness, setBisuness] = useState([])
const [currentPage, setCurrentPage] = useState(1);
const [postsPerPage] = useState(20);
const token = isAutheticated();
@ -32,7 +34,14 @@ const Bisuness = () => {
getProducts();
}, [getProducts]);
// Get current posts
//pagination
const indexOfLastPost = currentPage * postsPerPage;
const indexOfFirstPost = indexOfLastPost - postsPerPage;
const currentPosts = bisuness.slice(indexOfFirstPost, indexOfLastPost);
// Change page
const paginate = pageNumber => setCurrentPage(pageNumber);
const handleDelete = async (id) => {
let status = window.confirm("Do you want to delete");
@ -102,7 +111,7 @@ const Bisuness = () => {
</tr>
</thead>
<tbody>
{bisuness.map((item, index) =>
{currentPosts.map((item, index) =>
<tr key={index}>
<td>{item?.name} </td>
@ -248,6 +257,9 @@ const Bisuness = () => {
{/* <!-- container-fluid --> */}
</div>
</div>
<Pagination postsPerPage={postsPerPage}
totalPosts={bisuness.length}
paginate={paginate} />
</>
)
}

View File

@ -95,7 +95,7 @@ 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)) {
&& state.category && state.status)) {
return swal('Error!', 'All fields are required', 'error')
}

View File

@ -0,0 +1,25 @@
import React from 'react';
import { Link } from "react-router-dom";
const Pagination = ({ postsPerPage, totalPosts, paginate }) => {
const pageNumbers = [];
for (let i = 1; i <= Math.ceil(totalPosts / postsPerPage); i++) {
pageNumbers.push(i);
}
return (
<nav>
<ul className='ml-3 pagination '>
{pageNumbers.map(number => (
<li key={number} className='page-item'>
<Link onClick={() => paginate(number)} to="/bisuness" className='page-link'>
{number}
</Link>
</li>
))}
</ul>
</nav>
);
};
export default Pagination;

View File

@ -12,7 +12,7 @@ function feedback() {
const [currentPage, setCurrentPage] = useState(1);
const [postsPerPage] = useState(10);
const [postsPerPage] = useState(20);
const token = isAutheticated();
const getRestriction = useCallback(async () => {
@ -96,7 +96,7 @@ function feedback() {
</thead>
<tbody>
{currentPosts && currentPosts.map((item, index) =>
<tr>
<tr key={index}>
<td>{item?.name}</td>
<td>{item?.description}</td>

View File

@ -0,0 +1,25 @@
import React from 'react';
import { Link } from "react-router-dom";
const Pagination = ({ postsPerPage, totalPosts, paginate }) => {
const pageNumbers = [];
for (let i = 1; i <= Math.ceil(totalPosts / postsPerPage); i++) {
pageNumbers.push(i);
}
return (
<nav>
<ul className='ml-3 pagination '>
{pageNumbers.map(number => (
<li key={number} className='page-item'>
<Link onClick={() => paginate(number)} to="/requirement" className='page-link'>
{number}
</Link>
</li>
))}
</ul>
</nav>
);
};
export default Pagination;

View File

@ -5,11 +5,13 @@ import { Link } from "react-router-dom";
import swal from 'sweetalert';
// import { API } from "../../data";
import { isAutheticated } from "../../auth";
import Pagination from "./Pagination";
import RequirementOpt from "./RequirementOpt";
function Requirement() {
const [requirement, setRequirement] = useState([])
const [currentPage, setCurrentPage] = useState(1);
const [postsPerPage] = useState(20);
const token = isAutheticated();
// console.log(token)
const getRequirement = useCallback(async () => {
@ -29,6 +31,21 @@ function Requirement() {
useEffect(() => {
getRequirement();
}, [getRequirement]);
const indexOfLastPost = currentPage * postsPerPage;
const indexOfFirstPost = indexOfLastPost - postsPerPage;
const currentPosts = requirement.slice(indexOfFirstPost, indexOfLastPost);
// Change page
const paginate = pageNumber => setCurrentPage(pageNumber);
const handleApprove = async (id) => {
let status = window.confirm("Do you want to Approve");
if (!status) return;
@ -99,7 +116,7 @@ function Requirement() {
</tr>
</thead>
<tbody>
{requirement && requirement.map((item, index) =>
{currentPosts && currentPosts.map((item, index) =>
<RequirementOpt key={index} item={item} handleApprove={handleApprove} />
)}
</tbody>
@ -115,6 +132,9 @@ function Requirement() {
</div>
{/* <!-- container-fluid --> */}
</div>
<Pagination postsPerPage={postsPerPage}
totalPosts={requirement.length}
paginate={paginate} />
</div>
);
}

View File

@ -9,6 +9,7 @@ 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}`,
@ -18,7 +19,7 @@ const RequirementOpt = ({ item, handleApprove }) => {
},
}
);
// console.log(resp.data)
setUser(resp.data.user)
///approved
@ -36,7 +37,7 @@ const RequirementOpt = ({ item, handleApprove }) => {
setApprove(false)
}
} catch (e) {
console.log(e)
setApprove(false)
}
}
@ -79,7 +80,7 @@ const RequirementOpt = ({ item, handleApprove }) => {
<img src={`${item.image[0]?.url}`} width="50" alt="" />
</td>
<td>{item?.areaOfInterest}</td>
<td>{user?.name}</td>
{user && <td>{user?.name}</td>}
<td>
{/* {item?.addedOn} */}
{new Date(`${item?.createdAt}`).toDateString()}<span> , {`${formatAMPM(item?.createdAt)}`}</span>