Compare commits
23 Commits
Applicatio
...
Profile-sy
| Author | SHA1 | Date | |
|---|---|---|---|
| e7b73f9e73 | |||
| 533e315642 | |||
| 93e8f3b3d2 | |||
| 82eb6b7bbf | |||
| 8aad3c67c7 | |||
| 445c15b797 | |||
| 406f61a612 | |||
| f7daa1bb19 | |||
| 8a7ca9c2f9 | |||
| 1730714737 | |||
| 8dc11ee34d | |||
| 2a841ebf27 | |||
| d7908570b2 | |||
| 629fd59a7c | |||
| 333bf20d86 | |||
| bd3c3564a9 | |||
| c74b5b280b | |||
| 0a1704b60b | |||
| 97119dec97 | |||
| 7a6020febb | |||
| fb64b35807 | |||
| a8165e2ae5 | |||
| 79cf77dc63 |
@@ -21,6 +21,7 @@ CLIENT_URL= # This is whatever URL the client web app is served on
|
|||||||
CLIENT_DOMAIN= #whatever.com
|
CLIENT_DOMAIN= #whatever.com
|
||||||
APPLICATION_VERSION= # Should match release tag
|
APPLICATION_VERSION= # Should match release tag
|
||||||
APPLICATION_ENVIRONMENT= # dev / prod
|
APPLICATION_ENVIRONMENT= # dev / prod
|
||||||
|
CONFIG_ID= # configures
|
||||||
|
|
||||||
# Glitchtip
|
# Glitchtip
|
||||||
GLITCHTIP_DSN=
|
GLITCHTIP_DSN=
|
||||||
|
|||||||
@@ -3,13 +3,32 @@ const router = express.Router();
|
|||||||
|
|
||||||
import pool from '../db';
|
import pool from '../db';
|
||||||
import { approveApplication, createApplication, denyApplication, getAllMemberApplications, 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 { setUserState } from '../services/memberService';
|
||||||
|
import { MemberState } from '@app/shared/types/member';
|
||||||
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';
|
import { Request, response, Response } from 'express';
|
||||||
import { getUserRoles } from '../services/rolesService';
|
import { getUserRoles } from '../services/rolesService';
|
||||||
|
|
||||||
|
//get CoC
|
||||||
|
router.get('/coc', async (req: Request, res: Response) => {
|
||||||
|
const output = await fetch(`${process.env.DOC_HOST}/api/pages/714`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${process.env.DOC_TOKEN_ID}:${process.env.DOC_TOKEN_SECRET}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (output.ok) {
|
||||||
|
const out = await output.json();
|
||||||
|
res.status(200).json(out.html);
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch LOA policy from bookstack");
|
||||||
|
res.sendStatus(500);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// POST /application
|
// POST /application
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -141,8 +160,9 @@ router.get('/:id', async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// POST /application/approve/:id
|
// POST /application/approve/:id
|
||||||
router.post('/approve/:id', async (req, res) => {
|
router.post('/approve/:id', async (req: Request, res: Response) => {
|
||||||
const appID = req.params.id;
|
const appID = Number(req.params.id);
|
||||||
|
const approved_by = req.user.id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const app = await getApplicationByID(appID);
|
const app = await getApplicationByID(appID);
|
||||||
@@ -153,14 +173,14 @@ router.post('/approve/:id', async (req, res) => {
|
|||||||
throw new Error("Something went wrong approving the application");
|
throw new Error("Something went wrong approving the application");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(app.member_id);
|
|
||||||
//update user profile
|
//update user profile
|
||||||
await setUserState(app.member_id, MemberState.Member);
|
await setUserState(app.member_id, MemberState.Member);
|
||||||
|
|
||||||
let nextRank = await getRankByName('Recruit')
|
await pool.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by])
|
||||||
await insertMemberRank(app.member_id, nextRank.id);
|
// let nextRank = await getRankByName('Recruit')
|
||||||
//assign user to "pending basic"
|
// await insertMemberRank(app.member_id, nextRank.id);
|
||||||
await assignUserToStatus(app.member_id, 1);
|
// //assign user to "pending basic"
|
||||||
|
// await assignUserToStatus(app.member_id, 1);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Approve failed:', err);
|
console.error('Approve failed:', err);
|
||||||
@@ -282,4 +302,5 @@ router.post('/restart', async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
import { Request, Response } from 'express';
|
||||||
import pool from '../db';
|
import pool from '../db';
|
||||||
import { getUserActiveLOA } from '../services/loaService';
|
import { getUserActiveLOA } from '../services/loaService';
|
||||||
import { getUserData } from '../services/memberService';
|
import { getMemberSettings, getMembersFull, getMembersLite, getUserData, setUserSettings } from '../services/memberService';
|
||||||
import { getUserRoles } from '../services/rolesService';
|
import { getUserRoles } from '../services/rolesService';
|
||||||
|
import { memberSettings } from '@app/shared/types/member';
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
console.log(req.user);
|
console.log(req.user);
|
||||||
@@ -27,7 +29,7 @@ router.get('/', async (req, res) => {
|
|||||||
AND UTC_TIMESTAMP() BETWEEN l.start_date AND l.end_date
|
AND UTC_TIMESTAMP() BETWEEN l.start_date AND l.end_date
|
||||||
) THEN 1 ELSE 0
|
) THEN 1 ELSE 0
|
||||||
END AS on_loa
|
END AS on_loa
|
||||||
FROM view_member_rank_status_all v;`);
|
FROM view_member_rank_unit_status_latest v;`);
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error fetching users:', err);
|
console.error('Error fetching users:', err);
|
||||||
@@ -60,10 +62,57 @@ router.get('/me', async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.get('/settings', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
let user = req.user.id;
|
||||||
|
console.log(user);
|
||||||
|
let output = await getMemberSettings(user);
|
||||||
|
res.status(200).json(output);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.put('/settings', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
let user = req.user.id;
|
||||||
|
let settings: memberSettings = req.body;
|
||||||
|
console.log(settings)
|
||||||
|
await setUserSettings(user, settings);
|
||||||
|
res.sendStatus(200);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/lite/bulk', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
let ids = req.body.ids;
|
||||||
|
let out = await getMembersLite(ids);
|
||||||
|
res.status(200).json(out);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/full/bulk', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
let ids = req.body.ids;
|
||||||
|
let out = await getMembersFull(ids);
|
||||||
|
res.status(200).json(out);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
router.get('/:id', async (req, res) => {
|
router.get('/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.params.id;
|
const userId = req.params.id;
|
||||||
const result = await pool.query('SELECT * FROM view_member_rank_status_all WHERE id = $1;', [userId]);
|
const result = await pool.query('SELECT * FROM view_member_rank_unit_status_latest WHERE id = $1;', [userId]);
|
||||||
if (result.rows.length === 0) {
|
if (result.rows.length === 0) {
|
||||||
return res.status(404).json({ error: 'User not found' });
|
return res.status(404).json({ error: 'User not found' });
|
||||||
}
|
}
|
||||||
@@ -74,13 +123,4 @@ router.get('/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//update a user's display name (stub)
|
|
||||||
router.put('/:id/displayname', async (req, res) => {
|
|
||||||
// Stub: not implemented yet
|
|
||||||
return res.status(501).json({ error: 'Update display name not implemented' });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -49,7 +49,7 @@ r.get('/', async (req, res) => {
|
|||||||
const membersRoles = await con.query(`
|
const membersRoles = await con.query(`
|
||||||
SELECT mr.role_id, v.*
|
SELECT mr.role_id, v.*
|
||||||
FROM members_roles mr
|
FROM members_roles mr
|
||||||
JOIN view_member_rank_status_all v ON mr.member_id = v.member_id
|
JOIN view_member_rank_unit_status_latest v ON mr.member_id = v.member_id
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,17 @@
|
|||||||
import pool from "../db";
|
import pool from "../db";
|
||||||
|
import { Member, MemberLight, memberSettings, MemberState } from '@app/shared/types/member'
|
||||||
export enum MemberState {
|
|
||||||
Guest = "guest",
|
|
||||||
Applicant = "applicant",
|
|
||||||
Member = "member",
|
|
||||||
Retired = "retired",
|
|
||||||
Banned = "banned",
|
|
||||||
Denied = "denied"
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getUserData(userID: number) {
|
export async function getUserData(userID: number) {
|
||||||
const sql = `SELECT * FROM members WHERE id = ?`;
|
const sql = `SELECT * FROM members WHERE id = ?`;
|
||||||
const res = await pool.query(sql, [userID]);
|
const res = await pool.query(sql, [userID]);
|
||||||
return res[0] ?? null;
|
return res[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setUserState(userID: number, state: MemberState) {
|
export async function setUserState(userID: number, state: MemberState) {
|
||||||
const sql = `UPDATE members
|
const sql = `UPDATE members
|
||||||
SET state = ?
|
SET state = ?
|
||||||
WHERE id = ?;`;
|
WHERE id = ?;`;
|
||||||
return await pool.query(sql, [state, userID]);
|
return await pool.query(sql, [state, userID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -32,3 +24,40 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function getMemberSettings(id: number): Promise<memberSettings> {
|
||||||
|
const sql = `SELECT * FROM view_member_settings WHERE id = ?`;
|
||||||
|
let out: memberSettings[] = await pool.query(sql, [id]);
|
||||||
|
|
||||||
|
if (out.length != 1)
|
||||||
|
throw new Error("Could not get user settings");
|
||||||
|
|
||||||
|
return out[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setUserSettings(id: number, settings: memberSettings) {
|
||||||
|
const sql = `UPDATE view_member_settings SET
|
||||||
|
displayName = ?
|
||||||
|
WHERE id = ?;`;
|
||||||
|
let result = await pool.query(sql, [settings.displayName, id])
|
||||||
|
console.log(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMembersLite(ids: number[]): Promise<MemberLight[]> {
|
||||||
|
const sql = `SELECT m.member_id AS id,
|
||||||
|
m.member_name AS username,
|
||||||
|
m.displayName,
|
||||||
|
u.color
|
||||||
|
FROM view_member_rank_unit_status_latest m
|
||||||
|
LEFT JOIN units u ON u.name = m.unit
|
||||||
|
WHERE member_id IN (?);`;
|
||||||
|
const res: MemberLight[] = await pool.query(sql, [ids]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMembersFull(ids: number[]): Promise<Member[]> {
|
||||||
|
const sql = `SELECT * FROM view_member_rank_unit_status_latest WHERE member_id IN (?);`;
|
||||||
|
const res: Member[] = await pool.query(sql, [ids]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -21,8 +21,8 @@ export async function insertMemberRank(member_id: number, rank_id: number): Prom
|
|||||||
|
|
||||||
export async function insertMemberRank(member_id: number, rank_id: number, date?: Date): Promise<void> {
|
export async function insertMemberRank(member_id: number, rank_id: number, date?: Date): Promise<void> {
|
||||||
const sql = date
|
const sql = date
|
||||||
? `INSERT INTO members_ranks (member_id, rank_id, event_date) VALUES (?, ?, ?);`
|
? `INSERT INTO members_ranks (member_id, rank_id, start_date) VALUES (?, ?, ?);`
|
||||||
: `INSERT INTO members_ranks (member_id, rank_id, event_date) VALUES (?, ?, NOW());`;
|
: `INSERT INTO members_ranks (member_id, rank_id, start_date) VALUES (?, ?, NOW());`;
|
||||||
|
|
||||||
const params = date
|
const params = date
|
||||||
? [member_id, rank_id, date]
|
? [member_id, rank_id, date]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pool from "../db"
|
import pool from "../db"
|
||||||
|
|
||||||
export async function assignUserToStatus(userID: number, statusID: number) {
|
export async function assignUserToStatus(userID: number, statusID: number) {
|
||||||
const sql = `INSERT INTO members_statuses (member_id, status_id, event_date) VALUES (?, ?, NOW())`
|
const sql = `INSERT INTO members_statuses (member_id, status_id, start_date) VALUES (?, ?, NOW())`
|
||||||
await pool.execute(sql, [userID, statusID]);
|
await pool.execute(sql, [userID, statusID]);
|
||||||
}
|
}
|
||||||
|
|||||||
31
shared/types/member.ts
Normal file
31
shared/types/member.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
export interface memberSettings {
|
||||||
|
displayName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum MemberState {
|
||||||
|
Guest = "guest",
|
||||||
|
Applicant = "applicant",
|
||||||
|
Member = "member",
|
||||||
|
Retired = "retired",
|
||||||
|
Banned = "banned",
|
||||||
|
Denied = "denied"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Member = {
|
||||||
|
member_id: number;
|
||||||
|
member_name: string;
|
||||||
|
rank: string | null;
|
||||||
|
rank_date: string | null;
|
||||||
|
unit: string | null;
|
||||||
|
unit_date: string | null;
|
||||||
|
status: string | null;
|
||||||
|
status_date: string | null;
|
||||||
|
loa_until?: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface MemberLight {
|
||||||
|
id: number
|
||||||
|
displayName: string
|
||||||
|
username: string
|
||||||
|
color: string
|
||||||
|
}
|
||||||
@@ -89,7 +89,7 @@ export async function getMyApplication(id: number): Promise<ApplicationFull> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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', credentials: 'include' })
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error("Something went wrong approving the application")
|
console.error("Something went wrong approving the application")
|
||||||
@@ -97,7 +97,7 @@ export async function approveApplication(id: Number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function denyApplication(id: Number) {
|
export async function denyApplication(id: Number) {
|
||||||
const res = await fetch(`${addr}/application/deny/${id}`, { method: 'POST' })
|
const res = await fetch(`${addr}/application/deny/${id}`, { method: 'POST', credentials: 'include' })
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error("Something went wrong denying the application")
|
console.error("Something went wrong denying the application")
|
||||||
@@ -113,4 +113,20 @@ export async function restartApplication() {
|
|||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error("Something went wrong restarting your application")
|
console.error("Something went wrong restarting your application")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCoC(): Promise<string> {
|
||||||
|
const res = await fetch(`${addr}/application/coc`, {
|
||||||
|
method: "GET",
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
const out = res.json();
|
||||||
|
if (!out) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,4 @@
|
|||||||
export type Member = {
|
import { memberSettings, Member, MemberLight } from "@shared/types/member";
|
||||||
member_id: number;
|
|
||||||
member_name: string;
|
|
||||||
rank: string | null;
|
|
||||||
rank_date: string | null;
|
|
||||||
status: string | null;
|
|
||||||
status_date: string | null;
|
|
||||||
on_loa: boolean | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
const addr = import.meta.env.VITE_APIHOST;
|
||||||
@@ -19,4 +11,66 @@ export async function getMembers(): Promise<Member[]> {
|
|||||||
throw new Error("Failed to fetch members");
|
throw new Error("Failed to fetch members");
|
||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMemberSettings(): Promise<memberSettings> {
|
||||||
|
const response = await fetch(`${addr}/members/settings`, {
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch settings");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setMemberSettings(settings: memberSettings) {
|
||||||
|
const response = await fetch(`${addr}/members/settings`, {
|
||||||
|
credentials: 'include',
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'Application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(settings)
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch settings");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLightMembers(ids: number[]): Promise<MemberLight[]> {
|
||||||
|
|
||||||
|
if (ids.length === 0) return [];
|
||||||
|
|
||||||
|
const response = await fetch(`${addr}/members/lite/bulk`, {
|
||||||
|
credentials: 'include',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ ids })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch light members");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getFullMembers(ids: number[]): Promise<Member[]> {
|
||||||
|
|
||||||
|
if (ids.length === 0) return [];
|
||||||
|
|
||||||
|
const response = await fetch(`${addr}/members/full/bulk`, {
|
||||||
|
credentials: 'include',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ ids })
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch settings");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Root container */
|
/* Root container */
|
||||||
.ListRendererV2-container {
|
.bookstack-container {
|
||||||
font-family: var(--font-sans, system-ui), sans-serif;
|
font-family: var(--font-sans, system-ui), sans-serif;
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
line-height: 1.45;
|
line-height: 1.45;
|
||||||
@@ -178,56 +178,53 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Headers */
|
/* Headers */
|
||||||
.ListRendererV2-container h4 {
|
.bookstack-container h4 {
|
||||||
margin: 0.9rem 0 0.4rem 0;
|
margin: 0.9rem 0 0.4rem 0;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
line-height: 1.35;
|
line-height: 1.35;
|
||||||
font-size: 1.05rem;
|
font-size: 1.05rem;
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
/* PURE WHITE */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ListRendererV2-container h5 {
|
.bookstack-container h5 {
|
||||||
margin: 0.9rem 0 0.4rem 0;
|
margin: 0.9rem 0 0.4rem 0;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
line-height: 1.35;
|
line-height: 1.35;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
/* Still white (change to muted if desired) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lists */
|
/* Lists */
|
||||||
.ListRendererV2-container ul {
|
.bookstack-container ul {
|
||||||
list-style-type: disc;
|
list-style-type: disc;
|
||||||
margin-left: 1.1rem;
|
margin-left: 1.1rem;
|
||||||
margin-bottom: 0.6rem;
|
margin-bottom: 0.6rem;
|
||||||
padding-left: 0.6rem;
|
padding-left: 0.6rem;
|
||||||
color: var(--muted-foreground);
|
color: var(--muted-foreground);
|
||||||
/* dim text */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nested lists */
|
/* Nested lists */
|
||||||
.ListRendererV2-container ul ul {
|
.bookstack-container ul ul {
|
||||||
list-style-type: circle;
|
list-style-type: circle;
|
||||||
margin-left: 0.9rem;
|
margin-left: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List items */
|
/* List items */
|
||||||
.ListRendererV2-container li {
|
.bookstack-container li {
|
||||||
margin: 0.15rem 0;
|
margin: 0.15rem 0;
|
||||||
padding-left: 0.1rem;
|
padding-left: 0.1rem;
|
||||||
color: var(--muted-foreground);
|
color: var(--muted-foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bullet color */
|
/* Bullet color */
|
||||||
.ListRendererV2-container li::marker {
|
.bookstack-container li::marker {
|
||||||
color: var(--muted-foreground);
|
color: var(--muted-foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inline elements */
|
/* Inline elements */
|
||||||
.ListRendererV2-container li p,
|
.bookstack-container li p,
|
||||||
.ListRendererV2-container li span,
|
.bookstack-container li span,
|
||||||
.ListRendererV2-container p {
|
.bookstack-container p {
|
||||||
display: inline;
|
display: inline;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -235,6 +232,45 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Top-level spacing */
|
/* Top-level spacing */
|
||||||
.ListRendererV2-container>ul>li {
|
.bookstack-container>ul>li {
|
||||||
margin-top: 0.3rem;
|
margin-top: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* links */
|
||||||
|
.bookstack-container a {
|
||||||
|
color: var(--color-primary);
|
||||||
|
margin-top: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bookstack-container a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scrollbar stuff */
|
||||||
|
/* 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;
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,8 @@ import NavigationMenuContent from '../ui/navigation-menu/NavigationMenuContent.v
|
|||||||
import { navigationMenuTriggerStyle } from '../ui/navigation-menu/'
|
import { navigationMenuTriggerStyle } from '../ui/navigation-menu/'
|
||||||
import { useAuth } from '@/composables/useAuth';
|
import { useAuth } from '@/composables/useAuth';
|
||||||
import { ArrowUpRight, CircleArrowOutUpRight } from 'lucide-vue-next';
|
import { ArrowUpRight, CircleArrowOutUpRight } from 'lucide-vue-next';
|
||||||
|
import DropdownMenuGroup from '../ui/dropdown-menu/DropdownMenuGroup.vue';
|
||||||
|
import DropdownMenuSeparator from '../ui/dropdown-menu/DropdownMenuSeparator.vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
@@ -180,10 +182,12 @@ function blurAfter() {
|
|||||||
<p>{{ userStore.user.name }}</p>
|
<p>{{ userStore.user.name }}</p>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
<!-- <DropdownMenuItem>My Profile</DropdownMenuItem> -->
|
<DropdownMenuItem @click="$router.push('/profile')">My Profile</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator></DropdownMenuSeparator>
|
||||||
<!-- <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 @click="$router.push('/applications')">Application History</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator></DropdownMenuSeparator>
|
||||||
<DropdownMenuItem :variant="'destructive'" @click="logout()">Logout</DropdownMenuItem>
|
<DropdownMenuItem :variant="'destructive'" @click="logout()">Logout</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { useAuth } from '@/composables/useAuth'
|
|||||||
import { CommentRow } from '@shared/types/application'
|
import { CommentRow } from '@shared/types/application'
|
||||||
import { Dot } from 'lucide-vue-next'
|
import { Dot } from 'lucide-vue-next'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import MemberCard from '../members/MemberCard.vue'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
messages: CommentRow[]
|
messages: CommentRow[]
|
||||||
@@ -71,7 +72,7 @@ function onSubmit(values: { text: string }, { resetForm }: { resetForm: () => vo
|
|||||||
<!-- Comment header -->
|
<!-- Comment header -->
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<p>{{ message.poster_name }}</p>
|
<MemberCard :member-id="message.poster_id"></MemberCard>
|
||||||
<p v-if="message.admin_only" class="flex">
|
<p v-if="message.admin_only" class="flex">
|
||||||
<Dot /><span class="text-amber-300">Internal</span>
|
<Dot /><span class="text-amber-300">Internal</span>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -13,10 +13,18 @@ import Input from '@/components/ui/input/Input.vue';
|
|||||||
import Textarea from '@/components/ui/textarea/Textarea.vue';
|
import Textarea from '@/components/ui/textarea/Textarea.vue';
|
||||||
import { toTypedSchema } from '@vee-validate/zod';
|
import { toTypedSchema } from '@vee-validate/zod';
|
||||||
import { Form } from 'vee-validate';
|
import { Form } from 'vee-validate';
|
||||||
import { onMounted, ref } from 'vue';
|
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||||
import * as z from 'zod';
|
import * as z from 'zod';
|
||||||
import DateInput from '../form/DateInput.vue';
|
import DateInput from '../form/DateInput.vue';
|
||||||
import { ApplicationData } from '@shared/types/application';
|
import { ApplicationData } from '@shared/types/application';
|
||||||
|
import Dialog from '../ui/dialog/Dialog.vue';
|
||||||
|
import DialogTrigger from '../ui/dialog/DialogTrigger.vue';
|
||||||
|
import DialogContent from '../ui/dialog/DialogContent.vue';
|
||||||
|
import DialogHeader from '../ui/dialog/DialogHeader.vue';
|
||||||
|
import DialogTitle from '../ui/dialog/DialogTitle.vue';
|
||||||
|
import DialogDescription from '../ui/dialog/DialogDescription.vue';
|
||||||
|
import { getCoC } from '@/api/application';
|
||||||
|
import { startBrowserTracingPageLoadSpan } from '@sentry/vue';
|
||||||
|
|
||||||
const regexA = /^https?:\/\/steamcommunity\.com\/id\/[A-Za-z0-9_]+\/?$/;
|
const regexA = /^https?:\/\/steamcommunity\.com\/id\/[A-Za-z0-9_]+\/?$/;
|
||||||
const regexB = /^https?:\/\/steamcommunity\.com\/profiles\/\d+\/?$/;
|
const regexB = /^https?:\/\/steamcommunity\.com\/profiles\/\d+\/?$/;
|
||||||
@@ -61,7 +69,7 @@ async function onSubmit(val: any) {
|
|||||||
emit('submit', val);
|
emit('submit', val);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
if (props.data !== null) {
|
if (props.data !== null) {
|
||||||
const parsed = typeof props.data === "string"
|
const parsed = typeof props.data === "string"
|
||||||
? JSON.parse(props.data)
|
? JSON.parse(props.data)
|
||||||
@@ -71,8 +79,35 @@ onMounted(() => {
|
|||||||
} else {
|
} else {
|
||||||
initialValues.value = { ...fallbackInitials };
|
initialValues.value = { ...fallbackInitials };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CoCbox.value.innerHTML = await getCoC()
|
||||||
|
CoCString.value = await getCoC();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const showCoC = ref(false);
|
||||||
|
const CoCbox = ref<HTMLElement>();
|
||||||
|
const CoCString = ref<string>();
|
||||||
|
|
||||||
|
async function onDialogToggle(state: boolean) {
|
||||||
|
showCoC.value = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
function enforceExternalLinks() {
|
||||||
|
if (!CoCbox.value) return;
|
||||||
|
|
||||||
|
const links = CoCbox.value.querySelectorAll("a");
|
||||||
|
links.forEach(a => {
|
||||||
|
a.setAttribute("target", "_blank");
|
||||||
|
a.setAttribute("rel", "noopener noreferrer");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => showCoC.value, async () => {
|
||||||
|
if (showCoC) {
|
||||||
|
await nextTick(); // wait for v-html to update
|
||||||
|
enforceExternalLinks();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -273,7 +308,8 @@ onMounted(() => {
|
|||||||
<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 h-min">Code of
|
<span>By checking this box, you accept the <Button variant="link" class="p-0 h-min"
|
||||||
|
@click.prevent.stop="showCoC = true">Code of
|
||||||
Conduct</Button>.</span>
|
Conduct</Button>.</span>
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -284,7 +320,19 @@ onMounted(() => {
|
|||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<div class="pt-2" v-if="!readOnly">
|
<div class="pt-2" v-if="!readOnly">
|
||||||
<Button type="submit" :onClick="() => console.log('hi')" :disabled="readOnly">Submit Application</Button>
|
<Button type="submit" :disabled="readOnly">Submit Application</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Dialog :open="showCoC" @update:open="onDialogToggle">
|
||||||
|
<DialogContent class="sm:max-w-fit">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Community Code of Conduct</DialogTitle>
|
||||||
|
<DialogDescription class="w-full max-h-[75vh] overflow-y-auto scrollbar-themed">
|
||||||
|
<div v-html="CoCString" ref="CoCbox" class="bookstack-container w-full"></div>
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
</Form>
|
</Form>
|
||||||
</template>
|
</template>
|
||||||
@@ -12,6 +12,7 @@ import DropdownMenuTrigger from '../ui/dropdown-menu/DropdownMenuTrigger.vue';
|
|||||||
import DropdownMenuContent from '../ui/dropdown-menu/DropdownMenuContent.vue';
|
import DropdownMenuContent from '../ui/dropdown-menu/DropdownMenuContent.vue';
|
||||||
import DropdownMenuItem from '../ui/dropdown-menu/DropdownMenuItem.vue';
|
import DropdownMenuItem from '../ui/dropdown-menu/DropdownMenuItem.vue';
|
||||||
import { Calendar } from 'lucide-vue-next';
|
import { Calendar } from 'lucide-vue-next';
|
||||||
|
import MemberCard from '../members/MemberCard.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ defineExpose({ forceReload })
|
|||||||
<MapPin :size="20"></MapPin> {{ activeEvent.location || "Unknown" }}
|
<MapPin :size="20"></MapPin> {{ activeEvent.location || "Unknown" }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-foreground/80 flex gap-3 items-center">
|
<div class="text-foreground/80 flex gap-3 items-center">
|
||||||
<User :size="20"></User> {{ activeEvent.creator_name || "Unknown User" }}
|
<User :size="20"></User> <MemberCard :member-id="activeEvent.creator_id"></MemberCard>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<!-- Description -->
|
<!-- Description -->
|
||||||
@@ -276,7 +277,9 @@ defineExpose({ forceReload })
|
|||||||
|
|
||||||
<div v-for="person in attendanceList" :key="person.member_id"
|
<div v-for="person in attendanceList" :key="person.member_id"
|
||||||
class="grid grid-cols-2 py-1 *:px-3 hover:bg-muted">
|
class="grid grid-cols-2 py-1 *:px-3 hover:bg-muted">
|
||||||
<p>{{ person.member_name }}</p>
|
<div>
|
||||||
|
<MemberCard :member-id="person.member_id"></MemberCard>
|
||||||
|
</div>
|
||||||
<p :class="statusColor(person.status)" class="text-right">
|
<p :class="statusColor(person.status)" class="text-right">
|
||||||
{{ displayStatus(person.status) }}
|
{{ displayStatus(person.status) }}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ const maxEndDate = computed(() => {
|
|||||||
<div class="flex flex-row-reverse gap-6 mx-auto w-full" :class="!adminMode ? 'max-w-5xl' : 'max-w-5xl'">
|
<div class="flex flex-row-reverse gap-6 mx-auto w-full" :class="!adminMode ? 'max-w-5xl' : 'max-w-5xl'">
|
||||||
<div v-if="!adminMode" class="flex-1 flex flex-col space-x-4 rounded-md border p-4">
|
<div v-if="!adminMode" class="flex-1 flex flex-col space-x-4 rounded-md border p-4">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Policy</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Policy</p>
|
||||||
<div ref="policyRef">
|
<div ref="policyRef" class="bookstack-container">
|
||||||
<!-- LOA policy gets loaded here -->
|
<!-- LOA policy gets loaded here -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
getLocalTimeZone,
|
getLocalTimeZone,
|
||||||
} from "@internationalized/date"
|
} from "@internationalized/date"
|
||||||
import { el } from "@fullcalendar/core/internal-common";
|
import { el } from "@fullcalendar/core/internal-common";
|
||||||
|
import MemberCard from "../members/MemberCard.vue";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
adminMode?: boolean
|
adminMode?: boolean
|
||||||
@@ -146,7 +147,7 @@ async function commitExtend() {
|
|||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow v-for="post in LOAList" :key="post.id" class="hover:bg-muted/50">
|
<TableRow v-for="post in LOAList" :key="post.id" class="hover:bg-muted/50">
|
||||||
<TableCell class="font-medium">
|
<TableCell class="font-medium">
|
||||||
{{ post.name }}
|
<MemberCard :member-id="post.member_id"></MemberCard>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{{ post.type_name }}</TableCell>
|
<TableCell>{{ post.type_name }}</TableCell>
|
||||||
<TableCell>{{ formatDate(post.start_date) }}</TableCell>
|
<TableCell>{{ formatDate(post.start_date) }}</TableCell>
|
||||||
|
|||||||
153
ui/src/components/members/MemberCard.vue
Normal file
153
ui/src/components/members/MemberCard.vue
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useMemberDirectory } from '@/stores/memberDirectory';
|
||||||
|
import { ref, onMounted, computed } from 'vue';
|
||||||
|
import { Member, type MemberLight } from '@shared/types/member'
|
||||||
|
import Popover from '../ui/popover/Popover.vue';
|
||||||
|
import PopoverTrigger from '../ui/popover/PopoverTrigger.vue';
|
||||||
|
import PopoverContent from '../ui/popover/PopoverContent.vue';
|
||||||
|
import { cn } from '@/lib/utils.js'
|
||||||
|
import { watch } from 'vue';
|
||||||
|
import { format } from 'path';
|
||||||
|
|
||||||
|
|
||||||
|
// Props
|
||||||
|
const props = defineProps({
|
||||||
|
memberId: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Local state
|
||||||
|
const memberLight = ref<MemberLight | null>(null);
|
||||||
|
const memberFull = ref<Member | null>(null)
|
||||||
|
const loadingFull = ref(false)
|
||||||
|
const membersStore = useMemberDirectory();
|
||||||
|
|
||||||
|
// Fetch the light member data on mount
|
||||||
|
onMounted(async () => {
|
||||||
|
memberLight.value = await membersStore.getLight(props.memberId);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadFull() {
|
||||||
|
if (memberFull.value || loadingFull.value) return
|
||||||
|
|
||||||
|
loadingFull.value = true
|
||||||
|
try {
|
||||||
|
memberFull.value = await membersStore.getFull(props.memberId)
|
||||||
|
} finally {
|
||||||
|
loadingFull.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.memberId, async (newId) => {
|
||||||
|
memberLight.value = await membersStore.getLight(newId);
|
||||||
|
memberFull.value = null;
|
||||||
|
loadingFull.value = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Compute display name (displayName fallback to username)
|
||||||
|
const displayName = computed(() => {
|
||||||
|
if (!memberLight.value) return props.memberId;
|
||||||
|
return memberLight.value.displayName || memberLight.value.username;
|
||||||
|
});
|
||||||
|
|
||||||
|
const DEFAULT_TEXT_COLOR = '#9ca3af' // muted gray for text
|
||||||
|
const DEFAULT_BG_COLOR = '#d1d5db22' // muted gray ~20% opacity
|
||||||
|
|
||||||
|
const textColor = computed(() => memberLight.value?.color || DEFAULT_TEXT_COLOR)
|
||||||
|
const bgColor = computed(() => (memberLight.value?.color ? `${memberLight.value.color}22` : DEFAULT_BG_COLOR))
|
||||||
|
|
||||||
|
const hasFullInfo = computed(() => {
|
||||||
|
if (!memberFull.value) return false
|
||||||
|
|
||||||
|
// check if any field has a value
|
||||||
|
const { rank, unit, status } = memberFull.value
|
||||||
|
return !!(rank || unit || status)
|
||||||
|
})
|
||||||
|
|
||||||
|
function formatDate(date: Date): string {
|
||||||
|
if (!date) return "";
|
||||||
|
date = typeof date === 'string' ? new Date(date) : date;
|
||||||
|
return date.toLocaleDateString("en-US", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Popover @update:open="open => open && loadFull()">
|
||||||
|
<PopoverTrigger @click.stop>
|
||||||
|
<p :class="cn(
|
||||||
|
'px-2 py-1 rounded font-medium inline-flex items-center cursor-pointer'
|
||||||
|
)" :style="{
|
||||||
|
color: textColor,
|
||||||
|
backgroundColor: bgColor
|
||||||
|
}">
|
||||||
|
{{ displayName }}
|
||||||
|
</p>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent class="w-72 p-0 overflow-hidden">
|
||||||
|
<!-- Loading -->
|
||||||
|
<div v-if="loadingFull" class="p-4 text-sm text-muted-foreground">
|
||||||
|
Loading profile…
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Profile -->
|
||||||
|
<div v-else-if="memberFull">
|
||||||
|
<!-- Header -->
|
||||||
|
<div class="px-4 py-3 relative" :style="{ backgroundColor: `${memberLight?.color}22` }">
|
||||||
|
<!-- Display name / username -->
|
||||||
|
<div class="text-lg font-semibold leading-tight" :style="{ color: memberLight?.color }">
|
||||||
|
{{ displayName }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="memberLight.displayName" class="text-xs text-muted-foreground">
|
||||||
|
{{ memberLight?.username }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Body -->
|
||||||
|
<div class="p-4 space-y-3 text-sm">
|
||||||
|
<!-- Full info -->
|
||||||
|
<template v-if="hasFullInfo">
|
||||||
|
<div v-if="memberFull.loa_until"
|
||||||
|
class=" rounded-md text-center bg-yellow-500/10 px-2 py-1 text-xs text-yellow-600">
|
||||||
|
On Leave of Absence until {{ formatDate(memberFull.loa_until) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="memberFull.rank" class="flex justify-between">
|
||||||
|
<span class="text-muted-foreground">Rank</span>
|
||||||
|
<span class="font-medium">{{ memberFull.rank }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="memberFull.unit" class="flex justify-between">
|
||||||
|
<span class="text-muted-foreground">Unit</span>
|
||||||
|
<span class="font-medium">{{ memberFull.unit }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="memberFull.status" class="flex justify-between">
|
||||||
|
<span class="text-muted-foreground">Status</span>
|
||||||
|
<span class="font-medium">{{ memberFull.status }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- No info fallback -->
|
||||||
|
<div v-else class="text-sm text-muted-foreground italic">
|
||||||
|
No user info
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Not found -->
|
||||||
|
<div v-else class="p-4 text-sm text-muted-foreground">
|
||||||
|
Member not found
|
||||||
|
</div>
|
||||||
|
</PopoverContent>
|
||||||
|
|
||||||
|
</Popover>
|
||||||
|
</template>
|
||||||
16
ui/src/components/ui/spinner/Spinner.vue
Normal file
16
ui/src/components/ui/spinner/Spinner.vue
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script setup>
|
||||||
|
import { Loader2Icon } from "lucide-vue-next";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
class: { type: null, required: false },
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Loader2Icon
|
||||||
|
role="status"
|
||||||
|
aria-label="Loading"
|
||||||
|
:class="cn('size-4 animate-spin', props.class)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
1
ui/src/components/ui/spinner/index.js
Normal file
1
ui/src/components/ui/spinner/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default as Spinner } from "./Spinner.vue";
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { getAllApplications, approveApplication, denyApplication } from '@/api/application';
|
import { getAllApplications, approveApplication, denyApplication } from '@/api/application';
|
||||||
import { ApplicationStatus } from '@shared/types/application'
|
import { ApplicationStatus } from '@shared/types/application'
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -15,6 +15,7 @@ import { onMounted, ref, watch } from 'vue';
|
|||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
||||||
import Application from './Application.vue';
|
import Application from './Application.vue';
|
||||||
|
import MemberCard from '@/components/members/MemberCard.vue';
|
||||||
|
|
||||||
const appList = ref([]);
|
const appList = ref([]);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -96,39 +97,52 @@ onMounted(async () => {
|
|||||||
<!-- application list -->
|
<!-- application list -->
|
||||||
<div :class="openPanel == false ? 'w-full' : 'w-2/5'" class="pr-9">
|
<div :class="openPanel == false ? 'w-full' : 'w-2/5'" class="pr-9">
|
||||||
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">Manage Applications</h1>
|
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">Manage Applications</h1>
|
||||||
<Table>
|
<div class="max-h-[80vh] overflow-hidden">
|
||||||
<TableHeader>
|
<Table class="w-full">
|
||||||
<TableRow>
|
<TableHeader>
|
||||||
<TableHead>User</TableHead>
|
<TableRow>
|
||||||
<TableHead>Date Submitted</TableHead>
|
<TableHead>User</TableHead>
|
||||||
<TableHead class="text-right">Status</TableHead>
|
<TableHead>Date Submitted</TableHead>
|
||||||
</TableRow>
|
<TableHead class="text-right">Status</TableHead>
|
||||||
</TableHeader>
|
</TableRow>
|
||||||
<TableBody class="overflow-y-auto scrollbar-themed">
|
</TableHeader>
|
||||||
<TableRow v-for="app in appList" :key="app.id" class="cursor-pointer"
|
</Table>
|
||||||
:onClick="() => { openApplication(app.id) }">
|
|
||||||
<TableCell class="font-medium">{{ app.member_name }}</TableCell>
|
<!-- Scrollable body container -->
|
||||||
<TableCell :title="formatExact(app.submitted_at)">
|
<div class="overflow-y-auto max-h-[70vh] scrollbar-themed">
|
||||||
{{ formatAgo(app.submitted_at) }}
|
<Table class="w-full">
|
||||||
</TableCell>
|
<TableBody>
|
||||||
<TableCell v-if="app.app_status === ApplicationStatus.Pending"
|
<TableRow v-for="app in appList" :key="app.id" class="cursor-pointer"
|
||||||
class="inline-flex items-end gap-2">
|
@click="openApplication(app.id)">
|
||||||
<Button variant="success" @click.stop="() => { handleApprove(app.id) }">
|
<TableCell class="font-medium">
|
||||||
<CheckIcon></CheckIcon>
|
<MemberCard :memberId="app.member_id"></MemberCard>
|
||||||
</Button>
|
</TableCell>
|
||||||
<Button variant="destructive" @click.stop="() => { handleDeny(app.id) }">
|
<TableCell :title="formatExact(app.submitted_at)">
|
||||||
<XIcon></XIcon>
|
{{ formatAgo(app.submitted_at) }}
|
||||||
</Button>
|
</TableCell>
|
||||||
</TableCell>
|
|
||||||
<TableCell class="text-right font-semibold" :class="[
|
<TableCell v-if="app.app_status === ApplicationStatus.Pending"
|
||||||
,
|
class="inline-flex items-end gap-2">
|
||||||
app.app_status === ApplicationStatus.Pending && 'text-yellow-500',
|
<Button variant="success" @click.stop="handleApprove(app.id)">
|
||||||
app.app_status === ApplicationStatus.Accepted && 'text-green-500',
|
<CheckIcon />
|
||||||
app.app_status === ApplicationStatus.Denied && 'text-destructive'
|
</Button>
|
||||||
]">{{ app.app_status }}</TableCell>
|
<Button variant="destructive" @click.stop="handleDeny(app.id)">
|
||||||
</TableRow>
|
<XIcon />
|
||||||
</TableBody>
|
</Button>
|
||||||
</Table>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="openPanel" class="pl-9 border-l w-3/5" :key="$route.params.id">
|
<div v-if="openPanel" class="pl-9 border-l w-3/5" :key="$route.params.id">
|
||||||
<div class="mb-5 flex justify-between">
|
<div class="mb-5 flex justify-between">
|
||||||
@@ -144,32 +158,4 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
/* 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>
|
|
||||||
97
ui/src/pages/MyProfile.vue
Normal file
97
ui/src/pages/MyProfile.vue
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from "vue";
|
||||||
|
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { memberSettings } from '@shared/types/member'
|
||||||
|
import { getMemberSettings, setMemberSettings } from "@/api/member";
|
||||||
|
import Spinner from "@/components/ui/spinner/Spinner.vue";
|
||||||
|
import { useMemberDirectory } from "@/stores/memberDirectory";
|
||||||
|
import { useUserStore } from "@/stores/user";
|
||||||
|
|
||||||
|
const saving = ref(false);
|
||||||
|
const loading = ref(true);
|
||||||
|
const showLoading = ref(false);
|
||||||
|
const form = ref<memberSettings>();
|
||||||
|
|
||||||
|
const memberDictionary = useMemberDirectory()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
function saveSettings() {
|
||||||
|
saving.value = true;
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
// Replace with your API save call
|
||||||
|
setMemberSettings(form.value);
|
||||||
|
saving.value = false;
|
||||||
|
console.log(userStore.user.id)
|
||||||
|
memberDictionary.invalidateMember(userStore.user.id)
|
||||||
|
}, 800);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// Start a brief timer before showing the spinner
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
showLoading.value = true;
|
||||||
|
}, 200); // 150–250ms is ideal
|
||||||
|
|
||||||
|
form.value = await getMemberSettings();
|
||||||
|
|
||||||
|
clearTimeout(timer);
|
||||||
|
loading.value = false;
|
||||||
|
showLoading.value = false; // ensure spinner hides if it was shown
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="mx-auto max-w-3xl w-full py-10 px-6 space-y-10">
|
||||||
|
<!-- Page Header -->
|
||||||
|
<div>
|
||||||
|
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">Profile Settings</h1>
|
||||||
|
<p class="text-muted-foreground mt-1">
|
||||||
|
Manage your account information and display preferences.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Account Info</CardTitle>
|
||||||
|
<CardDescription>Your identity across the platform.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<Transition name="fade" mode="out-in">
|
||||||
|
|
||||||
|
<CardContent class="space-y-6 min-h-40" v-if="!loading">
|
||||||
|
<!-- Display Name -->
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<Label for="displayName">Display Name</Label>
|
||||||
|
<Input id="displayName" v-model="form.displayName" placeholder="Your display name" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</CardContent>
|
||||||
|
<CardContent v-else class="min-h-40 space-y-6 flex items-center">
|
||||||
|
<Spinner v-if="showLoading" class="size-7 flex mx-auto -my-10"></Spinner>
|
||||||
|
</CardContent>
|
||||||
|
</Transition>
|
||||||
|
|
||||||
|
<CardFooter class="flex justify-end">
|
||||||
|
<Button @click="saveSettings" :disabled="saving">
|
||||||
|
{{ saving ? "Saving..." : "Save Changes" }}
|
||||||
|
</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.fade-enter-active,
|
||||||
|
.fade-leave-active {
|
||||||
|
transition: opacity 0.05s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-enter-from,
|
||||||
|
.fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -21,6 +21,7 @@ import SelectValue from '@/components/ui/select/SelectValue.vue';
|
|||||||
import SelectContent from '@/components/ui/select/SelectContent.vue';
|
import SelectContent from '@/components/ui/select/SelectContent.vue';
|
||||||
import SelectItem from '@/components/ui/select/SelectItem.vue';
|
import SelectItem from '@/components/ui/select/SelectItem.vue';
|
||||||
import Input from '@/components/ui/input/Input.vue';
|
import Input from '@/components/ui/input/Input.vue';
|
||||||
|
import MemberCard from '@/components/members/MemberCard.vue';
|
||||||
|
|
||||||
enum sidePanelState { view, create, closed };
|
enum sidePanelState { view, create, closed };
|
||||||
|
|
||||||
@@ -152,9 +153,13 @@ onMounted(async () => {
|
|||||||
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname :
|
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname :
|
||||||
report.course_name }}</TableCell>
|
report.course_name }}</TableCell>
|
||||||
<TableCell>{{ report.date.split('T')[0] }}</TableCell>
|
<TableCell>{{ report.date.split('T')[0] }}</TableCell>
|
||||||
<TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
<TableCell class="text-right">
|
||||||
|
<MemberCard v-if="report.created_by_name" :member-id="report.created_by"></MemberCard>
|
||||||
|
<span v-else>Unknown User</span>
|
||||||
|
</TableCell>
|
||||||
|
<!-- <TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
||||||
report.created_by_name
|
report.created_by_name
|
||||||
}}</TableCell>
|
}}</TableCell> -->
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
@@ -172,11 +177,14 @@ onMounted(async () => {
|
|||||||
<div class="flex flex-col mb-5 border rounded-lg bg-muted/70 p-2 py-3 px-4">
|
<div class="flex flex-col mb-5 border rounded-lg bg-muted/70 p-2 py-3 px-4">
|
||||||
<p class="scroll-m-20 text-xl font-semibold tracking-tight">{{ focusedTrainingReport.course_name }}
|
<p class="scroll-m-20 text-xl font-semibold tracking-tight">{{ focusedTrainingReport.course_name }}
|
||||||
</p>
|
</p>
|
||||||
<div class="flex gap-10">
|
<div class="flex gap-10 items-center">
|
||||||
<p class="text-muted-foreground">{{ focusedTrainingReport.event_date.split('T')[0] }}</p>
|
<p class="text-muted-foreground">{{ focusedTrainingReport.event_date.split('T')[0] }}</p>
|
||||||
<p class="">Created by {{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
<p class="flex gap-2 items-center">Created by:
|
||||||
|
<MemberCard v-if="focusedTrainingReport.created_by"
|
||||||
|
:member-id="focusedTrainingReport.created_by" />
|
||||||
|
<p v-else>{{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
||||||
focusedTrainingReport.created_by_name
|
focusedTrainingReport.created_by_name
|
||||||
}}
|
}}</p>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -191,7 +199,11 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
<div v-for="person in focusedTrainingTrainers"
|
<div v-for="person in focusedTrainingTrainers"
|
||||||
class="grid grid-cols-4 py-2 items-center border-b last:border-none">
|
class="grid grid-cols-4 py-2 items-center border-b last:border-none">
|
||||||
<p>{{ person.attendee_name }}</p>
|
<div>
|
||||||
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
|
class="justify-self-start"></MemberCard>
|
||||||
|
<p v-else>{{ person.attendee_name }}</p>
|
||||||
|
</div>
|
||||||
<p class="">{{ person.role.name }}</p>
|
<p class="">{{ person.role.name }}</p>
|
||||||
<p class="col-span-2 text-right px-2"
|
<p class="col-span-2 text-right px-2"
|
||||||
:class="person.remarks == '' ? 'text-muted-foreground' : ''">
|
:class="person.remarks == '' ? 'text-muted-foreground' : ''">
|
||||||
@@ -213,7 +225,11 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
<div v-for="person in focusedTrainingTrainees"
|
<div v-for="person in focusedTrainingTrainees"
|
||||||
class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
||||||
<p>{{ person.attendee_name }}</p>
|
<div>
|
||||||
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
|
class="justify-self-start"></MemberCard>
|
||||||
|
<p v-else>{{ person.attendee_name }}</p>
|
||||||
|
</div>
|
||||||
<Checkbox :disabled="!focusedTrainingReport.course.hasQual"
|
<Checkbox :disabled="!focusedTrainingReport.course.hasQual"
|
||||||
:model-value="person.passed_bookwork" class="pointer-events-none ml-5">
|
:model-value="person.passed_bookwork" class="pointer-events-none ml-5">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
@@ -242,7 +258,11 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
<div v-for="person in focusedNoShows"
|
<div v-for="person in focusedNoShows"
|
||||||
class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
||||||
<p>{{ person.attendee_name }}</p>
|
<div>
|
||||||
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
|
class="justify-self-start"></MemberCard>
|
||||||
|
<p v-else>{{ person.attendee_name }}</p>
|
||||||
|
</div>
|
||||||
<!-- <Checkbox :default-value="person.passed_bookwork ? true : false" class="pointer-events-none">
|
<!-- <Checkbox :default-value="person.passed_bookwork ? true : false" class="pointer-events-none">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<Checkbox :default-value="person.passed_qual ? true : false" class="pointer-events-none">
|
<Checkbox :default-value="person.passed_qual ? true : false" class="pointer-events-none">
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ const searchedMembers = computed(() => {
|
|||||||
Member
|
Member
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead>Rank</TableHead>
|
<TableHead>Rank</TableHead>
|
||||||
|
<TableHead>Unit</TableHead>
|
||||||
<TableHead>Status</TableHead>
|
<TableHead>Status</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
@@ -75,6 +76,7 @@ const searchedMembers = computed(() => {
|
|||||||
{{ member.member_name }}
|
{{ member.member_name }}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{{ member.rank }}</TableCell>
|
<TableCell>{{ member.rank }}</TableCell>
|
||||||
|
<TableCell>{{ member.unit }}</TableCell>
|
||||||
<TableCell>{{ member.status }}</TableCell>
|
<TableCell>{{ member.status }}</TableCell>
|
||||||
<TableCell><Badge v-if="member.on_loa">On LOA</Badge></TableCell>
|
<TableCell><Badge v-if="member.on_loa">On LOA</Badge></TableCell>
|
||||||
<TableCell @click.stop="" class="text-right">
|
<TableCell @click.stop="" class="text-right">
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const router = createRouter({
|
|||||||
{ 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: '/profile', component: () => import('@/pages/MyProfile.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 }, },
|
||||||
|
|||||||
140
ui/src/stores/memberDirectory.ts
Normal file
140
ui/src/stores/memberDirectory.ts
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
import { defineStore } from "pinia"
|
||||||
|
import type { MemberLight, Member } from "@shared/types/member"
|
||||||
|
import { getLightMembers, getFullMembers } from "@/api/member"
|
||||||
|
import { reactive, ref } from "vue"
|
||||||
|
import { resolve } from "path"
|
||||||
|
import { rejects } from "assert"
|
||||||
|
|
||||||
|
export const useMemberDirectory = defineStore('memberDirectory', () => {
|
||||||
|
const light = reactive<Record<number, MemberLight>>({});
|
||||||
|
const full = reactive<Record<number, Member>>({})
|
||||||
|
|
||||||
|
function getLight(id: number): Promise<MemberLight> {
|
||||||
|
if (light[id]) return Promise.resolve(light[id]);
|
||||||
|
|
||||||
|
if (!lightWaiters.has(id)) {
|
||||||
|
pendingLight.add(id);
|
||||||
|
lightWaiters.set(id, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleBatch();
|
||||||
|
|
||||||
|
return new Promise<MemberLight>((resolve, reject) => {
|
||||||
|
lightWaiters.get(id)!.push({ resolve, reject })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFull(id: number): Promise<Member> {
|
||||||
|
if (full[id]) return Promise.resolve(full[id])
|
||||||
|
|
||||||
|
if (!fullWaiters.has(id)) {
|
||||||
|
pendingFull.add(id)
|
||||||
|
fullWaiters.set(id, [])
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleBatch()
|
||||||
|
|
||||||
|
return new Promise<Member>((resolve, reject) => {
|
||||||
|
fullWaiters.get(id)!.push({ resolve, reject })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function invalidateMember(id: number) {
|
||||||
|
delete light[id]
|
||||||
|
delete full[id]
|
||||||
|
}
|
||||||
|
|
||||||
|
//batching system
|
||||||
|
const pendingLight = new Set<number>()
|
||||||
|
const pendingFull = new Set<number>()
|
||||||
|
|
||||||
|
// promises
|
||||||
|
const lightWaiters = new Map<number, Array<{ resolve: (m: MemberLight) => void; reject: (e: any) => void }>>()
|
||||||
|
const fullWaiters = new Map<number, Array<{ resolve: (m: Member) => void; reject: (e: any) => void }>>()
|
||||||
|
|
||||||
|
let batchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
|
function scheduleBatch() {
|
||||||
|
if (batchTimer) return
|
||||||
|
|
||||||
|
batchTimer = setTimeout(async () => {
|
||||||
|
batchTimer = null;
|
||||||
|
|
||||||
|
//Batch light
|
||||||
|
if (pendingLight.size > 0) {
|
||||||
|
const ids = Array.from(pendingLight);
|
||||||
|
pendingLight.clear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getLightMembers(ids);
|
||||||
|
for (const m of res) {
|
||||||
|
light[m.id] = m;
|
||||||
|
|
||||||
|
const waiters = lightWaiters.get(m.id);
|
||||||
|
if (waiters) {
|
||||||
|
for (const w of waiters) w.resolve(m)
|
||||||
|
lightWaiters.delete(m.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const id of ids) {
|
||||||
|
if (!light[id]) {
|
||||||
|
const waiters = lightWaiters.get(id);
|
||||||
|
if (waiters) {
|
||||||
|
for (const w of waiters) w.reject("Not found");
|
||||||
|
lightWaiters.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
for (const id of ids) {
|
||||||
|
const waiters = lightWaiters.get(id);
|
||||||
|
if (waiters) {
|
||||||
|
for (const w of waiters) w.reject(error);
|
||||||
|
lightWaiters.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//batch full
|
||||||
|
if (pendingFull.size > 0) {
|
||||||
|
const ids = Array.from(pendingFull);
|
||||||
|
pendingFull.clear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getFullMembers(ids);
|
||||||
|
for (const m of res) {
|
||||||
|
full[m.member_id] = m;
|
||||||
|
|
||||||
|
const waiters = fullWaiters.get(m.member_id);
|
||||||
|
if (waiters) {
|
||||||
|
for (const w of waiters) w.resolve(m)
|
||||||
|
fullWaiters.delete(m.member_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const id of ids) {
|
||||||
|
if (!light[id]) {
|
||||||
|
const waiters = fullWaiters.get(id);
|
||||||
|
if (waiters) {
|
||||||
|
for (const w of waiters) w.reject("Not found");
|
||||||
|
fullWaiters.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
for (const id of ids) {
|
||||||
|
const waiters = fullWaiters.get(id);
|
||||||
|
if (waiters) {
|
||||||
|
for (const w of waiters) w.reject(error);
|
||||||
|
fullWaiters.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return { light, full, getLight, getFull, invalidateMember }
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user