11 Commits

Author SHA1 Message Date
4a65596283 tweaked get app query to support multiple applications
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m23s
2025-12-08 19:29:59 -05:00
e61bd1c5a1 Enabled restarting your application from denied state
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m23s
2025-12-08 17:10:53 -05:00
df89d9bf67 fixed some missing awaits 2025-12-08 16:24:00 -05:00
4ab803ec72 Fixed hardcoded value in application comment poster 2025-12-08 16:15:34 -05:00
6a55846f19 improved error message readability 2025-12-08 15:21:14 -05:00
c04a2b06cb Fixed glitchtip disabled inversion on API
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m22s
2025-12-08 14:51:02 -05:00
98138f51f4 Fixed glitchtip disabled state inverted (whoops)
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m12s
2025-12-04 23:42:28 -05:00
5a7b3ba2ab fixed application form sizing
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m12s
2025-12-03 19:23:50 -05:00
2de6b18135 Fixed scrolling on unauthroized page 2025-12-03 19:16:10 -05:00
aedcbd9492 Sticky'd navbar
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m11s
2025-12-03 19:14:47 -05:00
f985e0234c Merge pull request 'Onboarding-Reworko' (#52) from Onboarding-Reworko into main
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m11s
Reviewed-on: #52
2025-12-03 16:58:17 -06:00
10 changed files with 150 additions and 80 deletions

View File

@@ -20,8 +20,8 @@ const port = process.env.SERVER_PORT;
//glitchtip setup
const sentry = require('@sentry/node');
if (!process.env.DISABLE_GLITCHTIP) {
console.log("Glitchtip disabled AAAAAA")
if (process.env.DISABLE_GLITCHTIP) {
console.log("Glitchtip disabled")
} else {
let dsn = process.env.GLITCHTIP_DSN;
sentry.init({ dsn: dsn });

View File

@@ -2,11 +2,12 @@ const express = require('express');
const router = express.Router();
import pool from '../db';
import { approveApplication, createApplication, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
import { approveApplication, createApplication, denyApplication, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
import { MemberState, setUserState } from '../services/memberService';
import { getRankByName, insertMemberRank } from '../services/rankService';
import { ApplicationFull, CommentRow } from "@app/shared/types/application"
import { assignUserToStatus } from '../services/statusService';
import { Request, Response } from 'express';
// POST /application
router.post('/', async (req, res) => {
@@ -16,13 +17,13 @@ router.post('/', async (req, res) => {
const appVersion = 1;
createApplication(memberID, appVersion, JSON.stringify(App))
setUserState(memberID, MemberState.Applicant);
await createApplication(memberID, appVersion, JSON.stringify(App))
await setUserState(memberID, MemberState.Applicant);
res.sendStatus(201);
} catch (err) {
console.error('Insert failed:', err);
res.status(500).json({ error: 'Failed to save application' });
console.error('Failed to create application: \n', err);
res.status(500).json({ error: 'Failed to create application' });
}
});
@@ -64,7 +65,6 @@ router.get('/me', async (req, res) => {
// GET /application/:id
router.get('/:id', async (req, res) => {
let appID = req.params.id;
console.log("HELLO")
try {
const application = await getApplicationByID(appID);
if (application === undefined)
@@ -92,9 +92,6 @@ router.post('/approve/:id', async (req, res) => {
const app = await getApplicationByID(appID);
const result = await approveApplication(appID);
console.log("START");
console.log(app, result);
//guard against failures
if (result.affectedRows != 1) {
throw new Error("Something went wrong approving the application");
@@ -119,26 +116,11 @@ router.post('/approve/:id', async (req, res) => {
router.post('/deny/:id', async (req, res) => {
const appID = req.params.id;
const sql = `
UPDATE applications
SET denied_at = NOW()
WHERE id = ?
AND approved_at IS NULL
AND denied_at IS NULL
`;
try {
const result = await pool.execute(sql, appID);
console.log(result);
if (result.affectedRows === 0) {
res.status(400).json('Something went wrong denying the application');
}
if (result.affectedRows == 1) {
res.sendStatus(200);
}
const app = await getApplicationByID(appID);
await denyApplication(appID);
await setUserState(app.member_id, MemberState.Denied);
res.sendStatus(200);
} catch (err) {
console.error('Approve failed:', err);
res.status(500).json({ error: 'Failed to deny application' });
@@ -146,10 +128,12 @@ router.post('/deny/:id', async (req, res) => {
});
// POST /application/:id/comment
router.post('/:id/comment', async (req, res) => {
router.post('/:id/comment', async (req: Request, res: Response) => {
const appID = req.params.id;
const data = req.body.message;
const user = 1;
const user = req.user;
console.log(user)
const sql = `INSERT INTO application_comments(
application_id,
@@ -161,7 +145,7 @@ VALUES(?, ?, ?);`
try {
const conn = await pool.getConnection();
const result = await conn.query(sql, [appID, user, data])
const result = await conn.query(sql, [appID, user.id, data])
console.log(result)
if (result.affectedRows !== 1) {
conn.release();
@@ -186,4 +170,15 @@ VALUES(?, ?, ?);`
}
});
router.post('/restart', async (req: Request, res: Response) => {
const user = req.user.id;
try {
await setUserState(user, MemberState.Guest);
res.sendStatus(200);
} catch (error) {
console.error('Comment failed:', error);
res.status(500).json({ error: 'Could not rester application' });
}
})
module.exports = router;

View File

@@ -1,5 +1,6 @@
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
import pool from "../db";
import { error } from "console";
export async function createApplication(memberID: number, appVersion: number, app: string) {
const sql = `INSERT INTO applications (member_id, app_version, app_data) VALUES (?, ?, ?);`;
@@ -12,12 +13,16 @@ export async function getMemberApplication(memberID: number): Promise<Applicatio
member.name AS member_name
FROM applications AS app
INNER JOIN members AS member ON member.id = app.member_id
WHERE app.member_id = ?;`;
WHERE app.member_id = ? ORDER BY submitted_at DESC LIMIT 1;`;
let app: ApplicationRow[] = await pool.query(sql, [memberID]);
return app[0];
}
// export async function getAllMemberApplications(memberID: number): Promise<ApplicationListRow[]> {
// }
export async function getApplicationByID(appID: number): Promise<ApplicationRow> {
const sql =
`SELECT app.*,
@@ -44,7 +49,7 @@ export async function getApplicationList(): Promise<ApplicationListRow[]> {
return rows;
}
export async function approveApplication(id) {
export async function approveApplication(id: number) {
const sql = `
UPDATE applications
SET approved_at = NOW()
@@ -57,6 +62,24 @@ export async function approveApplication(id) {
return result;
}
export async function denyApplication(id: number) {
const sql = `
UPDATE applications
SET denied_at = NOW()
WHERE id = ?
AND approved_at IS NULL
AND denied_at IS NULL
`;
const result = await pool.execute(sql, id);
if (result.affectedRows == 1) {
return
} else {
throw new Error(`"Something went wrong denying application with ID ${id}`);
}
}
export async function getApplicationComments(appID: number): Promise<CommentRow[]> {
return await pool.query(`SELECT app.id AS comment_id,
app.post_content,

View File

@@ -22,18 +22,20 @@ const environment = import.meta.env.VITE_ENVIRONMENT;
<template>
<div class="flex flex-col min-h-screen">
<Navbar class="flex"></Navbar>
<Alert v-if="environment == 'dev'" class="m-2 mx-auto w-5xl" variant="info">
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
<p>This is a development build of the application. Some features will be unavailable or unstable.</p>
</AlertDescription>
</Alert>
<Alert v-if="userStore.user?.loa?.[0]" class="m-2 mx-auto w-5xl" variant="info">
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
<p>You are on LOA until <strong>{{ formatDate(userStore.user?.loa?.[0].end_date) }}</strong></p>
<Button variant="secondary">End LOA</Button>
</AlertDescription>
</Alert>
<div class="sticky top-0 bg-background z-50">
<Navbar class="flex"></Navbar>
<Alert v-if="environment == 'dev'" class="m-2 mx-auto w-5xl" variant="info">
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
<p>This is a development build of the application. Some features will be unavailable or unstable.</p>
</AlertDescription>
</Alert>
<Alert v-if="userStore.user?.loa?.[0]" class="m-2 mx-auto w-5xl" variant="info">
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
<p>You are on LOA until <strong>{{ formatDate(userStore.user?.loa?.[0].end_date) }}</strong></p>
<Button variant="secondary">End LOA</Button>
</AlertDescription>
</Alert>
</div>
<RouterView class="flex-1 min-h-0"></RouterView>
</div>

View File

@@ -104,6 +104,7 @@ export async function postChatMessage(message: any, post_id: number) {
const response = await fetch(`${addr}/application/${post_id}/comment`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(out),
})
@@ -135,4 +136,15 @@ export async function denyApplication(id: Number) {
if (!res.ok) {
console.error("Something went wrong denying the application")
}
}
export async function restartApplication() {
const res = await fetch(`${addr}/application/restart`, {
method: 'POST',
credentials: 'include'
})
if (!res.ok) {
console.error("Something went wrong restarting your application")
}
}

View File

@@ -20,18 +20,18 @@ import { ApplicationData } from '@/api/application';
const formSchema = toTypedSchema(z.object({
dob: z.string().refine(v => v, { message: "A date of birth is required." }),
name: z.string(),
name: z.string().nonempty(),
playtime: z.coerce.number({ invalid_type_error: "Must be a number", }).min(0, "Cannot be less than 0"),
hobbies: z.string(),
hobbies: z.string().nonempty(),
military: z.boolean(),
communities: z.string(),
joinReason: z.string(),
milsimAttraction: z.string(),
referral: z.string(),
steamProfile: z.string(),
timezone: z.string(),
communities: z.string().nonempty(),
joinReason: z.string().nonempty(),
milsimAttraction: z.string().nonempty(),
referral: z.string().nonempty(),
steamProfile: z.string().nonempty(),
timezone: z.string().nonempty(),
canAttendSaturday: z.boolean(),
interests: z.string(),
interests: z.string().nonempty(),
aknowledgeRules: z.literal(true, {
errorMap: () => ({ message: "Required" })
}),
@@ -82,7 +82,9 @@ onMounted(() => {
<FormControl>
<DateInput :model-value="(value as string) ?? ''" :disabled="readOnly" @update:model-value="handleChange" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -94,7 +96,9 @@ onMounted(() => {
<FormControl>
<Input :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -105,7 +109,9 @@ onMounted(() => {
<FormControl>
<Input type="number" :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -117,7 +123,9 @@ onMounted(() => {
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
:disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -131,7 +139,9 @@ onMounted(() => {
<span>Yes (checked) / No (unchecked)</span>
</div>
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -142,7 +152,9 @@ onMounted(() => {
<FormControl>
<Input :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -154,7 +166,9 @@ onMounted(() => {
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
:disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -166,7 +180,9 @@ onMounted(() => {
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
:disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -178,7 +194,9 @@ onMounted(() => {
<Input placeholder="e.g., Reddit / Member: Alice" :model-value="value" @update:model-value="handleChange"
:disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -194,7 +212,9 @@ onMounted(() => {
<Input type="url" placeholder="https://steamcommunity.com/profiles/7656119..." :model-value="value"
@update:model-value="handleChange" :disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -206,7 +226,9 @@ onMounted(() => {
<Input placeholder="e.g., AEST, EST, UTC+10" :model-value="value" @update:model-value="handleChange"
:disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -220,7 +242,9 @@ onMounted(() => {
<span>Yes (checked) / No (unchecked)</span>
</div>
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -232,7 +256,9 @@ onMounted(() => {
<Input placeholder="e.g., Rifleman; Medic; Pilot" :model-value="value" @update:model-value="handleChange"
:disabled="readOnly" />
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>
@@ -243,11 +269,13 @@ onMounted(() => {
<FormControl>
<div class="flex items-center gap-2">
<Checkbox :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
<span>By checking this box, you accept the <Button variant="link" class="p-0">Code of
<span>By checking this box, you accept the <Button variant="link" class="p-0 h-min">Code of
Conduct</Button>.</span>
</div>
</FormControl>
<FormMessage />
<div class="h-4">
<FormMessage class="text-destructive" />
</div>
</FormItem>
</FormField>

View File

@@ -20,7 +20,7 @@ const app = createApp(App)
app.use(createPinia())
app.use(router)
if (!!import.meta.env.VITE_DISABLE_GLITCHTIP) {
if (!import.meta.env.VITE_DISABLE_GLITCHTIP) {
let dsn = import.meta.env.VITE_GLITCHTIP_DSN;
let environment = import.meta.env.VITE_ENVIRONMENT;

View File

@@ -162,9 +162,9 @@ async function handleDeny(id) {
<div v-else class="flex flex-row justify-between items-center py-2 mb-8">
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">Apply to join the 17th Rangers</h3>
</div>
<ApplicationForm :read-only="readOnly" :data="appData" @submit="(e) => { postApp(e) }" class="mb-7">
<ApplicationForm :read-only="readOnly" :data="appData" @submit="(e) => { postApp(e) }" class="mb-7 pb-15">
</ApplicationForm>
<div v-if="!newApp">
<div v-if="!newApp" class="pb-15">
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight mb-4">Discussion</h3>
<ApplicationChat :messages="chatData" @post="postComment"></ApplicationChat>
</div>

View File

@@ -14,6 +14,7 @@ import { useUserStore } from '@/stores/user';
import { Check, Circle, Dot, Users, X } from 'lucide-vue-next'
import { computed, ref } from 'vue';
import Application from './Application.vue';
import { restartApplication } from '@/api/application';
function goToLogin() {
const redirectUrl = encodeURIComponent(window.location.origin + '/join')
@@ -71,10 +72,18 @@ const currentStep = computed<number>(() => {
})
const finalPanel = ref<'app' | 'message'>('message');
const reloadKey = ref(0);
async function restartApp() {
await restartApplication();
await userStore.loadUser();
reloadKey.value++;
}
</script>
<template>
<div class="flex flex-col items-center mt-10 w-full">
<div class="flex flex-col items-center mt-10 w-full" :key="reloadKey">
<!-- Stepper Container -->
<div class="w-full flex justify-center">
@@ -116,7 +125,7 @@ const finalPanel = ref<'app' | 'message'>('message');
</div>
<!-- Content -->
<div class="mt-12 mb-20 flex w-full justify-center">
<div class="mt-12 mb-20 flex w-full max-w-6xl justify-center">
<div v-if="currentStep === 1" class="w-full max-w-2xl p-8">
<h1 class="text-3xl sm:text-4xl font-bold mb-4 text-left">
Create your account
@@ -133,7 +142,7 @@ const finalPanel = ref<'app' | 'message'>('message');
</div>
<Application v-else-if="currentStep === 2" @submit="userStore.loadUser()" :mode="'create'"></Application>
<Application v-else-if="currentStep === 3" :mode="'view-self'"></Application>
<div v-if="currentStep === 5" class="w-full max-w-4xl p-8 pt-0">
<div v-if="currentStep === 5" class="w-full p-8 pt-0">
<div class="mb-5">
<div class="flex w-min *:px-10 pt-2 border-b *:w-full *:text-center *:pb-1 *:cursor-pointer">
<label :class="finalPanel === 'message' ? 'border-b-3 border-foreground' : 'mb-[2px]'"
@@ -219,8 +228,8 @@ const finalPanel = ref<'app' | 'message'>('message');
</div>
<!-- Denied message -->
<div v-else-if="userStore.state === 'denied'">
<div class="w-full max-w-2xl p-8">
<h1 class="text-3xl sm:text-4xl font-bold mb-4 text-left text-destructive">
<div class="w-full max-w-2xl flex flex-col gap-8">
<h1 class="text-3xl sm:text-4xl font-bold text-left">
Application Not Approved
</h1>
<div class="space-y-4 text-muted-foreground text-left leading-relaxed">
@@ -246,6 +255,7 @@ const finalPanel = ref<'app' | 'message'>('message');
Team</span>
</p>
</div>
<Button class="w-min" @click="restartApp">Restart Application</Button>
</div>
</div>
</div>

View File

@@ -1,5 +1,5 @@
<template>
<div class="min-h-screen flex flex-col items-center justify-center text-center px-6">
<div class="flex flex-col items-center justify-center text-center px-6">
<h1 class="text-5xl font-bold mb-4">Unauthorized</h1>
<p class="text-lg text-muted-foreground max-w-md mb-6">
You don't have permission to access this page.