Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ include_external_packages = True
name = Modules may reach each other ONLY through contracts.py
type = forbidden
source_modules =
modules.leave_elm
modules.placement
modules.directory
modules.accesscontrol
forbidden_modules =
modules.leave_elm.models
modules.leave_elm.services
modules.leave_elm.selectors
modules.leave_elm.api
modules.leave_elm.domain
modules.placement.models
modules.placement.services
modules.placement.selectors
Expand All @@ -38,6 +44,7 @@ type = forbidden
source_modules =
# Every module's domain, not just the first one written.
modules.placement.domain
modules.leave_elm.domain
forbidden_modules =
django
rest_framework
Expand Down Expand Up @@ -66,3 +73,13 @@ layers =
modules.placement.selectors
modules.placement.models
modules.placement.domain

[importlinter:contract:elm-layers]
name = Layering inside ELM
type = layers
layers =
modules.leave_elm.api
modules.leave_elm.services
modules.leave_elm.selectors
modules.leave_elm.models
modules.leave_elm.domain
29 changes: 29 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@mantine/core": "7.13.4",
"@mantine/dates": "7.13.4",
"@mantine/form": "7.13.4",
"@mantine/hooks": "7.13.4",
"@mantine/notifications": "7.13.4",
"@tanstack/react-query": "^5.59.0",
Expand Down
5 changes: 5 additions & 0 deletions client/src/app/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface ModuleManifest {
}

export const MODULE_REGISTRY: Record<string, ModuleManifest> = {
leave_elm: {
code: "leave_elm",
basePath: "/leave",
load: () => import("../modules/leave_elm/routes"),
},
placement_cell: {
code: "placement_cell",
basePath: "/placement",
Expand Down
121 changes: 121 additions & 0 deletions client/src/modules/leave_elm/api/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { useQuery, useMutation } from '@tanstack/react-query';
import { http } from '../../../lib/http';
import type { LeaveRequest } from './types';

const BASE = '/leave';

export function useMyLeave() {
return useQuery({
queryKey: ['leave', 'mine'],
queryFn: () => http.get(`${BASE}/mine`),
});
}

export function useApplyLeave(_data: Partial<LeaveRequest>) {
return useMutation({
mutationFn: (d: LeaveRequest) => http.post(`${BASE}/apply`, d),
});
}

export function useLeaveDetails(id: number) {
return useQuery({
queryKey: ['leave', 'detail', id],
queryFn: () => http.get(`${BASE}/${id}`),
enabled: !!id,
});
}

export function useWithdrawLeave(id: number) {
return useMutation({
mutationFn: (d: LeaveRequest) => http.post(`${BASE}/${id}/withdraw`, d),
});
}

export function useCancelLeave(id: number) {
return useMutation({
mutationFn: () => http.post(`${BASE}/${id}/cancel`),
});
}

export function useExtendLeave(id: number) {
return useMutation({
mutationFn: (d: { additional_days: number }) =>
http.post(`${BASE}/${id}/extend`, d),
});
}

export function useResumption(id: number) {
return useMutation({
mutationFn: (d: { actual_date: string }) =>
http.post(`${BASE}/${id}/resumption`, d),
});
}

export function useLeaveBalances() {
return useQuery({
queryKey: ['leave', 'balances'],
queryFn: () => http.get(`${BASE}/balances`),
});
}

export function useLeaveHistory() {
return useQuery({
queryKey: ['leave', 'history'],
queryFn: () => http.get(`${BASE}/history`),
});
}

export function useLeaveQueue(userId: number) {
return useQuery({
queryKey: ['leave', 'queue', userId],
queryFn: () => http.get(`${BASE}/queue`),
});
}

export function useSubstituteAccept(id: number) {
return useMutation({
mutationFn: () => http.post(`${BASE}/${id}/substitute/accept`),
});
}

export function useSubstituteDecline(id: number) {
return useMutation({
mutationFn: (d: { new_substitute_user_id?: number }) =>
http.post(`${BASE}/${id}/substitute/decline`, d),
});
}

export function useReviewLeave(id: number) {
return useMutation({
mutationFn: (d: { decision: string }) =>
http.post(`${BASE}/${id}/review`, d),
});
}

export function usePolicy() {
return useQuery({
queryKey: ['leave', 'policy'],
queryFn: () => http.get(`${BASE}/policy`),
});
}

export function useCalendar() {
return useQuery({
queryKey: ['leave', 'calendar'],
queryFn: () => http.get(`${BASE}/calendar`),
});
}

export function useNotifications(userId: number) {
return useQuery({
queryKey: ['leave', 'notifications', userId],
queryFn: () => http.get(`${BASE}/notifications`),
});
}

export function useOfflineRecord() {
return useMutation({
mutationFn: (d: { category: string; start_date: string; end_date: string; reference_number?: string; evidence?: string }) =>
http.post(`${BASE}/offline-record`, d),
});
}
41 changes: 41 additions & 0 deletions client/src/modules/leave_elm/api/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { LeaveApplication } from '../models';

export interface LeaveRequest {
category: string;
start_date: string;
end_date: string;
purpose?: string;
substitute_user_id?: number;
}

export interface LeaveResponse extends LeaveApplication {}

export type LeaveCategory = 'CL' | 'RH' | 'SCL' | 'EL' | 'COL' | 'VL';

export interface Policy {
CL_DAYS: number;
RH_DAYS: number;
SCL_MAX_DAYS: number;
EL_DAYS: number;
COL_DAYS: number;
VL_DAYS: number;
VL_TO_EL_RATIO: number;
}

export interface Calendar {
year: number;
holidays: Date[];
restricted_holidays: Date[];
is_effective: boolean;
}

export interface Notification {
id: number;
task_type: string;
assigned_to_user_id: number;
status: string;
reminder_threshold_seconds: number;
escalation_threshold_seconds: number;
last_reminder_sent_at?: string;
last_escalation_sent_at?: string;
}
80 changes: 80 additions & 0 deletions client/src/modules/leave_elm/json-editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useState } from 'react';
import { Group, Stack, Text, Button, ActionIcon, SimpleGrid, TextInput } from '@mantine/core';
import { RxTrash as Trash, RxPencil2 as Edit } from 'react-icons/rx';

export function useJsonEditor(value: any, onChange: (value: any) => void) {
const [editMode, setEditMode] = useState(false);
const [items, setItems] = useState(() => {
if (!value || typeof value !== 'object') return [];
return Object.entries(value).map(([k, v]) => ({ key: k, value: v }));
});

const addField = () => {
setItems([...items, { key: '', value: '' }]);
};

void addField;

const updateField = (index: number, field: 'key' | 'value', val: string) => {
const newItems = [...items];
if (field === 'key') newItems[index]!.key = val;
else newItems[index]!.value = val;
setItems(newItems);
};

const removeField = (index: number) => {
setItems(items.filter((_, i) => i !== index));
};

const handleSave = () => {
const newData: any = {};
items.forEach(({ key, value }) => {
if (key) newData[key] = value;
});
onChange(newData);
setEditMode(false);
};

return (
<Stack gap="sm">
{!editMode ? (
<Group justify="space-between" wrap="nowrap">
<Text fw={500}>Policy Data</Text>
<ActionIcon variant="light" onClick={() => setEditMode(true)}>
<Edit size={18} />
</ActionIcon>
</Group>
) : (
<>
<SimpleGrid cols={{ base: 1, md: 2 }} spacing="xs">
{items.map((item, idx) => (
<Stack key={idx} gap="xs">
<TextInput
label="Key"
value={item.key}
onChange={(e) => updateField(idx, 'key', e.target.value)}
placeholder="Key"
/>
<TextInput
label="Value"
value={String(item.value)}
onChange={(e) => updateField(idx, 'value', e.target.value)}
placeholder="Value"
/>
{items.length > 2 && (
<ActionIcon variant="light" color="red" onClick={() => removeField(idx)}>
<Trash size={16} />
</ActionIcon>
)}
</Stack>
))}
</SimpleGrid>
<Group justify="space-between" mt="md">
<Button variant="outline" onClick={() => setEditMode(false)}>Cancel</Button>
<Button onClick={handleSave}>Save Changes</Button>
</Group>
</>
)}
</Stack>
);
}
34 changes: 34 additions & 0 deletions client/src/modules/leave_elm/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export interface LeaveApplication {
id?: number;
category: string;
start_date: string;
end_date: string;
purpose?: string;
station_leave_required?: boolean;
substitute_user_id?: number;
status?: string;
final_decision_type?: string;
final_decision_date?: string | null;
created_at?: string;
}

export interface LeaveBalance {
effective_date: string;
cl_balance: number;
rh_balance: number;
scl_balance: number;
el_balance: number;
col_balance: number;
vl_balance: number;
}

export interface WorkflowTask {
id?: number;
task_type: string;
assigned_to_user_id?: number;
status?: string;
reminder_threshold_seconds?: number;
escalation_threshold_seconds?: number;
last_reminder_sent_at?: string | null;
last_escalation_sent_at?: string | null;
}
Loading