Compare commits
32 Commits
db-resourc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 94fac645af | |||
| 1eef9145a4 | |||
| fd94a5f261 | |||
| 2a0d7c2ff2 | |||
| 8aaaea5ed0 | |||
| 45aa59d54a | |||
| cf8113000f | |||
| 90e7a925ec | |||
| 10fea0982f | |||
| cdabd66986 | |||
| fd99ec73b3 | |||
| bc51ca1fcf | |||
| 826943c1a3 | |||
| 8409d971c1 | |||
| 6e2edc0096 | |||
| 1dfdb6bd0e | |||
| 618c290318 | |||
| 7f98d52634 | |||
| a73431f622 | |||
| 4670b568a5 | |||
| 82c9681dfa | |||
| 34469ee5af | |||
| ca4bb9fe2d | |||
| a335ce862d | |||
| b99d6653f8 | |||
| a6002dadb5 | |||
| 7ac83b532b | |||
| 2ee769dfdb | |||
| b2209ef870 | |||
| ed9190b298 | |||
| 412001b1b4 | |||
| d0322dc62e |
@@ -155,21 +155,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
||||
|
||||
try {
|
||||
const app = await getApplicationByID(appID);
|
||||
const result = await approveApplication(appID);
|
||||
|
||||
//guard against failures
|
||||
if (result.affectedRows != 1) {
|
||||
throw new Error("Something went wrong approving the application");
|
||||
}
|
||||
await approveApplication(appID, approved_by);
|
||||
|
||||
//update user profile
|
||||
await setUserState(app.member_id, MemberState.Member);
|
||||
|
||||
await pool.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by])
|
||||
// let nextRank = await getRankByName('Recruit')
|
||||
// await insertMemberRank(app.member_id, nextRank.id);
|
||||
// //assign user to "pending basic"
|
||||
// await assignUserToStatus(app.member_id, 1);
|
||||
|
||||
res.sendStatus(200);
|
||||
} catch (err) {
|
||||
console.error('Approve failed:', err);
|
||||
@@ -178,12 +170,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
||||
});
|
||||
|
||||
// POST /application/deny/:id
|
||||
router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req, res) => {
|
||||
const appID = req.params.id;
|
||||
router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req: Request, res: Response) => {
|
||||
const appID = Number(req.params.id);
|
||||
const approver = Number(req.user.id);
|
||||
|
||||
try {
|
||||
const app = await getApplicationByID(appID);
|
||||
await denyApplication(appID);
|
||||
await denyApplication(appID, approver);
|
||||
await setUserState(app.member_id, MemberState.Denied);
|
||||
res.sendStatus(200);
|
||||
} catch (err) {
|
||||
|
||||
@@ -10,10 +10,14 @@ import { Role } from '@app/shared/types/roles';
|
||||
import pool from '../db';
|
||||
import { requireLogin } from '../middleware/auth';
|
||||
import { getUserRoles } from '../services/rolesService';
|
||||
import { getUserState } from '../services/memberService';
|
||||
import { getUserState, mapDiscordtoID } from '../services/memberService';
|
||||
import { MemberState } from '@app/shared/types/member';
|
||||
import { toDateTime } from '@app/shared/utils/time';
|
||||
const querystring = require('querystring');
|
||||
|
||||
function parseJwt(token) {
|
||||
return JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
||||
}
|
||||
|
||||
passport.use(new OpenIDConnectStrategy({
|
||||
issuer: process.env.AUTH_ISSUER,
|
||||
@@ -23,16 +27,17 @@ passport.use(new OpenIDConnectStrategy({
|
||||
clientID: process.env.AUTH_CLIENT_ID,
|
||||
clientSecret: process.env.AUTH_CLIENT_SECRET,
|
||||
callbackURL: process.env.AUTH_REDIRECT_URI,
|
||||
scope: ['openid', 'profile']
|
||||
scope: ['openid', 'profile', 'discord']
|
||||
}, async function verify(issuer, sub, profile, jwtClaims, accessToken, refreshToken, params, cb) {
|
||||
|
||||
// console.log('--- OIDC verify() called ---');
|
||||
// console.log('issuer:', issuer);
|
||||
// console.log('sub:', sub);
|
||||
// // console.log('profile:', JSON.stringify(profile, null, 2));
|
||||
// // console.log('discord:', discord);
|
||||
// console.log('profile:', profile);
|
||||
// console.log('id_token claims:', JSON.stringify(jwtClaims, null, 2));
|
||||
// console.log('preferred_username:', jwtClaims?.preferred_username);
|
||||
// console.log('jwt: ', parseJwt(jwtClaims));
|
||||
// console.log('params:', params);
|
||||
|
||||
|
||||
try {
|
||||
var con = await pool.getConnection();
|
||||
@@ -41,20 +46,37 @@ passport.use(new OpenIDConnectStrategy({
|
||||
|
||||
//lookup existing user
|
||||
const existing = await con.query(`SELECT id FROM members WHERE authentik_issuer = ? AND authentik_sub = ? LIMIT 1;`, [issuer, sub]);
|
||||
let memberId;
|
||||
let memberId: number;
|
||||
//if member exists
|
||||
if (existing.length > 0) {
|
||||
memberId = existing[0].id;
|
||||
} else {
|
||||
//otherwise: create account
|
||||
const username = sub.username;
|
||||
const jwt = parseJwt(jwtClaims);
|
||||
const discordID = jwt.discord.id as number;
|
||||
|
||||
const result = await con.query(
|
||||
`INSERT INTO members (name, authentik_sub, authentik_issuer) VALUES (?, ?, ?)`,
|
||||
[username, sub, issuer]
|
||||
)
|
||||
memberId = Number(result.insertId);
|
||||
//check if account is available to claim
|
||||
memberId = await mapDiscordtoID(discordID);
|
||||
|
||||
if (memberId === null) {
|
||||
// create new account
|
||||
const username = sub.username;
|
||||
const result = await con.query(
|
||||
`INSERT INTO members (name, authentik_sub, authentik_issuer) VALUES (?, ?, ?)`,
|
||||
[username, sub, issuer]
|
||||
)
|
||||
memberId = Number(result.insertId);
|
||||
} else {
|
||||
// claim existing account
|
||||
const result = await con.query(
|
||||
`UPDATE members SET authentik_sub = ?, authentik_issuer = ? WHERE id = ?;`,
|
||||
[sub, issuer, memberId]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
await con.query(`UPDATE members SET last_login = ? WHERE id = ?`, [toDateTime(new Date()), memberId])
|
||||
|
||||
await con.commit();
|
||||
return cb(null, { memberId });
|
||||
} catch (error) {
|
||||
@@ -116,11 +138,10 @@ passport.deserializeUser(function (user, cb) {
|
||||
var userData: { id: number, name: string, roles: Role[], state: MemberState };
|
||||
try {
|
||||
var con = await pool.getConnection();
|
||||
|
||||
let userResults = await con.query(`SELECT id, name FROM members WHERE id = ?;`, [memberID])
|
||||
userData = userResults[0];
|
||||
let userRoles = await getUserRoles(memberID);
|
||||
userData.roles = userRoles;
|
||||
userData.roles = userRoles || [];
|
||||
userData.state = await getUserState(memberID);
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
||||
@@ -66,9 +66,11 @@ router.get("/history", async (req: Request, res: Response) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/all', [requireRole("17th Administrator")], async (req, res) => {
|
||||
router.get('/all', [requireRole("17th Administrator")], async (req: Request, res: Response) => {
|
||||
try {
|
||||
const result = await getAllLOA();
|
||||
const page = Number(req.query.page) || undefined;
|
||||
const pageSize = Number(req.query.pageSize) || undefined;
|
||||
const result = await getAllLOA(page, pageSize);
|
||||
res.status(200).json(result)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -38,18 +38,11 @@ router.get('/me', [requireLogin], async (req, res) => {
|
||||
|
||||
try {
|
||||
const { id, name, state } = await getUserData(req.user.id);
|
||||
// const LOAData = await pool.query(
|
||||
// `SELECT *
|
||||
// FROM leave_of_absences
|
||||
// WHERE member_id = ?
|
||||
// AND deleted = 0
|
||||
// AND UTC_TIMESTAMP() BETWEEN start_date AND end_date;`, req.user.id);
|
||||
const LOAData = await getUserActiveLOA(req.user.id);
|
||||
|
||||
const roleData = await getUserRoles(req.user.id);
|
||||
|
||||
const userDataFull = { id, name, state, LOAData, roleData };
|
||||
console.log(userDataFull)
|
||||
res.status(200).json(userDataFull);
|
||||
} catch (error) {
|
||||
console.error('Error fetching user data:', error);
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function getApplicationByID(appID: number): Promise<ApplicationRow>
|
||||
return app[0];
|
||||
}
|
||||
|
||||
export async function getApplicationList(): Promise<ApplicationListRow[]> {
|
||||
export async function getApplicationList(page: number = 1, pageSize: number = 25): Promise<ApplicationListRow[]> {
|
||||
const sql = `SELECT
|
||||
member.name AS member_name,
|
||||
app.id,
|
||||
@@ -40,9 +40,11 @@ export async function getApplicationList(): Promise<ApplicationListRow[]> {
|
||||
app.app_status
|
||||
FROM applications AS app
|
||||
LEFT JOIN members AS member
|
||||
ON member.id = app.member_id;`
|
||||
ON member.id = app.member_id
|
||||
ORDER BY app.submitted_at DESC
|
||||
LIMIT ? OFFSET ?;`
|
||||
|
||||
const rows: ApplicationListRow[] = await pool.query(sql);
|
||||
const rows: ApplicationListRow[] = await pool.query(sql, [pageSize, page]);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@@ -59,30 +61,35 @@ export async function getAllMemberApplications(memberID: number): Promise<Applic
|
||||
}
|
||||
|
||||
|
||||
export async function approveApplication(id: number) {
|
||||
export async function approveApplication(id: number, approver: number) {
|
||||
const sql = `
|
||||
UPDATE applications
|
||||
SET approved_at = NOW()
|
||||
SET approved_at = NOW(), approved_by = ?
|
||||
WHERE id = ?
|
||||
AND approved_at IS NULL
|
||||
AND denied_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.execute(sql, id);
|
||||
return result;
|
||||
const result = await pool.execute(sql, [approver, id]);
|
||||
console.log(result);
|
||||
if (result.affectedRows == 1) {
|
||||
return
|
||||
} else {
|
||||
throw new Error(`"Something went wrong approving application with ID ${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function denyApplication(id: number) {
|
||||
export async function denyApplication(id: number, approver: number) {
|
||||
const sql = `
|
||||
UPDATE applications
|
||||
SET denied_at = NOW()
|
||||
SET denied_at = NOW(), approved_by = ?
|
||||
WHERE id = ?
|
||||
AND approved_at IS NULL
|
||||
AND denied_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.execute(sql, id);
|
||||
|
||||
const result = await pool.execute(sql, [approver, id]);
|
||||
console.log(result);
|
||||
if (result.affectedRows == 1) {
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { toDateTime } from "@app/shared/utils/time";
|
||||
import pool from "../db";
|
||||
import { LOARequest, LOAType } from '@app/shared/types/loa'
|
||||
import { PagedData } from '@app/shared/types/pagination'
|
||||
|
||||
export async function getLoaTypes(): Promise<LOAType[]> {
|
||||
return await pool.query('SELECT * FROM leave_of_absences_types;');
|
||||
}
|
||||
|
||||
export async function getAllLOA(page = 1, pageSize = 20): Promise<LOARequest[]> {
|
||||
export async function getAllLOA(page = 1, pageSize = 10): Promise<PagedData<LOARequest>> {
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
const sql = `
|
||||
@@ -26,9 +27,13 @@ export async function getAllLOA(page = 1, pageSize = 20): Promise<LOARequest[]>
|
||||
loa.start_date DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
`;
|
||||
let loaList: LOARequest[] = await pool.query(sql, [pageSize, offset]) as LOARequest[];
|
||||
|
||||
let res: LOARequest[] = await pool.query(sql, [pageSize, offset]) as LOARequest[];
|
||||
return res;
|
||||
let loaCount = Number((await pool.query(`SELECT COUNT(*) as count FROM leave_of_absences;`))[0].count);
|
||||
let pageCount = loaCount / pageSize;
|
||||
|
||||
let output: PagedData<LOARequest> = { data: loaList, pagination: { page: page, pageSize: pageSize, total: loaCount, totalPages: pageCount } }
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function getUserLOA(userId: number): Promise<LOARequest[]> {
|
||||
@@ -73,7 +78,8 @@ export async function createNewLOA(data: LOARequest) {
|
||||
export async function closeLOA(id: number, closer: number) {
|
||||
const sql = `UPDATE leave_of_absences
|
||||
SET closed = 1,
|
||||
closed_by = ?
|
||||
closed_by = ?,
|
||||
ended_at = NOW()
|
||||
WHERE leave_of_absences.id = ?`;
|
||||
let out = await pool.query(sql, [closer, id]);
|
||||
console.log(out);
|
||||
|
||||
@@ -15,9 +15,8 @@ export async function setUserState(userID: number, state: MemberState) {
|
||||
}
|
||||
|
||||
export async function getUserState(user: number): Promise<MemberState> {
|
||||
let out = await pool.query(`SELECT state FROM members WHERE id = ?`, [user]);
|
||||
console.log('hi')
|
||||
return (out[0].state as MemberState);
|
||||
let out = await pool.query(`SELECT state FROM members WHERE id = ?`, [user]);
|
||||
return (out[0].state as MemberState);
|
||||
}
|
||||
|
||||
export async function getMemberSettings(id: number): Promise<memberSettings> {
|
||||
@@ -54,4 +53,10 @@ 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;
|
||||
}
|
||||
|
||||
export async function mapDiscordtoID(id: number): Promise<number | null> {
|
||||
const sql = `SELECT id FROM members WHERE discord_id = ?;`
|
||||
let res = await pool.query(sql, [id]);
|
||||
return res.length > 0 ? res[0].id : null;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ export enum MemberState {
|
||||
export type Member = {
|
||||
member_id: number;
|
||||
member_name: string;
|
||||
displayName?: string;
|
||||
rank: string | null;
|
||||
rank_date: string | null;
|
||||
unit: string | null;
|
||||
|
||||
11
shared/types/pagination.ts
Normal file
11
shared/types/pagination.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface PagedData<T> {
|
||||
data: T[]
|
||||
pagination: pagination
|
||||
}
|
||||
|
||||
export interface pagination {
|
||||
page: number
|
||||
pageSize: number
|
||||
total: number
|
||||
totalPages: number
|
||||
}
|
||||
@@ -12,4 +12,4 @@ export function toDateTime(date: Date): string {
|
||||
const second = date.getSeconds().toString().padStart(2, "0");
|
||||
|
||||
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
<title>17th Ranger Battalion</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 15 KiB |
@@ -94,16 +94,18 @@ export async function approveApplication(id: Number) {
|
||||
const res = await fetch(`${addr}/application/approve/${id}`, { method: 'POST', credentials: 'include' })
|
||||
|
||||
if (!res.ok) {
|
||||
console.error("Something went wrong approving the application")
|
||||
throw new Error("Something went wrong approving the application");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
export async function denyApplication(id: Number) {
|
||||
const res = await fetch(`${addr}/application/deny/${id}`, { method: 'POST', credentials: 'include' })
|
||||
|
||||
if (!res.ok) {
|
||||
console.error("Something went wrong denying the application")
|
||||
throw new Error("Something went wrong denyting the application");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
export async function restartApplication() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { LOARequest, LOAType } from '@shared/types/loa'
|
||||
import { PagedData } from '@shared/types/pagination'
|
||||
// @ts-ignore
|
||||
const addr = import.meta.env.VITE_APIHOST;
|
||||
|
||||
@@ -58,8 +59,18 @@ export async function getMyLOA(): Promise<LOARequest | null> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getAllLOAs(): Promise<LOARequest[]> {
|
||||
return fetch(`${addr}/loa/all`, {
|
||||
export async function getAllLOAs(page?: number, pageSize?: number): Promise<PagedData<LOARequest>> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (page !== undefined) {
|
||||
params.set("page", page.toString());
|
||||
}
|
||||
|
||||
if (pageSize !== undefined) {
|
||||
params.set("pageSize", pageSize.toString());
|
||||
}
|
||||
|
||||
return fetch(`${addr}/loa/all?${params}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -174,7 +174,7 @@ watch(() => showCoC.value, async () => {
|
||||
<FormLabel>Have you ever served in the military?</FormLabel>
|
||||
<FormControl>
|
||||
<div class="flex items-center gap-2">
|
||||
<Checkbox :checked="value ?? false" @update:checked="handleChange" :disabled="readOnly" />
|
||||
<Checkbox :model-value="value" @update:model-value="handleChange" :disabled="readOnly" />
|
||||
<span>Yes (checked) / No (unchecked)</span>
|
||||
</div>
|
||||
</FormControl>
|
||||
|
||||
@@ -13,6 +13,7 @@ import DropdownMenuContent from '../ui/dropdown-menu/DropdownMenuContent.vue';
|
||||
import DropdownMenuItem from '../ui/dropdown-menu/DropdownMenuItem.vue';
|
||||
import { Calendar } from 'lucide-vue-next';
|
||||
import MemberCard from '../members/MemberCard.vue';
|
||||
import Spinner from '../ui/spinner/Spinner.vue';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
@@ -240,7 +241,8 @@ defineExpose({ forceReload })
|
||||
<MapPin :size="20"></MapPin> {{ activeEvent.location || "Unknown" }}
|
||||
</div>
|
||||
<div class="text-foreground/80 flex gap-3 items-center">
|
||||
<User :size="20"></User> <MemberCard :member-id="activeEvent.creator_id"></MemberCard>
|
||||
<User :size="20"></User>
|
||||
<MemberCard :member-id="activeEvent.creator_id"></MemberCard>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Description -->
|
||||
@@ -289,4 +291,13 @@ defineExpose({ forceReload })
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="flex justify-center h-full items-center">
|
||||
<button
|
||||
class="absolute top-4 right-4 inline-flex flex-none size-8 items-center justify-center rounded-md border hover:bg-muted/40 transition cursor-pointer z-50"
|
||||
aria-label="Close" @click="emit('close')">
|
||||
<X class="size-4" />
|
||||
</button>
|
||||
|
||||
<Spinner class="size-8"></Spinner>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,7 +2,8 @@
|
||||
import { Check, Search } from "lucide-vue-next"
|
||||
import { ComboboxAnchor, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxItemIndicator, ComboboxList } from "@/components/ui/combobox"
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { Member, getMembers } from "@/api/member";
|
||||
import { getMembers } from "@/api/member";
|
||||
import { Member } from "@shared/types/member";
|
||||
import Button from "@/components/ui/button/Button.vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
@@ -70,6 +71,8 @@ const { handleSubmit, values, resetForm } = useForm({
|
||||
validationSchema: toTypedSchema(loaSchema),
|
||||
})
|
||||
|
||||
const formSubmitted = ref(false);
|
||||
|
||||
const onSubmit = handleSubmit(async (values) => {
|
||||
console.log(values);
|
||||
const out: LOARequest = {
|
||||
@@ -85,6 +88,7 @@ const onSubmit = handleSubmit(async (values) => {
|
||||
await submitLOA(out);
|
||||
userStore.loadUser();
|
||||
}
|
||||
formSubmitted.value = true;
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -137,7 +141,7 @@ const maxEndDate = computed(() => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-1 flex flex-col gap-5">
|
||||
<form @submit="onSubmit" class="flex flex-col gap-2">
|
||||
<form v-if="!formSubmitted" @submit="onSubmit" class="flex flex-col gap-2">
|
||||
<div class="flex w-full gap-5">
|
||||
<VeeField v-slot="{ field, errors }" name="member_id">
|
||||
<Field>
|
||||
@@ -272,6 +276,24 @@ const maxEndDate = computed(() => {
|
||||
<Button type="submit">Submit</Button>
|
||||
</div>
|
||||
</form>
|
||||
<div v-else class="flex flex-col gap-4 py-8 text-left">
|
||||
<h2 class="text-xl font-semibold">
|
||||
LOA Request Submitted
|
||||
</h2>
|
||||
|
||||
<p class="max-w-md text-muted-foreground">
|
||||
Your Leave of Absence request has been submitted successfully.
|
||||
It will take effect on your selected start date.
|
||||
</p>
|
||||
|
||||
|
||||
<div class="flex gap-3 mt-4">
|
||||
<Button variant="secondary" @click="formSubmitted = false">
|
||||
Submit another request
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { Ellipsis } from "lucide-vue-next";
|
||||
import { ChevronDown, ChevronUp, Ellipsis, X } from "lucide-vue-next";
|
||||
import { cancelLOA, extendLOA, getAllLOAs, getMyLOAs } from "@/api/loa";
|
||||
import { onMounted, ref, computed } from "vue";
|
||||
import { LOARequest } from "@shared/types/loa";
|
||||
@@ -33,6 +33,15 @@ import {
|
||||
} from "@internationalized/date"
|
||||
import { el } from "@fullcalendar/core/internal-common";
|
||||
import MemberCard from "../members/MemberCard.vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationNext,
|
||||
PaginationPrevious,
|
||||
} from '@/components/ui/pagination'
|
||||
import { pagination } from "@shared/types/pagination";
|
||||
|
||||
const props = defineProps<{
|
||||
adminMode?: boolean
|
||||
@@ -46,7 +55,9 @@ onMounted(async () => {
|
||||
|
||||
async function loadLOAs() {
|
||||
if (props.adminMode) {
|
||||
LOAList.value = await getAllLOAs();
|
||||
let result = await getAllLOAs(pageNum.value, pageSize.value);
|
||||
LOAList.value = result.data;
|
||||
pageData.value = result.pagination;
|
||||
} else {
|
||||
LOAList.value = await getMyLOAs();
|
||||
}
|
||||
@@ -76,12 +87,6 @@ function loaStatus(loa: LOARequest): "Upcoming" | "Active" | "Overdue" | "Closed
|
||||
return "Overdue"; // fallback
|
||||
}
|
||||
|
||||
function sortByStartDate(loas: LOARequest[]): LOARequest[] {
|
||||
return [...loas].sort(
|
||||
(a, b) => new Date(b.start_date).getTime() - new Date(a.start_date).getTime()
|
||||
);
|
||||
}
|
||||
|
||||
async function cancelAndReload(id: number) {
|
||||
await cancelLOA(id, props.adminMode);
|
||||
await loadLOAs();
|
||||
@@ -104,6 +109,26 @@ async function commitExtend() {
|
||||
isExtending.value = false;
|
||||
await loadLOAs();
|
||||
}
|
||||
|
||||
const expanded = ref<number | null>(null);
|
||||
const hoverID = ref<number | null>(null);
|
||||
|
||||
const pageNum = ref<number>(1);
|
||||
const pageData = ref<pagination>();
|
||||
|
||||
const pageSize = ref<number>(15)
|
||||
const pageSizeOptions = [10, 15, 30]
|
||||
|
||||
function setPageSize(size: number) {
|
||||
pageSize.value = size
|
||||
pageNum.value = 1;
|
||||
loadLOAs();
|
||||
}
|
||||
|
||||
function setPage(pagenum: number) {
|
||||
pageNum.value = pagenum;
|
||||
loadLOAs();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -139,51 +164,121 @@ async function commitExtend() {
|
||||
<TableHead>Type</TableHead>
|
||||
<TableHead>Start</TableHead>
|
||||
<TableHead>End</TableHead>
|
||||
<TableHead class="w-[500px]">Reason</TableHead>
|
||||
<!-- <TableHead class="w-[500px]">Reason</TableHead> -->
|
||||
<TableHead>Posted on</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="post in LOAList" :key="post.id" class="hover:bg-muted/50">
|
||||
<TableCell class="font-medium">
|
||||
<MemberCard :member-id="post.member_id"></MemberCard>
|
||||
</TableCell>
|
||||
<TableCell>{{ post.type_name }}</TableCell>
|
||||
<TableCell>{{ formatDate(post.start_date) }}</TableCell>
|
||||
<TableCell>{{ post.extended_till ? formatDate(post.extended_till) : formatDate(post.end_date) }}
|
||||
</TableCell>
|
||||
<TableCell>{{ post.reason }}</TableCell>
|
||||
<TableCell>{{ formatDate(post.filed_date) }}</TableCell>
|
||||
<TableCell>
|
||||
<Badge v-if="loaStatus(post) === 'Upcoming'" class="bg-blue-400">Upcoming</Badge>
|
||||
<Badge v-else-if="loaStatus(post) === 'Active'" class="bg-green-500">Active</Badge>
|
||||
<Badge v-else-if="loaStatus(post) === 'Overdue'" class="bg-yellow-400">Overdue</Badge>
|
||||
<Badge v-else class="bg-gray-400">Ended</Badge>
|
||||
</TableCell>
|
||||
<TableCell @click.stop="" class="text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger class="cursor-pointer">
|
||||
<Ellipsis></Ellipsis>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem v-if="!post.closed && props.adminMode"
|
||||
@click="isExtending = true; targetLOA = post">
|
||||
Extend
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="!post.closed" :variant="'destructive'"
|
||||
@click="cancelAndReload(post.id)">End
|
||||
</DropdownMenuItem>
|
||||
<!-- Fallback: no actions available -->
|
||||
<p v-if="post.closed || (!props.adminMode && post.closed)" class="p-2 text-center text-sm">
|
||||
No actions
|
||||
</p>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<template v-for="post in LOAList" :key="post.id">
|
||||
<TableRow class="hover:bg-muted/50 cursor-pointer" @click="expanded = post.id"
|
||||
@mouseenter="hoverID = post.id" @mouseleave="hoverID = null" :class="{
|
||||
'border-b-0': expanded === post.id,
|
||||
'bg-muted/50': hoverID === post.id
|
||||
}">
|
||||
<TableCell class="font-medium">
|
||||
<MemberCard :member-id="post.member_id"></MemberCard>
|
||||
</TableCell>
|
||||
<TableCell>{{ post.type_name }}</TableCell>
|
||||
<TableCell>{{ formatDate(post.start_date) }}</TableCell>
|
||||
<TableCell>{{ post.extended_till ? formatDate(post.extended_till) :
|
||||
formatDate(post.end_date) }}
|
||||
</TableCell>
|
||||
<!-- <TableCell>{{ post.reason }}</TableCell> -->
|
||||
<TableCell>{{ formatDate(post.filed_date) }}</TableCell>
|
||||
<TableCell>
|
||||
<Badge v-if="loaStatus(post) === 'Upcoming'" class="bg-blue-400">Upcoming</Badge>
|
||||
<Badge v-else-if="loaStatus(post) === 'Active'" class="bg-green-500">Active</Badge>
|
||||
<Badge v-else-if="loaStatus(post) === 'Overdue'" class="bg-yellow-400">Overdue</Badge>
|
||||
<Badge v-else class="bg-gray-400">Ended</Badge>
|
||||
</TableCell>
|
||||
<TableCell @click.stop="" class="text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger class="cursor-pointer">
|
||||
<Button variant="ghost">
|
||||
<Ellipsis class="size-6"></Ellipsis>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem v-if="!post.closed && props.adminMode"
|
||||
@click="isExtending = true; targetLOA = post">
|
||||
Extend
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="!post.closed" :variant="'destructive'"
|
||||
@click="cancelAndReload(post.id)">{{ loaStatus(post) === 'Upcoming' ?
|
||||
'Cancel' :
|
||||
'End' }}
|
||||
</DropdownMenuItem>
|
||||
<!-- Fallback: no actions available -->
|
||||
<p v-if="post.closed || (!props.adminMode && post.closed)"
|
||||
class="p-2 text-center text-sm">
|
||||
No actions
|
||||
</p>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Button v-if="expanded === post.id" @click.stop="expanded = null" variant="ghost">
|
||||
<ChevronUp class="size-6" />
|
||||
</Button>
|
||||
<Button v-else @click.stop="expanded = post.id" variant="ghost">
|
||||
<ChevronDown class="size-6" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-if="expanded === post.id" @mouseenter="hoverID = post.id"
|
||||
@mouseleave="hoverID = null" :class="{ 'bg-muted/50 border-t-0': hoverID === post.id }">
|
||||
<TableCell :colspan="8" class="p-0">
|
||||
<div class="w-full p-3 mb-6 space-y-3">
|
||||
<div class="flex justify-between items-start gap-4">
|
||||
<div class="flex-1">
|
||||
<!-- Title -->
|
||||
<p class="text-md font-semibold text-foreground">
|
||||
Reason
|
||||
</p>
|
||||
|
||||
<!-- Content -->
|
||||
<p
|
||||
class="mt-1 text-md whitespace-pre-wrap leading-relaxed text-muted-foreground">
|
||||
{{ post.reason }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
</template>
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div class="mt-5 flex justify-between">
|
||||
<div></div>
|
||||
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
||||
:default-page="2" :page="pageNum" @update:page="setPage">
|
||||
<PaginationContent v-slot="{ items }">
|
||||
<PaginationPrevious />
|
||||
<template v-for="(item, index) in items" :key="index">
|
||||
<PaginationItem v-if="item.type === 'page'" :value="item.value"
|
||||
:is-active="item.value === page">
|
||||
{{ item.value }}
|
||||
</PaginationItem>
|
||||
</template>
|
||||
<PaginationEllipsis :index="4" />
|
||||
<PaginationNext />
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
<div class="flex items-center gap-3 text-sm">
|
||||
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
||||
|
||||
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
||||
class="px-2 py-1 rounded transition-colors" :class="{
|
||||
'bg-muted font-semibold': pageSize === size,
|
||||
'hover:bg-muted/50': pageSize !== size
|
||||
}">
|
||||
{{ size }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -8,6 +8,7 @@ import PopoverContent from '../ui/popover/PopoverContent.vue';
|
||||
import { cn } from '@/lib/utils.js'
|
||||
import { watch } from 'vue';
|
||||
import { format } from 'path';
|
||||
import Spinner from '../ui/spinner/Spinner.vue';
|
||||
|
||||
|
||||
// Props
|
||||
@@ -91,8 +92,8 @@ function formatDate(date: Date): string {
|
||||
</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 v-if="loadingFull" class="p-4 text-sm text-muted-foreground mx-auto flex justify-center my-5">
|
||||
<Spinner></Spinner>
|
||||
</div>
|
||||
|
||||
<!-- Profile -->
|
||||
|
||||
33
ui/src/components/ui/pagination/Pagination.vue
Normal file
33
ui/src/components/ui/pagination/Pagination.vue
Normal file
@@ -0,0 +1,33 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { PaginationRoot, useForwardPropsEmits } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const props = defineProps({
|
||||
page: { type: Number, required: false },
|
||||
defaultPage: { type: Number, required: false },
|
||||
itemsPerPage: { type: Number, required: true },
|
||||
total: { type: Number, required: false },
|
||||
siblingCount: { type: Number, required: false },
|
||||
disabled: { type: Boolean, required: false },
|
||||
showEdges: { type: Boolean, required: false },
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
const emits = defineEmits(["update:page"]);
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class");
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationRoot
|
||||
v-slot="slotProps"
|
||||
data-slot="pagination"
|
||||
v-bind="forwarded"
|
||||
:class="cn('mx-auto flex w-full justify-center', props.class)"
|
||||
>
|
||||
<slot v-bind="slotProps" />
|
||||
</PaginationRoot>
|
||||
</template>
|
||||
24
ui/src/components/ui/pagination/PaginationContent.vue
Normal file
24
ui/src/components/ui/pagination/PaginationContent.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { PaginationList } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationList
|
||||
v-slot="slotProps"
|
||||
data-slot="pagination-content"
|
||||
v-bind="delegatedProps"
|
||||
:class="cn('flex flex-row items-center gap-1', props.class)"
|
||||
>
|
||||
<slot v-bind="slotProps" />
|
||||
</PaginationList>
|
||||
</template>
|
||||
27
ui/src/components/ui/pagination/PaginationEllipsis.vue
Normal file
27
ui/src/components/ui/pagination/PaginationEllipsis.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { MoreHorizontal } from "lucide-vue-next";
|
||||
import { PaginationEllipsis } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationEllipsis
|
||||
data-slot="pagination-ellipsis"
|
||||
v-bind="delegatedProps"
|
||||
:class="cn('flex size-9 items-center justify-center', props.class)"
|
||||
>
|
||||
<slot>
|
||||
<MoreHorizontal class="size-4" />
|
||||
<span class="sr-only">More pages</span>
|
||||
</slot>
|
||||
</PaginationEllipsis>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationFirst.vue
Normal file
36
ui/src/components/ui/pagination/PaginationFirst.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronLeftIcon } from "lucide-vue-next";
|
||||
import { PaginationFirst, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationFirst
|
||||
data-slot="pagination-first"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<ChevronLeftIcon />
|
||||
<span class="hidden sm:block">First</span>
|
||||
</slot>
|
||||
</PaginationFirst>
|
||||
</template>
|
||||
35
ui/src/components/ui/pagination/PaginationItem.vue
Normal file
35
ui/src/components/ui/pagination/PaginationItem.vue
Normal file
@@ -0,0 +1,35 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { PaginationListItem } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
value: { type: Number, required: true },
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "icon" },
|
||||
class: { type: null, required: false },
|
||||
isActive: { type: Boolean, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size", "isActive");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationListItem
|
||||
data-slot="pagination-item"
|
||||
v-bind="delegatedProps"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({
|
||||
variant: isActive ? 'outline' : 'ghost',
|
||||
size,
|
||||
}),
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
>
|
||||
<slot />
|
||||
</PaginationListItem>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationLast.vue
Normal file
36
ui/src/components/ui/pagination/PaginationLast.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronRightIcon } from "lucide-vue-next";
|
||||
import { PaginationLast, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationLast
|
||||
data-slot="pagination-last"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<span class="hidden sm:block">Last</span>
|
||||
<ChevronRightIcon />
|
||||
</slot>
|
||||
</PaginationLast>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationNext.vue
Normal file
36
ui/src/components/ui/pagination/PaginationNext.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronRightIcon } from "lucide-vue-next";
|
||||
import { PaginationNext, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationNext
|
||||
data-slot="pagination-next"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<span class="hidden sm:block">Next</span>
|
||||
<ChevronRightIcon />
|
||||
</slot>
|
||||
</PaginationNext>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationPrevious.vue
Normal file
36
ui/src/components/ui/pagination/PaginationPrevious.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronLeftIcon } from "lucide-vue-next";
|
||||
import { PaginationPrev, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationPrev
|
||||
data-slot="pagination-previous"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<ChevronLeftIcon />
|
||||
<span class="hidden sm:block">Previous</span>
|
||||
</slot>
|
||||
</PaginationPrev>
|
||||
</template>
|
||||
8
ui/src/components/ui/pagination/index.js
Normal file
8
ui/src/components/ui/pagination/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export { default as Pagination } from "./Pagination.vue";
|
||||
export { default as PaginationContent } from "./PaginationContent.vue";
|
||||
export { default as PaginationEllipsis } from "./PaginationEllipsis.vue";
|
||||
export { default as PaginationFirst } from "./PaginationFirst.vue";
|
||||
export { default as PaginationItem } from "./PaginationItem.vue";
|
||||
export { default as PaginationLast } from "./PaginationLast.vue";
|
||||
export { default as PaginationNext } from "./PaginationNext.vue";
|
||||
export { default as PaginationPrevious } from "./PaginationPrevious.vue";
|
||||
@@ -8,6 +8,7 @@ import Button from '@/components/ui/button/Button.vue';
|
||||
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
||||
import Unauthorized from './Unauthorized.vue';
|
||||
import { ApplicationData, ApplicationFull, ApplicationStatus, CommentRow } from '@shared/types/application';
|
||||
import Spinner from '@/components/ui/spinner/Spinner.vue';
|
||||
|
||||
const appData = ref<ApplicationData>(null);
|
||||
const appID = ref<number | null>(null);
|
||||
@@ -105,12 +106,21 @@ async function postApp(appData) {
|
||||
}
|
||||
|
||||
async function handleApprove(id) {
|
||||
console.log("hi");
|
||||
await approveApplication(id);
|
||||
try {
|
||||
await approveApplication(id);
|
||||
loadData(await loadApplication(Number(route.params.id), true))
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeny(id) {
|
||||
await denyApplication(id);
|
||||
try {
|
||||
await denyApplication(id);
|
||||
loadData(await loadApplication(Number(route.params.id), true))
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -164,12 +174,15 @@ async function handleDeny(id) {
|
||||
</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" @post-internal="postCommentInternal" :admin-mode="finalMode === 'view-recruiter'">
|
||||
<ApplicationChat :messages="chatData" @post="postComment" @post-internal="postCommentInternal"
|
||||
:admin-mode="finalMode === 'view-recruiter'">
|
||||
</ApplicationChat>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- 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">
|
||||
<Spinner class="size-8"/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -217,7 +217,7 @@ onMounted(() => {
|
||||
<aside v-if="panelOpen"
|
||||
class="3xl:w-lg 2xl:w-md border-l bg-card text-foreground flex flex-col overflow-auto scrollbar-themed"
|
||||
:style="{ height: 'calc(100vh - 61px)', position: 'sticky', top: '64px' }">
|
||||
<ViewCalendarEvent ref="eventViewRef" @close="() => { router.push('/calendar'); }"
|
||||
<ViewCalendarEvent ref="eventViewRef" :key="currentEventID" @close="() => { router.push('/calendar'); }"
|
||||
@reload="loadEvents()" @edit="(val) => { dialogRef.openDialog(null, 'edit', val) }">
|
||||
</ViewCalendarEvent>
|
||||
</aside>
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
TableRow,
|
||||
} from '@/components/ui/table'
|
||||
import Button from '@/components/ui/button/Button.vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { CheckIcon, XIcon } from 'lucide-vue-next';
|
||||
import Application from './Application.vue';
|
||||
@@ -52,36 +52,26 @@ function formatExact(iso) {
|
||||
return isNaN(d) ? '' : exactFmt.format(d)
|
||||
}
|
||||
|
||||
async function handleApprove(id) {
|
||||
await approveApplication(id);
|
||||
appList.value = await getAllApplications();
|
||||
}
|
||||
|
||||
async function handleDeny(id) {
|
||||
await denyApplication(id);
|
||||
appList.value = await getAllApplications();
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
function openApplication(id) {
|
||||
if (!id) return;
|
||||
router.push(`/administration/applications/${id}`)
|
||||
openPanel.value = true;
|
||||
}
|
||||
|
||||
function closeApplication() {
|
||||
router.push('/administration/applications')
|
||||
openPanel.value = false;
|
||||
}
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
watch(() => route.params.id, (newId) => {
|
||||
if (newId === undefined) {
|
||||
openPanel.value = false;
|
||||
}
|
||||
})
|
||||
|
||||
const openPanel = ref(false);
|
||||
// const openPanel = ref(false);
|
||||
const openPanel = computed(() => route.params.id !== undefined)
|
||||
|
||||
|
||||
onMounted(async () => {
|
||||
appList.value = await getAllApplications();
|
||||
@@ -102,7 +92,7 @@ onMounted(async () => {
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>User</TableHead>
|
||||
<TableHead>Date Submitted</TableHead>
|
||||
<TableHead class="text-right">Date Submitted</TableHead>
|
||||
<TableHead class="text-right">Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -117,20 +107,10 @@ onMounted(async () => {
|
||||
<TableCell class="font-medium">
|
||||
<MemberCard :memberId="app.member_id"></MemberCard>
|
||||
</TableCell>
|
||||
<TableCell :title="formatExact(app.submitted_at)">
|
||||
<TableCell class="text-right" :title="formatExact(app.submitted_at)">
|
||||
{{ formatAgo(app.submitted_at) }}
|
||||
</TableCell>
|
||||
|
||||
<TableCell v-if="app.app_status === ApplicationStatus.Pending"
|
||||
class="inline-flex items-end gap-2">
|
||||
<Button variant="success" @click.stop="handleApprove(app.id)">
|
||||
<CheckIcon />
|
||||
</Button>
|
||||
<Button variant="destructive" @click.stop="handleDeny(app.id)">
|
||||
<XIcon />
|
||||
</Button>
|
||||
</TableCell>
|
||||
|
||||
<TableCell class="text-right font-semibold" :class="[
|
||||
app.app_status === ApplicationStatus.Pending && 'text-yellow-500',
|
||||
app.app_status === ApplicationStatus.Accepted && 'text-green-500',
|
||||
|
||||
@@ -30,10 +30,12 @@ const showLOADialog = ref(false);
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<div class="max-w-5xl mx-auto pt-10">
|
||||
<div class="flex justify-end mb-4">
|
||||
<Button @click="showLOADialog = true">Post LOA</Button>
|
||||
<div class="flex justify-between mb-4">
|
||||
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Log</h1>
|
||||
<div>
|
||||
<Button @click="showLOADialog = true">Post LOA</Button>
|
||||
</div>
|
||||
</div>
|
||||
<h1>LOA Log</h1>
|
||||
<LoaList :admin-mode="true"></LoaList>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,6 +22,7 @@ import SelectContent from '@/components/ui/select/SelectContent.vue';
|
||||
import SelectItem from '@/components/ui/select/SelectItem.vue';
|
||||
import Input from '@/components/ui/input/Input.vue';
|
||||
import MemberCard from '@/components/members/MemberCard.vue';
|
||||
import Spinner from '@/components/ui/spinner/Spinner.vue';
|
||||
|
||||
enum sidePanelState { view, create, closed };
|
||||
|
||||
@@ -42,6 +43,7 @@ watch(() => route.params.id, async (newID) => {
|
||||
focusedTrainingReport.value = null;
|
||||
return;
|
||||
}
|
||||
TRLoaded.value = false;
|
||||
viewTrainingReport(Number(route.params.id));
|
||||
})
|
||||
|
||||
@@ -60,6 +62,7 @@ const focusedTrainingTrainers = computed<CourseAttendee[] | null>(() => {
|
||||
})
|
||||
async function viewTrainingReport(id: number) {
|
||||
focusedTrainingReport.value = await getTrainingReport(id);
|
||||
TRLoaded.value = true;
|
||||
}
|
||||
|
||||
async function closeTrainingReport() {
|
||||
@@ -93,6 +96,8 @@ onMounted(async () => {
|
||||
viewTrainingReport(Number(route.params.id))
|
||||
loaded.value = true;
|
||||
})
|
||||
|
||||
const TRLoaded = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -173,7 +178,7 @@ onMounted(async () => {
|
||||
<X></X>
|
||||
</button>
|
||||
</div>
|
||||
<div class="max-h-[70vh] overflow-auto scrollbar-themed my-5">
|
||||
<div v-if="TRLoaded" class="max-h-[70vh] overflow-auto scrollbar-themed my-5">
|
||||
<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>
|
||||
@@ -184,7 +189,7 @@ onMounted(async () => {
|
||||
:member-id="focusedTrainingReport.created_by" />
|
||||
<p v-else>{{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
||||
focusedTrainingReport.created_by_name
|
||||
}}</p>
|
||||
}}</p>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -284,6 +289,9 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="flex w-full items-center justify-center h-[80%]">
|
||||
<Spinner class="size-8"></Spinner>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="sidePanel == sidePanelState.create" class="pl-7 border-l w-3/5 max-w-5xl">
|
||||
<div class="flex justify-between my-3">
|
||||
|
||||
Reference in New Issue
Block a user