Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vedang8 committed May 1, 2024
1 parent f85940f commit 92cd8f0
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 16 deletions.
36 changes: 31 additions & 5 deletions client/src/pages/Admin/Credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,44 @@ function Credits() {
{
title: "Sender's Name",
dataIndex: "senderName",
render: (_, record) => {
return record.user ? record.user.fname : "";
},
render: (_, record) => (
<span style={{ color: '#203545' }}>
{record.user ? record.user.fname : ""}
</span>
),
},
{
title: "Project Name",
dataIndex: "projectName",
render: (text) => (
<span
style={{
fontSize: "16px",
color: "#652A0E",
backgroundColor: "#FFF39A",
}}
>
{text}
</span>
),
},
{
title: "Start Date",
dataIndex: "startDate",
render: (record) => {
return (
<span style={{ color: "blueviolet" }}>{new Date(record).toLocaleDateString()}</span>
);
}
},
{
title: "End Date",
dataIndex: "endDate",
render: (record) => {
return (
<span style={{ color: "red" }}>{new Date(record).toLocaleDateString()}</span>
);
}
},
{
title: "Baseline Emission Amt",
Expand Down Expand Up @@ -58,8 +81,11 @@ function Credits() {
{
title: "Added On",
dataIndex: "createdAt",
render: (text, record) =>
moment(record.createdAt).format("DD-MM-YYYY hh:mm A"),
render: (text, record) => (
<span style={{ color: '#888' }}>
{moment(record.createdAt).format("DD-MM-YYYY hh:mm A")}
</span>
),
},
{
title: "Action",
Expand Down
13 changes: 11 additions & 2 deletions client/src/pages/Admin/SellCredits.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ function SellCredits() {
},
},
{
title: "Credits",
title: "Carbon Credits",
dataIndex: "sellCredits",
},
{
title: "date",
title: "Bidding Deadline",
dataIndex: "sellBeforeDate",
render: (text, record) =>
moment(record.sellBeforeDate).format("DD-MM-YYYY hh:mm A"),
},
{
title: "Selling Status",
dataIndex: "selling_status",
render: (text, record) => {
return record.selling_status.toUpperCase();
},
},
{
title: "Status",
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/CarbonCredits/Bids.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Bids({ showBidsModal, setShowBidsModal, selectedSellCredit }) {
// notify buyer for the credits
const notify1 = {
title: "Congratulations! 🎉",
message: `You have earned ${selectedSellCredit.sellCredits} Carbon Credits from ${selectedSellCredit.user.fname}`,
message: `You have earned ${selectedSellCredit.sellCredits} Carbon Credits from ${selectedSellCredit.seller.fname}`,
user: id,
onClick: `/profile`,
read: false,
Expand Down
30 changes: 28 additions & 2 deletions client/src/pages/CarbonCredits/Credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ function Credits() {
{
title: "Project Name",
dataIndex: "projectName",
render: (text) => (
<span
style={{
fontSize: "16px",
color: "#652A0E",
backgroundColor: "#FFF39A",
}}
>
{text}
</span>
),
},
{
title: "Project Type",
Expand All @@ -78,7 +89,7 @@ function Credits() {
dataIndex: "startDate",
render: (record) => {
return (
<span>{new Date(record).toLocaleDateString()}</span>
<span style={{ color: "blueviolet" }}>{new Date(record).toLocaleDateString()}</span>
);
}
},
Expand All @@ -87,7 +98,7 @@ function Credits() {
dataIndex: "endDate",
render: (record) => {
return (
<span>{new Date(record).toLocaleDateString()}</span>
<span style={{ color: "red" }}>{new Date(record).toLocaleDateString()}</span>
);
}
},
Expand All @@ -102,14 +113,29 @@ function Credits() {
{
title: "Trees",
dataIndex: "numOfTrees",
render: (record) => {
return (
<span style={{ color: "darkgreen" }}>{record}</span>
);
}
},
{
title: "Solar Panels",
dataIndex: "numOfSolarPanels",
render: (record) => {
return (
<span style={{ color: "darkgreen" }}>{record}</span>
);
}
},
{
title: "Electricity Consumption",
dataIndex: "electricity",
render: (record) => {
return (
<span style={{ color: "darkgreen" }}>{record}</span>
);
}
},
{
title: "Status",
Expand Down
3 changes: 1 addition & 2 deletions client/src/pages/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,14 @@ const Register = () => {
<button className="btn" onClick={addUserdata}>
Sign Up
</button>
<p>
<p className="para">
Already have an Account? <NavLink to="/login">Login</NavLink>
</p>
</form>
</div>
</section>
</div>
</div>

</>
);
};
Expand Down
Binary file added server/certificates/660fb311b30339aae631eda8.pdf
Binary file not shown.
Binary file added server/certificates/660fb3e2b30339aae631f1f6.pdf
Binary file not shown.
11 changes: 9 additions & 2 deletions server/routes/creditsFormRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,17 @@ router.put(
async (req, res) => {
try {
const { status } = req.body;
await CreditForm.findByIdAndUpdate(req.params.id, { status });
const updatedForm = await CreditForm.findByIdAndUpdate(req.params.id, { status });

// send notification to user

const newNotification = new Notification({
user: updatedForm.user,
message: `Your Generation Form has been ${status}`,
title: "Generation Status Updated",
onClick: `/profile`,
read: false,
});
await newNotification.save();
res.send({
success: true,
message: "Form status updated Successfully",
Expand Down
16 changes: 14 additions & 2 deletions server/routes/sellCreditsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { uploadImageCloudinary } = require("../db/uploadClodinary");
const userdb = require("../models/user");
const creditdb = require("../models/credits");
const { serialize } = require("v8");
const Notification = require("../models/notification");

// create a new sell credit form
router.post("/sell-credit-forms", authenticate, async (req, res) => {
Expand All @@ -22,6 +23,18 @@ router.post("/sell-credit-forms", authenticate, async (req, res) => {
await newForm.save();
user.rewardCredits += 25;
await user.save();
// send notification to admin
const admins = await userdb.find({ role: "admin" });
admins.forEach(async (admin) => {
const newNotification = new Notification({
user: admin._id,
message: `New Form added by ${user.fname}`,
title: "Carbon Credits Selling Form",
onClick: `/admin`,
read: false,
});
await newNotification.save();
});
res.send({
success: true,
message: "Form Submitted Successfully",
Expand All @@ -39,8 +52,7 @@ router.get("/get-all-sell-credit-forms", authenticate, async (req, res) => {
try {
const forms = await sell_creditforms
.find()
.populate("user", "fname")
.populate("user", "profilePicture")
.populate("user", "fname profilePicture")
.sort({ createdAt: -1 });
res.send({
success: true,
Expand Down

0 comments on commit 92cd8f0

Please sign in to comment.