Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add inquiries page to admin UI #242

Merged
merged 1 commit into from
May 1, 2024

Conversation

shaunwarman
Copy link
Contributor

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

@titanism titanism merged commit e094ae6 into forwardemail:master May 1, 2024
3 of 4 checks passed
const inquiry = await Inquiries.findById(ctx.params.id);
if (!inquiry) throw Boom.notFound(ctx.translateError('INVALID_INQUIRY'));

await Inquiries.deleteOne({ _id: inquiry.id });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await Inquiries.deleteOne({ id: inquiry.id });

Or

await Inquiries.findByIdAndRemove(inquiry._id);


async function reply(ctx) {
const inquiry = await Inquiries.findById(ctx.params.id);
if (!inquiry) throw Boom.notFound(ctx.translateError('INVALID_INQUIRY'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INVALID_INQUIRY is not defined in config/phrases.js yet

{
$set: { is_resolved: true }
}
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should instead be:

  await Inquiries.findByIdAndUpdate(inquiry._id, {
    $set: { is_resolved: true }
  });

// in bulk to a previous message then let's skip the email
if (!repliedTo.has(user)) {
// eslint-disable-next-line no-await-in-loop
await email({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the await here in the loop would be extra slow if you're doing a lot of inquiries to reply to in production. We could optimize this probably by doing await Emails.create in the future. It's OK for now.

}

// eslint-disable-next-line no-await-in-loop
await Inquiries.findOneAndUpdate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another case where you can use findByIdAndUpdate to keep code a bit cleaner

@@ -43,7 +43,7 @@ async function help(ctx) {

ctx.logger.debug('created inquiry', { inquiry });

await email({
const emaild = await email({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I try not to do stuff like adding a letter at the end because of duplicate variable names. Instead you can rename const email = require('#helpers/email') to const emailHelper = require('#helpers/email') at the top of the file. Then you can do const email = await emailHelper({ .... I do this approach elsewhere in the codebase.

@@ -56,6 +56,15 @@ async function help(ctx) {
}
});

const { subject } = JSON.parse(emaild.message);

await Inquiries.findOneAndUpdate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concept with findByIdAndUpdate to keep code cleaner.

+sortHeader('created_at', 'Created', '#table-inquiries')
th(scope="col")
+sortHeader('updated_at', 'Updated', '#table-inquiries')
if passport && passport.otp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can remove this if passport && passport.otp stuff, guessing it was just extra from a copy/paste that can be removed.

maxlength=300,
rows=8
)
p.form-text.small.text-black.text-themed-50= t("Message has a max of 300 characters.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove maxlength and this p.form-text line.

textarea#input-message.form-control(
rows="8",
required,
maxlength=config.supportRequestMaxLength,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove maxlength here

sqlite: 'ttab -G nodemon sqlite.js',

watch: 'ttab -G gulp watch',
bree: 'nodemon bree.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also remove ttab in package.json and elsewhere?

❯ rg "ttab"
package.json
352:    "ttab": "0.8.0",

README.md
157:You can start any of the services using our pre-built commands to make it easy.  Note that all of these pre-built commands are using [nps](https://github.com/sezna/nps) and [ttab](https://github.com/mklement0/ttab) (it will automatically open a new tab in terminal for you!).
-You can start any of the services using our pre-built commands to make it easy.  Note that all of these pre-built commands are using [nps](https://github.com/sezna/nps) and [ttab](https://github.com/mklement0/ttab) (it will automatically open a new tab in terminal for you!).
+You can start any of the services using our pre-built commands to make it easy.  Note that all of these pre-built commands are using [nps](https://github.com/sezna/nps).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants