Skip to content

Commit 10535b6

Browse files
authored
Merge pull request dubinc#3222 from dubinc/program-reapply
Support re-applying to programs after 30 days
2 parents 8c318d2 + 3db320c commit 10535b6

3 files changed

Lines changed: 58 additions & 14 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
2+
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
3+
import { prisma } from "@dub/prisma";
4+
import { log } from "@dub/utils";
5+
import { NextResponse } from "next/server";
6+
7+
export const dynamic = "force-dynamic";
8+
9+
// This route is used to remove rejected programEnrollments from the database after 30 days so partners can re-apply
10+
// Runs once every day at 02:00:00 AM UTC (0 2 * * *)
11+
// POST /api/cron/cleanup/rejected-applications
12+
export async function POST(req: Request) {
13+
try {
14+
const rawBody = await req.text();
15+
16+
await verifyQstashSignature({
17+
req,
18+
rawBody,
19+
});
20+
21+
// rejected programEnrollments more than 30 days ago
22+
const rejectedProgramEnrollments =
23+
await prisma.programEnrollment.deleteMany({
24+
where: {
25+
status: "rejected",
26+
updatedAt: {
27+
lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30),
28+
},
29+
},
30+
});
31+
32+
console.log(
33+
`Deleted ${rejectedProgramEnrollments.count} rejected programEnrollments (older than 30 days)`,
34+
);
35+
36+
return NextResponse.json({ status: "OK" });
37+
} catch (error) {
38+
await log({
39+
message: `/api/cron/cleanup/rejected-applications failed - ${error.message}`,
40+
type: "errors",
41+
});
42+
43+
return handleAndReturnErrorResponse(error);
44+
}
45+
}

apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/unapproved-program-page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const states: Record<
3434
}),
3535
rejected: () => ({
3636
title: "Application rejected",
37-
description: "Your application has been rejected.",
37+
description:
38+
"Your application has been rejected. You can re-apply in 30 days.",
3839
}),
3940
};
4041

@@ -86,7 +87,7 @@ export function UnapprovedProgramPage({
8687
</h2>
8788
<p className="text-content-subtle [&_strong]:text-content-default mt-2 max-w-sm text-balance text-sm font-medium [&_strong]:font-semibold">
8889
{description}{" "}
89-
{["banned", "rejected"].includes(programEnrollment.status) && (
90+
{programEnrollment.status === "banned" && (
9091
<>
9192
<Link
9293
href={`/messages/${programEnrollment.program.slug}`}

apps/web/ui/partners/program-card.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,18 @@ export function ProgramCard({
5959
<div className="mt-4 flex h-20 items-center justify-center text-balance rounded-md border border-neutral-200 bg-neutral-50 p-5 text-center text-sm text-neutral-500">
6060
{status === "pending" ? (
6161
`Applied ${formatDate(createdAt)}`
62+
) : status === "rejected" ? (
63+
`${statusDescription} You can re-apply in 30 days.`
6264
) : statusDescription ? (
6365
<p>
64-
{` ${statusDescription} `}
65-
{status !== "rejected" && (
66-
<>
67-
<Link
68-
href={`/messages/${program.slug}`}
69-
className="text-neutral-400 underline decoration-dotted underline-offset-2 hover:text-neutral-700"
70-
>
71-
Reach out to the {program.name} team
72-
</Link>{" "}
73-
if you have any questions.
74-
</>
75-
)}
66+
{statusDescription}{" "}
67+
<Link
68+
href={`/messages/${program.slug}`}
69+
className="text-neutral-400 underline decoration-dotted underline-offset-2 hover:text-neutral-700"
70+
>
71+
Reach out to the {program.name} team
72+
</Link>{" "}
73+
if you have any questions.
7674
</p>
7775
) : null}
7876
</div>

0 commit comments

Comments
 (0)