FBLA25/src/lib/shared.svelte.ts
drake fa14fe0496
All checks were successful
ci / docker_image (push) Successful in 1m38s
ci / deploy (push) Successful in 18s
dev
2025-01-29 22:38:07 -06:00

53 lines
1.4 KiB
TypeScript

import { PERMISSIONS } from '$lib/consts';
import type { EmploymentType } from '$lib/types';
export let userState = $state({
perms: PERMISSIONS.VIEW,
username: null,
id: null,
companyId: null
});
export const userPerms = PERMISSIONS.VIEW | PERMISSIONS.APPLY_FOR_JOBS;
export const employerPerms = PERMISSIONS.SUBMIT_POSTINGS | PERMISSIONS.MANAGE_EMPLOYERS;
export const adminPerms =
PERMISSIONS.MANAGE_TAGS |
PERMISSIONS.MANAGE_POSTINGS |
PERMISSIONS.MANAGE_USERS |
PERMISSIONS.MANAGE_COMPANIES;
export function telFormatter(initial: string) {
const num = initial.replace(/\D/g, '');
initial =
(num.length > 0 ? '(' : '') +
num.substring(0, 3) +
(num.length > 3 ? ') ' + num.substring(3, 6) : '') +
(num.length > 6 ? '-' + num.substring(6, 10) : '');
return initial;
}
export const getCookieValue = (name: String) =>
document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '';
export function updateUserState() {
const JWT = getCookieValue('jwt');
if (JWT !== '') {
const state = JSON.parse(atob(JWT.split('.')[1]));
userState.perms = state.perms;
userState.username = state.username;
userState.id = state.id;
userState.companyId = state.companyId;
}
}
export function employmentTypeDisplayName(type: EmploymentType) {
switch (type) {
case 'full_time':
return 'Full Time';
case 'part_time':
return 'Part Time';
case 'internship':
return 'Internship';
}
}