Skip to content

Commit dc4f6a9

Browse files
author
Ajit Kumar
committed
fix(send email and ui issues)
1 parent 2e96da7 commit dc4f6a9

File tree

14 files changed

+93
-79
lines changed

14 files changed

+93
-79
lines changed

client/main.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,8 @@ footer {
443443
backdrop-filter: blur(20px);
444444
position: relative;
445445
z-index: 0;
446+
}
447+
448+
.text-center {
449+
text-align: center;
446450
}

client/pages/payments/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function Payments() {
3030
};
3131

3232
return (
33-
<div id='payments'>
33+
<div id='payments' className='text-center'>
3434
<h1>Payments</h1>
3535
<div className='payments'>
3636
<ul ref={list} className='list' />
@@ -40,7 +40,7 @@ export default function Payments() {
4040

4141
function Payment({ id, amount, user_name: name, user_email: email, status, created_at: date, payment_method_id: paymentId }) {
4242
return (
43-
<li data-id={id} className={`payment ${status}`} onclick={() => renderPaymentMethod(id, paymentId)}>
43+
<li data-id={id} className={`payment ${status}`} onclick={() => renderPaymentMethod(id, paymentId, amount)}>
4444
<div className='group'>
4545
<strong onclick={updateStatus} data-id={id} className='status'>
4646
{status}
@@ -84,17 +84,13 @@ export default function Payments() {
8484
throw new Error(data);
8585
}
8686

87-
const old = list.get(`[data-id='${id}']`);
88-
const el = Payment(data);
89-
90-
old.replaceWith(el);
91-
el.click();
87+
list.get(`[data-id='${id}']`)?.replaceWith(<Payment {...data} />);
9288
} catch (err) {
9389
alert('ERROR', err.message || err);
9490
}
9591
}
9692

97-
async function renderPaymentMethod(id, pmId) {
93+
async function renderPaymentMethod(id, pmId, amount) {
9894
try {
9995
list.get('li.active')?.classList.remove('active');
10096
list.get(`[data-id='${id}']`)?.classList.add('active');
@@ -148,6 +144,10 @@ export default function Payments() {
148144
<th>Email</th>
149145
<td>{data.user_email}</td>
150146
</tr>
147+
<tr>
148+
<th>Amount</th>
149+
<td>{amount}</td>
150+
</tr>
151151
</>
152152
);
153153
document.body.append($paymentDialog);

client/pages/payments/style.scss

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,25 @@
1616

1717
li {
1818
margin: 10px 10px 0 10px;
19+
text-align: left;
1920

2021
&:first-child {
2122
margin-top: 0;
2223
}
2324

24-
background: linear-gradient(
25-
to bottom right,
25+
background: linear-gradient(to bottom right,
2626
rgb(100, 176, 252),
27-
rgb(4, 64, 99)
28-
);
27+
rgb(4, 64, 99));
2928
color: white;
3029
padding: 10px;
3130
border-radius: 4px;
3231
min-height: 60px;
3332
user-select: none;
3433

3534
&.paid {
36-
background: linear-gradient(
37-
to bottom right,
38-
rgb(0, 255, 0),
39-
rgb(0, 128, 0)
40-
);
35+
background: linear-gradient(to bottom right,
36+
rgb(0, 255, 0),
37+
rgb(0, 128, 0));
4138
}
4239

4340
&.active {
@@ -57,4 +54,4 @@
5754
margin: 0 10px 0 0;
5855
width: calc(100% - 10px);
5956
}
60-
}
57+
}

client/pages/registerUser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default async function registerUser({ mode, redirect }) {
2222
}
2323

2424
return (
25-
<section id='register-user'>
25+
<section id='register-user' className='text-center'>
2626
<h1>{title}</h1>
2727
<AjaxForm
2828
loading={(form) => loadingStart(form, errorText, successText)}

server/apis/admin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ const moment = require('moment');
33
const User = require('../entities/user');
44
const Payment = require('../entities/payment');
55
const PaymentMethod = require('../entities/paymentMethod');
6-
const { getLoggedInUser, sendNotification } = require('../lib/helpers');
6+
const { getLoggedInUser } = require('../lib/helpers');
77
const purchaseOrder = require('../entities/purchaseOrder');
88
const plugin = require('../entities/plugin');
99
const downloadSalesReportCsv = require('../lib/downloadSalesCsv');
10+
const sendEmail = require('../lib/sendEmail');
1011

1112
const router = Router();
1213

@@ -101,7 +102,7 @@ router.patch('/payment', async (req, res) => {
101102
const lastMonth = moment().subtract(1, 'month').format('MM-YYYY');
102103
const message = `Your payment for ${lastMonth} has been sent.`;
103104

104-
sendNotification(user.email, user.name, 'Payment Sent', message);
105+
sendEmail(user.email, user.name, 'Payment Sent', message);
105106
});
106107

107108
router.delete('/user/:id', async (req, res) => {

server/apis/comment.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const { Router } = require('express');
2-
const { getLoggedInUser, sendNotification } = require('../lib/helpers');
2+
const { getLoggedInUser } = require('../lib/helpers');
33
const Comment = require('../entities/comment');
44
const Plugin = require('../entities/plugin');
55
const user = require('../entities/user');
6+
const sendEmail = require('../lib/sendEmail');
67

78
const router = Router();
89

@@ -130,7 +131,7 @@ router.post('/', async (req, res) => {
130131
updateVoteInPlugin(vote, pluginId);
131132
}
132133

133-
sendNotification(plugin.author_email, plugin.author, `Review update for your Acode plugin - ${plugin.name}.`, getNotificationMessage());
134+
sendEmail(plugin.author_email, plugin.author, `Review update for your Acode plugin - ${plugin.name}.`, getNotificationMessage());
134135

135136
return;
136137
}
@@ -152,7 +153,7 @@ router.post('/', async (req, res) => {
152153
res.send({ message: 'Comment added', comment: row });
153154
voteMessage = vote !== Comment.VOTE_NULL ? `${loggedInUser.name} voted ${Comment.getVoteString(vote)}` : '';
154155
commentMessage = comment ? `${loggedInUser.name} commented: ${comment}` : '';
155-
sendNotification(plugin.author_email, plugin.author, `New review for your Acode plugin - ${plugin.name}.`, getNotificationMessage());
156+
sendEmail(plugin.author_email, plugin.author, `New review for your Acode plugin - ${plugin.name}.`, getNotificationMessage());
156157
} catch (error) {
157158
res.status(500).send({ error: error.message });
158159
}
@@ -239,7 +240,7 @@ router.post('/:commentId/reply', async (req, res) => {
239240

240241
try {
241242
const [commenter] = await user.get([user.NAME, user.EMAIL], [user.ID, comment.user_id]);
242-
sendNotification(commenter.email, commenter.name, `Reply to your comment on Acode plugin - ${plugin.name}.`, `<p>${reply}</p>`);
243+
sendEmail(commenter.email, commenter.name, `Reply to your comment on Acode plugin - ${plugin.name}.`, `<p>${reply}</p>`);
243244
} catch (error) {
244245
// eslint-disable-next-line no-console
245246
console.error(error);

server/apis/otp.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { Router } = require('express');
22
const Otp = require('../entities/otp');
3-
const { sendNotification } = require('../lib/helpers');
43
const User = require('../entities/user');
4+
const sendEmail = require('../lib/sendEmail');
55

66
const route = Router();
77

@@ -37,7 +37,8 @@ route.post('/', async (req, res) => {
3737
await Otp.insert([Otp.EMAIL, email], [Otp.OTP, otp]);
3838
res.send({ message: 'OTP sent' });
3939
} catch (error) {
40-
res.status(500).send({ error: error.message });
40+
console.error(error);
41+
res.status(500).send({ error: 'Something went wrong! Please try again later.' });
4142
}
4243
});
4344

@@ -49,7 +50,7 @@ async function sendOtpToEmail(email, name, otp, type) {
4950
message = 'You have requested to reset your password.';
5051
subject = 'OTP for password reset';
5152
}
52-
const res = await sendNotification(
53+
const res = await sendEmail(
5354
email,
5455
name,
5556
subject,

server/apis/plugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const User = require('../entities/user');
99
const Order = require('../entities/purchaseOrder');
1010
const Download = require('../entities/download');
1111
const badWords = require('../badWords.json');
12-
const { getLoggedInUser, sendNotification, getPluginSKU } = require('../lib/helpers');
12+
const { getLoggedInUser, getPluginSKU } = require('../lib/helpers');
13+
const sendEmail = require('../lib/sendEmail');
1314

1415
const androidpublisher = google.androidpublisher('v3');
1516

@@ -448,7 +449,7 @@ router.post('/', async (req, res) => {
448449

449450
User.get([User.EMAIL, User.NAME], [User.ROLE, 'admin']).then((rows) => {
450451
for (const row of rows) {
451-
sendNotification(
452+
sendEmail(
452453
row.email,
453454
row.name,
454455
'New plugin waiting for approval',
@@ -602,7 +603,7 @@ router.patch('/', async (req, res) => {
602603
}
603604
}
604605

605-
sendNotification(email, name, subject, message);
606+
sendEmail(email, name, subject, message);
606607
} catch (error) {
607608
// eslint-disable-next-line no-console
608609
console.log(error);

server/apis/sponsor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const { resolve } = require('node:path');
55
const { existsSync } = require('node:fs');
66
const { google } = require('googleapis');
77
const moment = require('moment');
8-
const { getLoggedInUser, sendNotification } = require('../lib/helpers');
8+
const { getLoggedInUser } = require('../lib/helpers');
9+
const sendEmail = require('../lib/sendEmail');
910

1011
const router = Router();
1112
const androidpublisher = google.androidpublisher('v3');
@@ -101,7 +102,7 @@ router.post('/', async (req, res) => {
101102
);
102103

103104
if (email) {
104-
sendNotification(email, name, 'Thank you for sponsoring Acode', `We appreciate your support, ${name}. Thank you for being a valued sponsor!`);
105+
sendEmail(email, name, 'Thank you for sponsoring Acode', 'Acode team appreciate your support. Thank you for being a valued sponsor!');
105106
}
106107

107108
res.status(201).json({ message: 'Thank you for becoming a sponsor!' });

server/crons/updateEarnings.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
/* eslint-disable no-console */
21
const path = require('node:path');
32
const { config } = require('dotenv');
43
const setAuth = require('../lib/gapis');
54
const updateEarnings = require('../lib/updateEarnings');
6-
const { sendNotification } = require('../lib/helpers');
5+
const sendEmail = require('../lib/sendEmail');
76

87
config({ path: path.resolve(__dirname, '../.env') });
98

109
module.exports = async () => {
1110
try {
1211
await setAuth();
1312
await updateEarnings();
14-
sendNotification('[email protected]', 'Ajit Kumar', 'Monthly cron job completed', 'Cron job completed successfully');
13+
sendEmail('[email protected]', 'Ajit Kumar', 'Monthly cron job completed', 'Cron job completed successfully');
1514
} catch (error) {
16-
// eslint-disable-next-line no-console
17-
sendNotification('[email protected]', 'Ajit Kumar', 'Monthly cron job failed', `Cron job failed, ${error.message}`);
15+
sendEmail('[email protected]', 'Ajit Kumar', 'Monthly cron job failed', `Cron job failed, ${error.message}`);
1816
console.error(error);
1917
}
2018
};

0 commit comments

Comments
 (0)