Skip to content

Commit

Permalink
Allow quiet Mod approval
Browse files Browse the repository at this point in the history
  • Loading branch information
mcongrove committed Jan 14, 2025
1 parent fb8560a commit 8940edc
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 31 deletions.
11 changes: 11 additions & 0 deletions src/components/moderation/PendingItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export const PendingItem = ({
children,
createdAt,
onApprove,
onApproveSkipEmail,
onReject,
ownerId,
}: {
carId?: string;
children: React.ReactNode;
createdAt: number;
onApprove: () => void;
onApproveSkipEmail?: () => void;
onReject: () => void;
ownerId?: string;
}) => {
Expand Down Expand Up @@ -102,6 +104,15 @@ export const PendingItem = ({
>
<i className="fa-solid fa-fw fa-check"></i>
</Button>

{onApproveSkipEmail && (
<Button
onClick={onApproveSkipEmail}
className="bg-green-50 hover:bg-green-100 text-green-600 flex items-center justify-center h-8 w-16 gap-2"
>
<i className="fa-solid fa-fw fa-check"></i> 🤫
</Button>
)}
</div>
</div>

Expand Down
18 changes: 17 additions & 1 deletion src/pages/Moderation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export const Moderation = () => {

const handleApprove = async (
type: 'car' | 'carOwner' | 'owner' | 'photo',
id: string
id: string,
skipEmail: boolean = false
) => {
try {
const token = await getToken();
Expand All @@ -197,6 +198,7 @@ export const Moderation = () => {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({ skipEmail }),
}
);

Expand Down Expand Up @@ -460,6 +462,13 @@ export const Moderation = () => {
onApprove={() =>
handleApprove('car', pending.id)
}
onApproveSkipEmail={() =>
handleApprove(
'car',
pending.id,
true
)
}
onReject={() =>
handleReject('car', pending.id)
}
Expand Down Expand Up @@ -517,6 +526,13 @@ export const Moderation = () => {
pending.id
)
}
onApproveSkipEmail={() =>
handleApprove(
'carOwner',
pending.id,
true
)
}
onReject={() =>
handleReject(
'carOwner',
Expand Down
73 changes: 43 additions & 30 deletions src/worker/routes/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ moderationRouter.post(
withModerator(),
async (c) => {
const { id } = c.req.param();
const { skipEmail } = await c.req
.json<{ skipEmail?: boolean }>()
.catch(() => ({ skipEmail: false }));

try {
const db = createDb(c.env.DB);
Expand Down Expand Up @@ -310,21 +313,24 @@ moderationRouter.post(
.get('clerk')
.users.getUser(user_id);

const primaryEmail = requestingUser.emailAddresses.find(
(email) => email.id === requestingUser.primaryEmailAddressId
);

if (primaryEmail) {
const resend = new Resend(c.env.RESEND_API_KEY);

await resend.emails.send({
from: 'Miata Registry <no-reply@miataregistry.com>',
to: primaryEmail.emailAddress,
subject: 'Miata Registry: Car update approved',
react: ApprovedCar({
car_id,
}),
});
if (!skipEmail) {
const primaryEmail = requestingUser.emailAddresses.find(
(email) =>
email.id === requestingUser.primaryEmailAddressId
);

if (primaryEmail) {
const resend = new Resend(c.env.RESEND_API_KEY);

await resend.emails.send({
from: 'Miata Registry <no-reply@miataregistry.com>',
to: primaryEmail.emailAddress,
subject: 'Miata Registry: Car update approved',
react: ApprovedCar({
car_id,
}),
});
}
}
}

Expand Down Expand Up @@ -352,6 +358,9 @@ moderationRouter.post(
withModerator(),
async (c) => {
const { id } = c.req.param();
const { skipEmail } = await c.req
.json<{ skipEmail?: boolean }>()
.catch(() => ({ skipEmail: false }));

try {
const db = createDb(c.env.DB);
Expand Down Expand Up @@ -441,21 +450,25 @@ moderationRouter.post(
.get('clerk')
.users.getUser(user_id);

const primaryEmail = requestingUser.emailAddresses.find(
(email) => email.id === requestingUser.primaryEmailAddressId
);

if (primaryEmail) {
const resend = new Resend(c.env.RESEND_API_KEY);

await resend.emails.send({
from: 'Miata Registry <no-reply@miataregistry.com>',
to: primaryEmail.emailAddress,
subject: 'Miata Registry: Ownership update approved',
react: ApprovedOwner({
car_id: pendingCarOwner.car_id,
}),
});
if (!skipEmail) {
const primaryEmail = requestingUser.emailAddresses.find(
(email) =>
email.id === requestingUser.primaryEmailAddressId
);

if (primaryEmail) {
const resend = new Resend(c.env.RESEND_API_KEY);

await resend.emails.send({
from: 'Miata Registry <no-reply@miataregistry.com>',
to: primaryEmail.emailAddress,
subject:
'Miata Registry: Ownership update approved',
react: ApprovedOwner({
car_id: pendingCarOwner.car_id,
}),
});
}
}
}

Expand Down

0 comments on commit 8940edc

Please sign in to comment.