Skip to content

Commit

Permalink
βž• Added approval/reject button in broadcasts (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemu21 authored Jun 14, 2024
1 parent 3fefdb3 commit 7b0f3d4
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 9 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
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
39 changes: 38 additions & 1 deletion frontend/src/service/Broadcast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,41 @@ const postBoardcast = async ( data, setToast, toast) => {
}
};

export { boardcast, customBoardcast, deleteBoardcast, postBoardcast };
const UpdateBoardCast = async (data, setToast, toast) => {
try {
const response = await fetch(`${END_POINT}/broadcast/update`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error("Failed to Approve");
}
setToast({
...toast,
toastMessage: "Successfully Approved",
toastStatus: true,
toastType: "success",
});
return true;
} catch (error) {
console.log("Failed to Approve", error.message);
setToast({
...toast,
toastMessage: "Failed to Approve",
toastStatus: true,
toastType: "error",
});
}
};

export {
boardcast,
customBoardcast,
deleteBoardcast,
postBoardcast,
UpdateBoardCast,
};

0 comments on commit 7b0f3d4

Please sign in to comment.