Skip to content

Commit

Permalink
Merge branch 'HITK-TECH-Community:main' into admin-profile-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushpatel1248 authored Jun 15, 2024
2 parents e1113b4 + ed6ac50 commit 3b4e0e1
Show file tree
Hide file tree
Showing 22 changed files with 1,239 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/app/routes/broadcast/@validationSchema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const updateBroadcastValidationSchema = Joi.object().keys({
.min(new Date(new Date() - 100000)),
imageUrl: Joi.array().min(1).items(Joi.string().uri()),
tags: Joi.array().min(1).items(Joi.string()),
isApproved: Joi.boolean().required(),
id : Joi.string().min(24).max(24).required()
});

Expand Down
22 changes: 22 additions & 0 deletions backend/app/routes/testimonial/@validationSchema/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Joi = require('joi');

const postTestimonialValidationSchema = Joi.object().keys({
name: Joi.string().required(),
position: Joi.string().required(),
company: Joi.string().required(),
image: Joi.string().uri().required(),
text: Joi.string().required(),
rating: Joi.number().min(1).max(5).required(),
});

const getTestimonialsValidationSchema = Joi.object().keys({
page: Joi.number().min(1).optional(),
company: Joi.string().optional(),
year: Joi.number().optional(),
month: Joi.number().min(1).max(12).optional(),
});

module.exports = {
postTestimonialValidationSchema,
getTestimonialsValidationSchema,
};
27 changes: 27 additions & 0 deletions backend/app/routes/testimonial/deleteTestimonial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const to = require('await-to-js').default;
const Testimonial = require('../../models/Testimonial');
const { ErrorHandler } = require('../../../helpers/error');
const constants = require('../../../constants');

module.exports = async (req, res, next) => {
const [err, testimonial] = await to(Testimonial.findByIdAndDelete(req.params.id));
if (!testimonial) {
const error = new ErrorHandler(constants.ERRORS.INPUT, {
statusCode: 400,
message: "Testimonial doesn't exist",
});
return next(error);
}
if (err) {
const error = new ErrorHandler(constants.ERRORS.DATABASE, {
statusCode: 500,
message: 'Mongo Error: Deletion Failed',
errStack: err,
});
return next(error);
}
res.status(200).send({
message: 'Testimonial deleted successfully',
});
return next();
};
7 changes: 7 additions & 0 deletions backend/app/routes/testimonial/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const router = require('express').Router({ mergeParams: true });
const validationMiddleware = require('../../../helpers/middlewares/validation');
const { authMiddleware } = require('../../../helpers/middlewares/auth');

const { postTestimonialValidationSchema } = require('./@validationSchema');
const postTestimonial = require('./postTestimonial');
const getTestimonials = require('./getTestimonials');
const deleteTestimonial = require('./deleteTestimonial');

router.post('/', validationMiddleware(postTestimonialValidationSchema), authMiddleware, postTestimonial);
router.get('/getTestimonials', getTestimonials);
router.delete('/:id', authMiddleware, deleteTestimonial);

module.exports = router;
21 changes: 21 additions & 0 deletions backend/app/routes/testimonial/postTestimonial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const to = require('await-to-js').default;
const Testimonial = require('../../models/Testimonial');
const { ErrorHandler } = require('../../../helpers/error');
const constants = require('../../../constants');

module.exports = async (req, res, next) => {
const [err, { _id }] = await to(Testimonial.create({ ...req.body }));
if (err) {
const error = new ErrorHandler(constants.ERRORS.DATABASE, {
statusCode: 500,
message: 'Mongo Error: Insertion Failed',
errStack: err,
});
return next(error);
}
res.status(200).send({
message: 'Testimonial added successfully',
id: _id,
});
return next();
};
Binary file added frontend/public/images/testimonialImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions frontend/src/pages/Admin/Admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { useDispatch } from "react-redux";
import { ManageFaq } from "./Components/Faq/ManageFaq";
import { QandA } from "./Components/Faq/Q&A/QandA";
import { Manageqa } from "./Components/Faq/Q&A/ManageQ&A/ManageQ&A";
import { Testimonial } from "./Components/Testimonial";
import { AddTestimonial } from "./Components/Testimonial/AddTestimonial";
import { ManageTestimonial } from "./Components/Testimonial/ManageTestimonial";

export const Admin = (props) => {
const [tab, setTab] = useState(1);
Expand Down Expand Up @@ -177,6 +180,20 @@ export const Admin = (props) => {
<div className={style["span"]}>FAQs and Q&As</div>
</div>
</li>
<li onClick={closeMobileMenu}>
<div
className={
tab === 20 ? style["features-icons"] : style["features-icons1"]
}
onClick={() => setTab(20)}
>
<i
className="fas fa-solid fa-comments fa-fw fa-lg"
aria-hidden="true"
></i>
<div className={style["span"]}>Testimonial</div>
</div>
</li>
<li onClick={closeMobileMenu}>
<div
className={
Expand Down Expand Up @@ -246,6 +263,12 @@ export const Admin = (props) => {
<QandA setQId={setQId} setTab={setTab} tab={tab} />
) : tab === 19 ? (
<Manageqa qId={qId} setTab={setTab} />
) : tab === 20 ? (
<Testimonial setTab={setTab} />
) : tab === 21 ? (
<AddTestimonial setTab={setTab} />
) : tab === 22 ? (
<ManageTestimonial setTab={setTab} />
) : null}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Admin/Components/Broadcast/Broadcast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export function Broadcast(props) {
<AiFillEdit className={style["editt"]} />
</div>
<div className={style["card-content"]}>
<Link
<div
onClick={() => props.setTab(16)}
className={style["main-btn"]}
>
Manage here
</Link>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { IconButton } from "@material-ui/core";
import { useSelector } from "react-redux";
import { SimpleToast } from "../../../../../../components/util/Toast";
import style from "./card.module.scss";
import { deleteBoardcast } from "../../../../../../service/Broadcast.jsx";
import {
UpdateBoardCast,
deleteBoardcast,
} from "../../../../../../service/Broadcast.jsx";

export function Card(props) {
let dark = props.theme;
Expand Down Expand Up @@ -38,14 +41,31 @@ export function Card(props) {
}
setToast({ ...toast, toastStatus: false });
};

async function deleteCard(id) {
const res = await deleteBoardcast(id, setToast, toast);
if (res) {
props.setHandleDelete(props.handleDelete + 1);
}
if (res) {
props.setHandleDelete(props.handleDelete + 1);
}
}

const handleApprove = async () => {
const { project } = props;
const data = {
id: project._id,
content: project.content,
link: project.link,
expiresOn: project.expiresOn,
imageUrl: project.imageUrl,
tags: project.tags,
isApproved: true,
title: project.title,
};
const res = await UpdateBoardCast(data, setToast, toast);
if (res) {
props.setHandleDelete(props.handleDelete + 1);
}
};

const isSuperAdmin = useSelector((state) => state.isSuperAdmin);
const date = new Date(props.project.createdAt.slice(0, 10));
var months = [
Expand Down Expand Up @@ -137,6 +157,24 @@ export function Card(props) {
>
View Details
</button>
<div className={style["button-group"]}>
<button
className={
!props?.project?.isApproved
? style["button-approve"]
: style["button-info"]
}
onClick={!props?.project?.isApproved && handleApprove}
>
{props?.project?.isApproved ? "Approved" : "Approve"}
</button>
<button
className={style["button-delete"]}
onClick={() => deleteCard(props.id)}
>
Reject
</button>
</div>
</div>
</div>
</ReactCardFlip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,66 @@
box-shadow: 0.5em 0.5em 0.5em rgb(54, 53, 53);
}

.button-group {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
gap: 10px;
margin: 5px 2px 5px 2px;
}

.button-approve {
padding: 10px;
border: none;
outline: none;
border-radius: 5px;
background-color: rgb(6, 158, 41);
margin: 5px;
color: #fff;
width: 120px;
font-size: medium;
font-weight: bold;
transition: background-color 200ms;
}

.button-edit:hover {
background-color: rgb(10, 205, 53);
}

.button-info {
padding: 10px;
border: none;
outline: none;
border-radius: 5px;
background-color: rgb(4, 123, 182);
margin: 5px;
color: #fff;
width: 120px;
font-size: medium;
font-weight: bold;
transition: background-color 200ms;
}

.button-delete {
padding: 10px;
border: none;
outline: none;
border-radius: 5px;
background-color: #fc0254;
margin: 5px;
color: #fff;
width: 120px;
font-size: medium;
font-weight: bold;
transition: background-color 200ms;
text-align: center;
}

.button-delete:hover {
background-color: #fc3779;
}

// for dark theme
.card-item-dark {
background-color: #171717;
Expand All @@ -28,7 +88,7 @@
align-items: center;
padding: 1.5em;
color: var(--bs-light);
height: 380px;
height: 410px;
}

.clickable-card:hover {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/pages/Admin/Components/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector } from "react-redux";
import LiveHelpIcon from "@material-ui/icons/LiveHelp";
import PermContactCalendarIcon from "@material-ui/icons/PermContactCalendar";
import { SimpleToast } from "../../../../components/util/Toast";
import Chat from "@material-ui/icons/Chat"

export const Dashboard = (props) => {
const [openLoginSuccess, setOpenLoginSuccessToast] = React.useState(false);
Expand Down Expand Up @@ -50,6 +51,11 @@ export const Dashboard = (props) => {
icon: <LiveHelpIcon style={{ fontSize: 23 }} />,
tab: 5,
},
{
name: "Testimonial",
icon: <Chat style={{ fontSize: 23 }} />,
tab: 20,
},
];

return (
Expand Down
Loading

0 comments on commit 3b4e0e1

Please sign in to comment.