Compare commits
11 Commits
dossier-pe
...
#54-Applic
| Author | SHA1 | Date | |
|---|---|---|---|
| e22f164097 | |||
| ae9c7c89b1 | |||
| dab0a7543c | |||
| 63267ac679 | |||
| 4a65596283 | |||
| e61bd1c5a1 | |||
| df89d9bf67 | |||
| 4ab803ec72 | |||
| 6a55846f19 | |||
| c04a2b06cb | |||
| 98138f51f4 |
@@ -20,8 +20,8 @@ const port = process.env.SERVER_PORT;
|
|||||||
|
|
||||||
//glitchtip setup
|
//glitchtip setup
|
||||||
const sentry = require('@sentry/node');
|
const sentry = require('@sentry/node');
|
||||||
if (!process.env.DISABLE_GLITCHTIP) {
|
if (process.env.DISABLE_GLITCHTIP) {
|
||||||
console.log("Glitchtip disabled AAAAAA")
|
console.log("Glitchtip disabled")
|
||||||
} else {
|
} else {
|
||||||
let dsn = process.env.GLITCHTIP_DSN;
|
let dsn = process.env.GLITCHTIP_DSN;
|
||||||
sentry.init({ dsn: dsn });
|
sentry.init({ dsn: dsn });
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
import pool from '../db';
|
import pool from '../db';
|
||||||
import { approveApplication, createApplication, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
|
import { approveApplication, createApplication, denyApplication, getAllMemberApplications, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
|
||||||
import { MemberState, setUserState } from '../services/memberService';
|
import { MemberState, setUserState } from '../services/memberService';
|
||||||
import { getRankByName, insertMemberRank } from '../services/rankService';
|
import { getRankByName, insertMemberRank } from '../services/rankService';
|
||||||
import { ApplicationFull, CommentRow } from "@app/shared/types/application"
|
import { ApplicationFull, CommentRow } from "@app/shared/types/application"
|
||||||
import { assignUserToStatus } from '../services/statusService';
|
import { assignUserToStatus } from '../services/statusService';
|
||||||
|
import { Request, Response } from 'express';
|
||||||
|
|
||||||
// POST /application
|
// POST /application
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
@@ -16,13 +17,13 @@ router.post('/', async (req, res) => {
|
|||||||
|
|
||||||
const appVersion = 1;
|
const appVersion = 1;
|
||||||
|
|
||||||
createApplication(memberID, appVersion, JSON.stringify(App))
|
await createApplication(memberID, appVersion, JSON.stringify(App))
|
||||||
setUserState(memberID, MemberState.Applicant);
|
await setUserState(memberID, MemberState.Applicant);
|
||||||
|
|
||||||
res.sendStatus(201);
|
res.sendStatus(201);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Insert failed:', err);
|
console.error('Failed to create application: \n', err);
|
||||||
res.status(500).json({ error: 'Failed to save application' });
|
res.status(500).json({ error: 'Failed to create application' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,6 +38,20 @@ router.get('/all', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/meList', async (req, res) => {
|
||||||
|
|
||||||
|
let userID = req.user.id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let application = await getAllMemberApplications(userID);
|
||||||
|
|
||||||
|
return res.status(200).json(application);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load applications: \n', error);
|
||||||
|
return res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
router.get('/me', async (req, res) => {
|
router.get('/me', async (req, res) => {
|
||||||
|
|
||||||
let userID = req.user.id;
|
let userID = req.user.id;
|
||||||
@@ -61,10 +76,36 @@ router.get('/me', async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// GET /application/:id
|
||||||
|
router.get('/me/:id', async (req: Request, res: Response) => {
|
||||||
|
let appID = Number(req.params.id);
|
||||||
|
let member = req.user.id;
|
||||||
|
try {
|
||||||
|
const application = await getApplicationByID(appID);
|
||||||
|
if (application === undefined)
|
||||||
|
return res.sendStatus(204);
|
||||||
|
console.log(application.member_id, member)
|
||||||
|
if (application.member_id != member) {
|
||||||
|
return res.sendStatus(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
const comments: CommentRow[] = await getApplicationComments(appID);
|
||||||
|
|
||||||
|
const output: ApplicationFull = {
|
||||||
|
application,
|
||||||
|
comments,
|
||||||
|
}
|
||||||
|
return res.status(200).json(output);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error('Query failed:', err);
|
||||||
|
return res.status(500).json({ error: 'Failed to load application' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// GET /application/:id
|
// GET /application/:id
|
||||||
router.get('/:id', async (req, res) => {
|
router.get('/:id', async (req, res) => {
|
||||||
let appID = req.params.id;
|
let appID = req.params.id;
|
||||||
console.log("HELLO")
|
|
||||||
try {
|
try {
|
||||||
const application = await getApplicationByID(appID);
|
const application = await getApplicationByID(appID);
|
||||||
if (application === undefined)
|
if (application === undefined)
|
||||||
@@ -92,9 +133,6 @@ router.post('/approve/:id', async (req, res) => {
|
|||||||
const app = await getApplicationByID(appID);
|
const app = await getApplicationByID(appID);
|
||||||
const result = await approveApplication(appID);
|
const result = await approveApplication(appID);
|
||||||
|
|
||||||
console.log("START");
|
|
||||||
console.log(app, result);
|
|
||||||
|
|
||||||
//guard against failures
|
//guard against failures
|
||||||
if (result.affectedRows != 1) {
|
if (result.affectedRows != 1) {
|
||||||
throw new Error("Something went wrong approving the application");
|
throw new Error("Something went wrong approving the application");
|
||||||
@@ -119,26 +157,11 @@ router.post('/approve/:id', async (req, res) => {
|
|||||||
router.post('/deny/:id', async (req, res) => {
|
router.post('/deny/:id', async (req, res) => {
|
||||||
const appID = req.params.id;
|
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 {
|
try {
|
||||||
const result = await pool.execute(sql, appID);
|
const app = await getApplicationByID(appID);
|
||||||
|
await denyApplication(appID);
|
||||||
console.log(result);
|
await setUserState(app.member_id, MemberState.Denied);
|
||||||
|
res.sendStatus(200);
|
||||||
if (result.affectedRows === 0) {
|
|
||||||
res.status(400).json('Something went wrong denying the application');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.affectedRows == 1) {
|
|
||||||
res.sendStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Approve failed:', err);
|
console.error('Approve failed:', err);
|
||||||
res.status(500).json({ error: 'Failed to deny application' });
|
res.status(500).json({ error: 'Failed to deny application' });
|
||||||
@@ -146,10 +169,12 @@ router.post('/deny/:id', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// POST /application/:id/comment
|
// 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 appID = req.params.id;
|
||||||
const data = req.body.message;
|
const data = req.body.message;
|
||||||
const user = 1;
|
const user = req.user;
|
||||||
|
|
||||||
|
console.log(user)
|
||||||
|
|
||||||
const sql = `INSERT INTO application_comments(
|
const sql = `INSERT INTO application_comments(
|
||||||
application_id,
|
application_id,
|
||||||
@@ -161,7 +186,7 @@ VALUES(?, ?, ?);`
|
|||||||
try {
|
try {
|
||||||
const conn = await pool.getConnection();
|
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)
|
console.log(result)
|
||||||
if (result.affectedRows !== 1) {
|
if (result.affectedRows !== 1) {
|
||||||
conn.release();
|
conn.release();
|
||||||
@@ -186,4 +211,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;
|
module.exports = router;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
|
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
|
||||||
import pool from "../db";
|
import pool from "../db";
|
||||||
|
import { error } from "console";
|
||||||
|
|
||||||
export async function createApplication(memberID: number, appVersion: number, app: string) {
|
export async function createApplication(memberID: number, appVersion: number, app: string) {
|
||||||
const sql = `INSERT INTO applications (member_id, app_version, app_data) VALUES (?, ?, ?);`;
|
const sql = `INSERT INTO applications (member_id, app_version, app_data) VALUES (?, ?, ?);`;
|
||||||
@@ -12,12 +13,13 @@ export async function getMemberApplication(memberID: number): Promise<Applicatio
|
|||||||
member.name AS member_name
|
member.name AS member_name
|
||||||
FROM applications AS app
|
FROM applications AS app
|
||||||
INNER JOIN members AS member ON member.id = app.member_id
|
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]);
|
let app: ApplicationRow[] = await pool.query(sql, [memberID]);
|
||||||
return app[0];
|
return app[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getApplicationByID(appID: number): Promise<ApplicationRow> {
|
export async function getApplicationByID(appID: number): Promise<ApplicationRow> {
|
||||||
const sql =
|
const sql =
|
||||||
`SELECT app.*,
|
`SELECT app.*,
|
||||||
@@ -44,7 +46,20 @@ export async function getApplicationList(): Promise<ApplicationListRow[]> {
|
|||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function approveApplication(id) {
|
export async function getAllMemberApplications(memberID: number): Promise<ApplicationListRow[]> {
|
||||||
|
const sql = `SELECT
|
||||||
|
app.id,
|
||||||
|
app.member_id,
|
||||||
|
app.submitted_at,
|
||||||
|
app.app_status
|
||||||
|
FROM applications AS app WHERE app.member_id = ? ORDER BY submitted_at DESC;`;
|
||||||
|
|
||||||
|
const rows: ApplicationListRow[] = await pool.query(sql, [memberID])
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function approveApplication(id: number) {
|
||||||
const sql = `
|
const sql = `
|
||||||
UPDATE applications
|
UPDATE applications
|
||||||
SET approved_at = NOW()
|
SET approved_at = NOW()
|
||||||
@@ -57,6 +72,24 @@ export async function approveApplication(id) {
|
|||||||
return result;
|
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[]> {
|
export async function getApplicationComments(appID: number): Promise<CommentRow[]> {
|
||||||
return await pool.query(`SELECT app.id AS comment_id,
|
return await pool.query(`SELECT app.id AS comment_id,
|
||||||
app.post_content,
|
app.post_content,
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ export async function postChatMessage(message: any, post_id: number) {
|
|||||||
|
|
||||||
const response = await fetch(`${addr}/application/${post_id}/comment`, {
|
const response = await fetch(`${addr}/application/${post_id}/comment`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(out),
|
body: JSON.stringify(out),
|
||||||
})
|
})
|
||||||
@@ -121,6 +122,26 @@ export async function getAllApplications(): Promise<ApplicationFull> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function loadMyApplications(): Promise<ApplicationFull> {
|
||||||
|
const res = await fetch(`${addr}/application/meList`, { credentials: 'include' })
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
return res.json()
|
||||||
|
} else {
|
||||||
|
console.error("Something went wrong approving the application")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMyApplication(id: number): Promise<ApplicationFull> {
|
||||||
|
const res = await fetch(`${addr}/application/me/${id}`, { credentials: 'include' })
|
||||||
|
if (res.status === 204) return null
|
||||||
|
if (res.status === 403) throw new Error("Unauthorized");
|
||||||
|
if (!res.ok) throw new Error('Failed to load application')
|
||||||
|
const json = await res.json()
|
||||||
|
// Accept either the object at root or under `application`
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
export async function approveApplication(id: Number) {
|
export async function approveApplication(id: Number) {
|
||||||
const res = await fetch(`${addr}/application/approve/${id}`, { method: 'POST' })
|
const res = await fetch(`${addr}/application/approve/${id}`, { method: 'POST' })
|
||||||
|
|
||||||
@@ -135,4 +156,15 @@ export async function denyApplication(id: Number) {
|
|||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error("Something went wrong denying the application")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -170,6 +170,7 @@ function blurAfter() {
|
|||||||
<!-- <DropdownMenuItem>My Profile</DropdownMenuItem> -->
|
<!-- <DropdownMenuItem>My Profile</DropdownMenuItem> -->
|
||||||
<!-- <DropdownMenuItem>Settings</DropdownMenuItem> -->
|
<!-- <DropdownMenuItem>Settings</DropdownMenuItem> -->
|
||||||
<DropdownMenuItem @click="$router.push('/join')">My Application</DropdownMenuItem>
|
<DropdownMenuItem @click="$router.push('/join')">My Application</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem @click="$router.push('/applications')">Application History</DropdownMenuItem>
|
||||||
<DropdownMenuItem :variant="'destructive'" @click="logout()">Logout</DropdownMenuItem>
|
<DropdownMenuItem :variant="'destructive'" @click="logout()">Logout</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
|
|||||||
@@ -18,21 +18,25 @@ import * as z from 'zod';
|
|||||||
import DateInput from '../form/DateInput.vue';
|
import DateInput from '../form/DateInput.vue';
|
||||||
import { ApplicationData } from '@/api/application';
|
import { ApplicationData } from '@/api/application';
|
||||||
|
|
||||||
|
const regexA = /^https?:\/\/steamcommunity\.com\/id\/[A-Za-z0-9_]+\/?$/;
|
||||||
|
const regexB = /^https?:\/\/steamcommunity\.com\/profiles\/\d+\/?$/;
|
||||||
|
|
||||||
|
|
||||||
const formSchema = toTypedSchema(z.object({
|
const formSchema = toTypedSchema(z.object({
|
||||||
dob: z.string().refine(v => v, { message: "A date of birth is required." }),
|
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"),
|
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(),
|
military: z.boolean(),
|
||||||
communities: z.string(),
|
communities: z.string().nonempty(),
|
||||||
joinReason: z.string(),
|
joinReason: z.string().nonempty(),
|
||||||
milsimAttraction: z.string(),
|
milsimAttraction: z.string().nonempty(),
|
||||||
referral: z.string(),
|
referral: z.string().nonempty(),
|
||||||
steamProfile: z.string(),
|
steamProfile: z.string().nonempty().refine((val) => regexA.test(val) || regexB.test(val), { message: "Invalid Steam profile URL." }),
|
||||||
timezone: z.string(),
|
timezone: z.string().nonempty(),
|
||||||
canAttendSaturday: z.boolean(),
|
canAttendSaturday: z.boolean(),
|
||||||
interests: z.string(),
|
interests: z.string().nonempty(),
|
||||||
aknowledgeRules: z.literal(true, {
|
acknowledgeRules: z.literal(true, {
|
||||||
errorMap: () => ({ message: "Required" })
|
errorMap: () => ({ message: "Required" })
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
@@ -41,7 +45,7 @@ const formSchema = toTypedSchema(z.object({
|
|||||||
const fallbackInitials = {
|
const fallbackInitials = {
|
||||||
military: false,
|
military: false,
|
||||||
canAttendSaturday: false,
|
canAttendSaturday: false,
|
||||||
aknowledgeRules: false,
|
acknowledgeRules: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -82,7 +86,9 @@ onMounted(() => {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<DateInput :model-value="(value as string) ?? ''" :disabled="readOnly" @update:model-value="handleChange" />
|
<DateInput :model-value="(value as string) ?? ''" :disabled="readOnly" @update:model-value="handleChange" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -94,7 +100,9 @@ onMounted(() => {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<Input :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
<Input :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -105,7 +113,9 @@ onMounted(() => {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<Input type="number" :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
<Input type="number" :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -117,7 +127,9 @@ onMounted(() => {
|
|||||||
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
|
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
|
||||||
:disabled="readOnly" />
|
:disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -131,7 +143,9 @@ onMounted(() => {
|
|||||||
<span>Yes (checked) / No (unchecked)</span>
|
<span>Yes (checked) / No (unchecked)</span>
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -142,7 +156,9 @@ onMounted(() => {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<Input :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
<Input :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -154,7 +170,9 @@ onMounted(() => {
|
|||||||
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
|
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
|
||||||
:disabled="readOnly" />
|
:disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -166,7 +184,9 @@ onMounted(() => {
|
|||||||
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
|
<Textarea rows="4" class="resize-none" :model-value="value" @update:model-value="handleChange"
|
||||||
:disabled="readOnly" />
|
:disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -178,7 +198,9 @@ onMounted(() => {
|
|||||||
<Input placeholder="e.g., Reddit / Member: Alice" :model-value="value" @update:model-value="handleChange"
|
<Input placeholder="e.g., Reddit / Member: Alice" :model-value="value" @update:model-value="handleChange"
|
||||||
:disabled="readOnly" />
|
:disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -194,7 +216,9 @@ onMounted(() => {
|
|||||||
<Input type="url" placeholder="https://steamcommunity.com/profiles/7656119..." :model-value="value"
|
<Input type="url" placeholder="https://steamcommunity.com/profiles/7656119..." :model-value="value"
|
||||||
@update:model-value="handleChange" :disabled="readOnly" />
|
@update:model-value="handleChange" :disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -206,7 +230,9 @@ onMounted(() => {
|
|||||||
<Input placeholder="e.g., AEST, EST, UTC+10" :model-value="value" @update:model-value="handleChange"
|
<Input placeholder="e.g., AEST, EST, UTC+10" :model-value="value" @update:model-value="handleChange"
|
||||||
:disabled="readOnly" />
|
:disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -220,7 +246,9 @@ onMounted(() => {
|
|||||||
<span>Yes (checked) / No (unchecked)</span>
|
<span>Yes (checked) / No (unchecked)</span>
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
@@ -232,22 +260,26 @@ onMounted(() => {
|
|||||||
<Input placeholder="e.g., Rifleman; Medic; Pilot" :model-value="value" @update:model-value="handleChange"
|
<Input placeholder="e.g., Rifleman; Medic; Pilot" :model-value="value" @update:model-value="handleChange"
|
||||||
:disabled="readOnly" />
|
:disabled="readOnly" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<!-- Code of Conduct (boolean, field name kept as-is) -->
|
<!-- Code of Conduct (boolean, field name kept as-is) -->
|
||||||
<FormField name="aknowledgeRules" v-slot="{ value, handleChange }">
|
<FormField name="acknowledgeRules" v-slot="{ value, handleChange }">
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Community Code of Conduct</FormLabel>
|
<FormLabel>Community Code of Conduct</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Checkbox :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
<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>
|
Conduct</Button>.</span>
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<div class="h-4">
|
||||||
|
<FormMessage class="text-destructive" />
|
||||||
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const app = createApp(App)
|
|||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.use(router)
|
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 dsn = import.meta.env.VITE_GLITCHTIP_DSN;
|
||||||
let environment = import.meta.env.VITE_ENVIRONMENT;
|
let environment = import.meta.env.VITE_ENVIRONMENT;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
import ApplicationChat from '@/components/application/ApplicationChat.vue';
|
import ApplicationChat from '@/components/application/ApplicationChat.vue';
|
||||||
import ApplicationForm from '@/components/application/ApplicationForm.vue';
|
import ApplicationForm from '@/components/application/ApplicationForm.vue';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { ApplicationData, approveApplication, denyApplication, loadApplication, postApplication, postChatMessage, ApplicationStatus } from '@/api/application';
|
import { ApplicationData, approveApplication, denyApplication, loadApplication, postApplication, postChatMessage, ApplicationStatus, getMyApplication, ApplicationFull } from '@/api/application';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import Button from '@/components/ui/button/Button.vue';
|
import Button from '@/components/ui/button/Button.vue';
|
||||||
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
||||||
|
import Unauthorized from './Unauthorized.vue';
|
||||||
|
|
||||||
const appData = ref<ApplicationData>(null);
|
const appData = ref<ApplicationData>(null);
|
||||||
const appID = ref<number | null>(null);
|
const appID = ref<number | null>(null);
|
||||||
@@ -19,13 +20,12 @@ const loading = ref<boolean>(true);
|
|||||||
const member_name = ref<string>();
|
const member_name = ref<string>();
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
mode?: "create" | "view-self" | "view-recruiter"
|
mode?: "create" | "view-self" | "view-recruiter" | "view-self-id"
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const finalMode = ref<"create" | "view-self" | "view-recruiter">("create");
|
const finalMode = ref<"create" | "view-self" | "view-recruiter" | "view-self-id">("create");
|
||||||
|
|
||||||
async function loadByID(id: number | string) {
|
function loadData(raw: ApplicationFull) {
|
||||||
const raw = await loadApplication(id);
|
|
||||||
|
|
||||||
const data = raw.application;
|
const data = raw.application;
|
||||||
|
|
||||||
@@ -40,20 +40,20 @@ async function loadByID(id: number | string) {
|
|||||||
readOnly.value = true;
|
readOnly.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const router = useRoute();
|
const route = useRoute();
|
||||||
|
const unauthorized = ref(false);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
||||||
//recruiter mode
|
//recruiter mode
|
||||||
if (props.mode === 'view-recruiter') {
|
if (props.mode === 'view-recruiter') {
|
||||||
finalMode.value = 'view-recruiter';
|
finalMode.value = 'view-recruiter';
|
||||||
await loadByID(Number(router.params.id));
|
loadData(await loadApplication(Number(route.params.id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
//viewer mode
|
//viewer mode
|
||||||
if (props.mode === 'view-self') {
|
if (props.mode === 'view-self') {
|
||||||
finalMode.value = 'view-self';
|
finalMode.value = 'view-self';
|
||||||
await loadByID('me');
|
loadData(await loadApplication("me"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//creator mode
|
//creator mode
|
||||||
@@ -64,34 +64,23 @@ onMounted(async () => {
|
|||||||
newApp.value = true;
|
newApp.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.mode === 'view-self-id') {
|
||||||
|
finalMode.value = 'view-self-id';
|
||||||
|
try {
|
||||||
|
let raw = await getMyApplication(Number(route.params.id))
|
||||||
|
loadData(raw);
|
||||||
|
unauthorized.value = false;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (error.message === "Unauthorized") {
|
||||||
|
unauthorized.value = true;
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
|
||||||
// try {
|
|
||||||
// //get app ID from URL param
|
|
||||||
// if (appIDRaw === undefined) {
|
|
||||||
// //new app
|
|
||||||
// appData.value = null
|
|
||||||
// readOnly.value = false;
|
|
||||||
// newApp.value = true;
|
|
||||||
// } else {
|
|
||||||
// //load app
|
|
||||||
// const raw = await loadApplication(appIDRaw.toString());
|
|
||||||
|
|
||||||
// const data = raw.application;
|
|
||||||
|
|
||||||
// appID.value = data.id;
|
|
||||||
// appData.value = data.app_data;
|
|
||||||
// chatData.value = raw.comments;
|
|
||||||
// status.value = data.app_status;
|
|
||||||
// decisionDate.value = new Date(data.decision_at);
|
|
||||||
// submitDate.value = data.submitted_at ? new Date(data.submitted_at) : null;
|
|
||||||
// member_name.value = data.member_name;
|
|
||||||
// newApp.value = false;
|
|
||||||
// readOnly.value = true;
|
|
||||||
// }
|
|
||||||
// } catch (e) {
|
|
||||||
// console.error(e);
|
|
||||||
// }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function postComment(comment) {
|
async function postComment(comment) {
|
||||||
@@ -107,7 +96,7 @@ async function postApp(appData) {
|
|||||||
newApp.value = false;
|
newApp.value = false;
|
||||||
emit('submit');
|
emit('submit');
|
||||||
}
|
}
|
||||||
// TODO: Handle fail to post
|
// TODO: Handle fail to post
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleApprove(id) {
|
async function handleApprove(id) {
|
||||||
@@ -122,52 +111,58 @@ async function handleDeny(id) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="!loading" class="w-full h-20">
|
<div v-if="!loading" class="w-full h-20">
|
||||||
<div v-if="!newApp" class="flex flex-row justify-between items-center py-2 mb-8">
|
<div v-if="unauthorized" class="flex justify-center w-full my-10">
|
||||||
<!-- Application header -->
|
You do not have permission to view this application.
|
||||||
<div>
|
</div>
|
||||||
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">{{ member_name }}</h3>
|
<div v-else>
|
||||||
<p class="text-muted-foreground">Submitted: {{ submitDate.toLocaleString("en-US", {
|
<div v-if="!newApp" class="flex flex-row justify-between items-center py-2 mb-8">
|
||||||
year: "numeric",
|
<!-- Application header -->
|
||||||
month: "long",
|
<div>
|
||||||
day: "numeric",
|
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">{{ member_name }}</h3>
|
||||||
hour: "2-digit",
|
<p class="text-muted-foreground">Submitted: {{ submitDate.toLocaleString("en-US", {
|
||||||
minute: "2-digit"
|
|
||||||
}) }}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 class="text-right" :class="[
|
|
||||||
'font-semibold',
|
|
||||||
status === ApplicationStatus.Pending && 'text-yellow-500',
|
|
||||||
status === ApplicationStatus.Accepted && 'text-green-500',
|
|
||||||
status === ApplicationStatus.Denied && 'text-red-500'
|
|
||||||
]">{{ status }}</h3>
|
|
||||||
<p v-if="status != ApplicationStatus.Pending" class="text-muted-foreground">{{ status }}: {{
|
|
||||||
decisionDate.toLocaleString("en-US", {
|
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "long",
|
month: "long",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit"
|
minute: "2-digit"
|
||||||
}) }}</p>
|
}) }}</p>
|
||||||
<div class="mt-2" v-else-if="finalMode === 'view-recruiter'">
|
</div>
|
||||||
<Button variant="success" class="mr-2" :onclick="() => { handleApprove(appID) }">
|
<div>
|
||||||
<CheckIcon></CheckIcon>
|
<h3 class="text-right" :class="[
|
||||||
</Button>
|
'font-semibold',
|
||||||
<Button variant="destructive" :onClick="() => { handleDeny(appID) }">
|
status === ApplicationStatus.Pending && 'text-yellow-500',
|
||||||
<XIcon></XIcon>
|
status === ApplicationStatus.Accepted && 'text-green-500',
|
||||||
</Button>
|
status === ApplicationStatus.Denied && 'text-red-500'
|
||||||
|
]">{{ status }}</h3>
|
||||||
|
<p v-if="status != ApplicationStatus.Pending" class="text-muted-foreground">{{ status }}: {{
|
||||||
|
decisionDate.toLocaleString("en-US", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit"
|
||||||
|
}) }}</p>
|
||||||
|
<div class="mt-2" v-else-if="finalMode === 'view-recruiter'">
|
||||||
|
<Button variant="success" class="mr-2" :onclick="() => { handleApprove(appID) }">
|
||||||
|
<CheckIcon></CheckIcon>
|
||||||
|
</Button>
|
||||||
|
<Button variant="destructive" :onClick="() => { handleDeny(appID) }">
|
||||||
|
<XIcon></XIcon>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<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>
|
|
||||||
<div v-if="!newApp">
|
|
||||||
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight mb-4">Discussion</h3>
|
|
||||||
<ApplicationChat :messages="chatData" @post="postComment"></ApplicationChat>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- TODO: Implement some kinda loading screen -->
|
<!-- TODO: Implement some kinda loading screen -->
|
||||||
<div v-else class="flex items-center justify-center h-full">Loading</div>
|
<div v-else class="flex items-center justify-center h-full">Loading</div>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { useUserStore } from '@/stores/user';
|
|||||||
import { Check, Circle, Dot, Users, X } from 'lucide-vue-next'
|
import { Check, Circle, Dot, Users, X } from 'lucide-vue-next'
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import Application from './Application.vue';
|
import Application from './Application.vue';
|
||||||
|
import { restartApplication } from '@/api/application';
|
||||||
|
|
||||||
function goToLogin() {
|
function goToLogin() {
|
||||||
const redirectUrl = encodeURIComponent(window.location.origin + '/join')
|
const redirectUrl = encodeURIComponent(window.location.origin + '/join')
|
||||||
@@ -67,14 +68,25 @@ const currentStep = computed<number>(() => {
|
|||||||
case "denied":
|
case "denied":
|
||||||
return 5;
|
return 5;
|
||||||
break;
|
break;
|
||||||
|
case "retired":
|
||||||
|
return 5;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const finalPanel = ref<'app' | 'message'>('message');
|
const finalPanel = ref<'app' | 'message'>('message');
|
||||||
|
|
||||||
|
const reloadKey = ref(0);
|
||||||
|
|
||||||
|
async function restartApp() {
|
||||||
|
await restartApplication();
|
||||||
|
await userStore.loadUser();
|
||||||
|
reloadKey.value++;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<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 -->
|
<!-- Stepper Container -->
|
||||||
<div class="w-full flex justify-center">
|
<div class="w-full flex justify-center">
|
||||||
@@ -219,8 +231,8 @@ const finalPanel = ref<'app' | 'message'>('message');
|
|||||||
</div>
|
</div>
|
||||||
<!-- Denied message -->
|
<!-- Denied message -->
|
||||||
<div v-else-if="userStore.state === 'denied'">
|
<div v-else-if="userStore.state === 'denied'">
|
||||||
<div class="w-full max-w-2xl p-8">
|
<div class="w-full max-w-2xl flex flex-col gap-8">
|
||||||
<h1 class="text-3xl sm:text-4xl font-bold mb-4 text-left text-destructive">
|
<h1 class="text-3xl sm:text-4xl font-bold text-left">
|
||||||
Application Not Approved
|
Application Not Approved
|
||||||
</h1>
|
</h1>
|
||||||
<div class="space-y-4 text-muted-foreground text-left leading-relaxed">
|
<div class="space-y-4 text-muted-foreground text-left leading-relaxed">
|
||||||
@@ -246,6 +258,39 @@ const finalPanel = ref<'app' | 'message'>('message');
|
|||||||
Team</span>
|
Team</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<Button class="w-min" @click="restartApp">New Application</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="userStore.state === 'retired'">
|
||||||
|
<div class="w-full max-w-2xl flex flex-col gap-8">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-bold text-left">
|
||||||
|
You have retired from the 17th Ranger Battalion
|
||||||
|
</h1>
|
||||||
|
<div class="space-y-4 text-muted-foreground text-left leading-relaxed">
|
||||||
|
<p>
|
||||||
|
Thank you for your service and participation in the <strong>17th Ranger
|
||||||
|
Battalion</strong>.
|
||||||
|
Your time with us has been sincerely appreciated.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Should you ever wish to return, you are welcome to <strong>reach out to our
|
||||||
|
leadership
|
||||||
|
team</strong>
|
||||||
|
for guidance on the reinstatement process or to stay connected with the community.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
We recognize that circumstances change, and you will always have a place to
|
||||||
|
reconnect with
|
||||||
|
us
|
||||||
|
should the opportunity arise in the future.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
All the best,<br />
|
||||||
|
<span class="text-foreground font-medium">The 17th Ranger Battalion Leadership
|
||||||
|
Team</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button class="w-min" @click="restartApp">New Application</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
147
ui/src/pages/MyApplications.vue
Normal file
147
ui/src/pages/MyApplications.vue
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<script setup>
|
||||||
|
import { getAllApplications, approveApplication, denyApplication, ApplicationStatus, loadMyApplications } from '@/api/application';
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCaption,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from '@/components/ui/table'
|
||||||
|
import Button from '@/components/ui/button/Button.vue';
|
||||||
|
import { onMounted, ref, watch } from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
||||||
|
import Application from './Application.vue';
|
||||||
|
|
||||||
|
const appList = ref([]);
|
||||||
|
const now = Date.now();
|
||||||
|
// relative time formatter (uses user locale)
|
||||||
|
const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' })
|
||||||
|
// exact date/time for tooltip
|
||||||
|
const exactFmt = new Intl.DateTimeFormat(undefined, {
|
||||||
|
dateStyle: 'medium', timeStyle: 'short', timeZone: 'America/Toronto'
|
||||||
|
})
|
||||||
|
|
||||||
|
function formatAgo(iso) {
|
||||||
|
const d = new Date(iso)
|
||||||
|
if (isNaN(d)) return ''
|
||||||
|
let diff = (d.getTime() - now) / 1000 // seconds relative to page load
|
||||||
|
const divisions = [
|
||||||
|
{ amount: 60, name: 'second' },
|
||||||
|
{ amount: 60, name: 'minute' },
|
||||||
|
{ amount: 24, name: 'hour' },
|
||||||
|
{ amount: 7, name: 'day' },
|
||||||
|
{ amount: 4.34524, name: 'week' }, // avg weeks per month
|
||||||
|
{ amount: 12, name: 'month' },
|
||||||
|
{ amount: Infinity, name: 'year' },
|
||||||
|
]
|
||||||
|
for (const div of divisions) {
|
||||||
|
if (Math.abs(diff) < div.amount) {
|
||||||
|
return rtf.format(Math.round(diff), div.name)
|
||||||
|
}
|
||||||
|
diff /= div.amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatExact(iso) {
|
||||||
|
const d = new Date(iso)
|
||||||
|
return isNaN(d) ? '' : exactFmt.format(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
function openApplication(id) {
|
||||||
|
router.push(`/applications/${id}`)
|
||||||
|
openPanel.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
watch(() => route.params.id, (newId) => {
|
||||||
|
if (newId === undefined) {
|
||||||
|
openPanel.value = false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const openPanel = ref(false);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
appList.value = await loadMyApplications();
|
||||||
|
|
||||||
|
//preload application
|
||||||
|
if (route.params.id != undefined) {
|
||||||
|
openApplication(route.params.id)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="px-20 mx-auto max-w-[100rem] w-full flex mt-5 h-52 min-h-0 overflow-hidden">
|
||||||
|
<!-- application list -->
|
||||||
|
<div :class="openPanel == false ? 'w-full' : 'w-2/5'" class="pr-9">
|
||||||
|
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight mb-5">My Applications</h1>
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Date Submitted</TableHead>
|
||||||
|
<TableHead class="text-right">Status</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody class="overflow-y-auto scrollbar-themed">
|
||||||
|
<TableRow v-for="app in appList" :key="app.id" class="cursor-pointer"
|
||||||
|
:onClick="() => { openApplication(app.id) }">
|
||||||
|
<TableCell :title="formatExact(app.submitted_at)">
|
||||||
|
{{ formatAgo(app.submitted_at) }}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell class="text-right font-semibold" :class="[
|
||||||
|
,
|
||||||
|
app.app_status === ApplicationStatus.Pending && 'text-yellow-500',
|
||||||
|
app.app_status === ApplicationStatus.Accepted && 'text-green-500',
|
||||||
|
app.app_status === ApplicationStatus.Denied && 'text-destructive'
|
||||||
|
]">{{ app.app_status }}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
<div v-if="openPanel" class="pl-9 border-l w-3/5" :key="$route.params.id">
|
||||||
|
<div class="mb-5 flex justify-between">
|
||||||
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight"> Application</p>
|
||||||
|
</div>
|
||||||
|
<div class="overflow-y-auto max-h-[80vh] h-full mt-5 scrollbar-themed">
|
||||||
|
<Application :mode="'view-self-id'"></Application>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
/* Firefox */
|
||||||
|
.scrollbar-themed {
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: #555 #1f1f1f;
|
||||||
|
padding-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Chrome, Edge, Safari */
|
||||||
|
.scrollbar-themed::-webkit-scrollbar {
|
||||||
|
width: 10px;
|
||||||
|
/* slightly wider to allow padding look */
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollbar-themed::-webkit-scrollbar-track {
|
||||||
|
background: #1f1f1f;
|
||||||
|
margin-left: 6px;
|
||||||
|
/* ❗ adds space between content + scrollbar */
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollbar-themed::-webkit-scrollbar-thumb {
|
||||||
|
background: #555;
|
||||||
|
border-radius: 9999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollbar-themed::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #777;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -6,19 +6,20 @@ const router = createRouter({
|
|||||||
routes: [
|
routes: [
|
||||||
// PUBLIC
|
// PUBLIC
|
||||||
{ path: '/join', component: () => import('@/pages/Join.vue') },
|
{ path: '/join', component: () => import('@/pages/Join.vue') },
|
||||||
|
{ path: '/applications', component: () => import('@/pages/MyApplications.vue'), meta: { requiresAuth: true } },
|
||||||
|
{ path: '/applications/:id', component: () => import('@/pages/MyApplications.vue'), meta: { requiresAuth: true } },
|
||||||
|
|
||||||
// AUTH REQUIRED
|
// AUTH REQUIRED
|
||||||
{ path: '/apply', component: () => import('@/pages/Application.vue'), meta: { requiresAuth: true } },
|
|
||||||
{ path: '/', component: () => import('@/pages/Homepage.vue') },
|
{ path: '/', component: () => import('@/pages/Homepage.vue') },
|
||||||
|
|
||||||
// MEMBER ROUTES
|
// MEMBER ROUTES
|
||||||
{ path: '/members', component: () => import('@/pages/memberList.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/members', component: () => import('@/pages/memberList.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/loa', component: () => import('@/pages/SubmitLOA.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/loa', component: () => import('@/pages/SubmitLOA.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/transfer', component: () => import('@/pages/Transfer.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/transfer', component: () => import('@/pages/Transfer.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
|
|
||||||
{ path: '/calendar', component: () => import('@/pages/Calendar.vue'), meta: { requiresAuth: true, memberOnly: true }, },
|
{ path: '/calendar', component: () => import('@/pages/Calendar.vue'), meta: { requiresAuth: true, memberOnly: true }, },
|
||||||
{ path: '/calendar/event/:id', component: () => import('@/pages/Calendar.vue'), meta: { requiresAuth: true, memberOnly: true }, },
|
{ path: '/calendar/event/:id', component: () => import('@/pages/Calendar.vue'), meta: { requiresAuth: true, memberOnly: true }, },
|
||||||
|
|
||||||
{ path: '/trainingReport', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/trainingReport', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/trainingReport/new', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/trainingReport/new', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/trainingReport/:id', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/trainingReport/:id', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
|
|||||||
Reference in New Issue
Block a user