Skip to content

Commit 1b91b50

Browse files
authored
Merge pull request #213 from hackclub/staging
Ship cutoff
2 parents b0501ec + e0330b7 commit 1b91b50

File tree

2 files changed

+78
-26
lines changed

2 files changed

+78
-26
lines changed

src/routes/dashboard/projects/[id]/ship/+page.server.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from '$lib/server/db/index.js';
2-
import { devlog, project, clubMembership, club } from '$lib/server/db/schema.js';
2+
import { devlog, project, clubMembership, club, ship } from '$lib/server/db/schema.js';
33
import { error, fail, redirect } from '@sveltejs/kit';
4-
import { eq, and, or, sql } from 'drizzle-orm';
4+
import { eq, and, or, sql, desc } from 'drizzle-orm';
55
import type { Actions } from './$types';
66
import { sendSlackDM } from '$lib/server/slack.js';
77
import { isValidUrl } from '$lib/utils';
@@ -10,8 +10,8 @@ import { extname } from 'path';
1010
import { env } from '$env/dynamic/private';
1111
import { PutObjectCommand } from '@aws-sdk/client-s3';
1212
import { S3 } from '$lib/server/s3';
13-
import { ship } from '$lib/server/db/schema.js';
1413
import { sanitizeUrl } from '@braintree/sanitize-url';
14+
import { END_DATE } from '$lib/defs';
1515

1616
export async function load({ params, locals }) {
1717
const id: number = parseInt(params.id);
@@ -74,7 +74,8 @@ export async function load({ params, locals }) {
7474

7575
return {
7676
project: queriedProject,
77-
clubMembership: membership.length > 0 ? membership[0] : null
77+
clubMembership: membership.length > 0 ? membership[0] : null,
78+
lastIsClubsShip: await lastIsClubsShip(id)
7879
};
7980
}
8081

@@ -109,7 +110,7 @@ export const actions = {
109110
});
110111
}
111112

112-
// Double dipping
113+
// Double dipping
113114
if (doubleDippingWith !== 'none' && doubleDippingWith !== 'enclosure') {
114115
return error(400);
115116
}
@@ -233,6 +234,7 @@ export const actions = {
233234
name: project.name,
234235
description: project.description,
235236
url: project.url,
237+
status: project.status,
236238
timeSpent: sql<number>`COALESCE(SUM(${devlog.timeSpent}), 0)`,
237239
devlogCount: sql<number>`COALESCE(COUNT(${devlog.id}), 0)`
238240
})
@@ -267,6 +269,23 @@ export const actions = {
267269
return error(400, { message: 'project must have a description' });
268270
}
269271

272+
// Get club ID if submitting as club
273+
let clubIdForShip: number | null = null;
274+
if (submitAsClub) {
275+
const [membership] = await db
276+
.select({ clubId: clubMembership.clubId })
277+
.from(clubMembership)
278+
.where(eq(clubMembership.userId, locals.user.id))
279+
.limit(1);
280+
if (membership) {
281+
clubIdForShip = membership.clubId;
282+
}
283+
}
284+
285+
if (END_DATE <= new Date() && clubIdForShip === null && (queriedProject.status === 'building' || await lastIsClubsShip(id))) {
286+
return error(400, { message: "can't submit individual project past end date" });
287+
}
288+
270289
// Editor file
271290
const editorFilePath = `ships/editor-files/${crypto.randomUUID()}${extname(editorFile.name)}`;
272291

@@ -299,7 +318,7 @@ export const actions = {
299318
uploadedFileUrl: editorFileExists ? editorFilePath : undefined,
300319

301320
modelFile: modelPath,
302-
doubleDippingWith
321+
doubleDippingWith
303322
})
304323
.where(
305324
and(
@@ -309,19 +328,6 @@ export const actions = {
309328
)
310329
);
311330

312-
// Get club ID if submitting as club
313-
let clubIdForShip: number | null = null;
314-
if (submitAsClub) {
315-
const [membership] = await db
316-
.select({ clubId: clubMembership.clubId })
317-
.from(clubMembership)
318-
.where(eq(clubMembership.userId, locals.user.id))
319-
.limit(1);
320-
if (membership) {
321-
clubIdForShip = membership.clubId;
322-
}
323-
}
324-
325331
await db.insert(ship).values({
326332
userId: locals.user.id,
327333
projectId: queriedProject.id,
@@ -343,3 +349,18 @@ export const actions = {
343349
return redirect(303, '/dashboard/projects');
344350
}
345351
} satisfies Actions;
352+
353+
async function lastIsClubsShip(id: number) {
354+
const [latestShip] = await db
355+
.select({
356+
clubId: ship.clubId
357+
})
358+
.from(ship)
359+
.where(eq(ship.projectId, id))
360+
.orderBy(desc(ship.timestamp))
361+
.limit(1);
362+
363+
if (latestShip && latestShip.clubId) return true;
364+
365+
return false;
366+
}

src/routes/dashboard/projects/[id]/ship/+page.svelte

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import Head from '$lib/components/Head.svelte';
55
import Project from '$lib/components/Project.svelte';
66
import { calculateCurrencyPayout, calculateMinutes } from '$lib/currency';
7+
import { END_DATE } from '$lib/defs';
78
import { MAX_UPLOAD_SIZE } from '../config';
89
import type { PageProps } from './$types';
910
import { Ship, SquarePen } from '@lucide/svelte';
@@ -16,7 +17,11 @@
1617
let editorUrl = $state(data.project.editorUrl);
1718
let editorUploadFile = $state(null);
1819
let modelFile = $state(null);
19-
let submitAsClub = $state(false);
20+
let submitAsClub = $state(
21+
END_DATE <= new Date() && (data.project.status === 'building' || data.lastIsClubsShip) && data.clubMembership
22+
? true
23+
: false
24+
);
2025
2126
let hasEditorFile = $derived((editorUrl || editorUploadFile) && !(editorUrl && editorUploadFile));
2227
@@ -33,6 +38,20 @@
3338
<Head title="Ship project" />
3439

3540
<h1 class="mt-5 mb-3 font-hero text-2xl font-medium">Ship project</h1>
41+
42+
{#if END_DATE <= new Date() && data.project.status == 'building'}
43+
<div
44+
class="mt-3 mb-3 flex flex-col gap-0.5 rounded-lg border-3 border-primary-700 bg-primary-900 p-3"
45+
>
46+
<h2 class="text-xl font-bold text-primary-400">New non-clubs submissions are now closed!</h2>
47+
<p>
48+
Construct has ended for non-clubs projects. The market is still open and you can re-ship
49+
rejected projects, however you can't ship new projects.
50+
</p>
51+
<p class="mt-1">You can still ship new projects as normal for clubs.</p>
52+
</div>
53+
{/if}
54+
3655
<Project
3756
id={data.project.id}
3857
name={data.project.name}
@@ -169,13 +188,19 @@
169188
<div class="mt-1">
170189
<p class="mb-1 font-bold">Submit as</p>
171190
<div class="themed-box flex flex-col gap-2 p-3">
172-
<label class="flex cursor-pointer items-center gap-2">
191+
<label
192+
class="flex items-center gap-2"
193+
class:opacity-50={END_DATE <= new Date() && (data.project.status === 'building' || data.lastIsClubsShip)}
194+
class:cursor-pointer={!(END_DATE <= new Date() && (data.project.status === 'building' || data.lastIsClubsShip))}
195+
class:cursor-not-allowed={END_DATE <= new Date() && (data.project.status === 'building' || data.lastIsClubsShip)}
196+
>
173197
<input
174198
type="radio"
175199
name="submission_type"
176200
value="individual"
177201
checked={!submitAsClub}
178202
onchange={() => (submitAsClub = false)}
203+
disabled={END_DATE <= new Date() && (data.project.status === 'building' || data.lastIsClubsShip)}
179204
class="radio"
180205
/>
181206
<span>Individual submission</span>
@@ -239,10 +264,15 @@
239264
</div>
240265
<div class="mb-1">
241266
{#if data.project.timeSpent >= 60 && data.project.description != '' && data.project.url != ''}
242-
<p class="text-primary-300">
243-
Are you sure you want to ship "{data.project.name}"?
244-
<span class="font-bold">You won't be able to edit it or journal again</span> unless it gets rejected.
245-
</p>
267+
{#if !submitAsClub && END_DATE <= new Date() && data.project.status === 'building'}
268+
<p class="text-red-400">Non-clubs submissions are now closed!</p>
269+
{:else}
270+
<p class="text-primary-300">
271+
Are you sure you want to ship "{data.project.name}"?
272+
<span class="font-bold">You won't be able to edit it or journal again</span> unless it gets
273+
rejected.
274+
</p>
275+
{/if}
246276
{/if}
247277
</div>
248278
<div class="flex flex-row gap-2">
@@ -258,7 +288,8 @@
258288
data.project.description == '' ||
259289
!printablesUrl ||
260290
!hasEditorFile ||
261-
!modelFile}
291+
!modelFile ||
292+
(!submitAsClub && END_DATE <= new Date())}
262293
>
263294
<Ship />
264295
Ship

0 commit comments

Comments
 (0)