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
11 changes: 7 additions & 4 deletions app-backend/src/controllers/shift.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Branch from '../models/Branch.js';
import Guard from '../models/Guard.js';
import Availability from '../models/Availability.js';
import ShiftAttendance from '../models/ShiftAttendance.js';

Check failure on line 6 in app-backend/src/controllers/shift.controller.js

View workflow job for this annotation

GitHub Actions / lint

'ShiftAttendance' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 6 in app-backend/src/controllers/shift.controller.js

View workflow job for this annotation

GitHub Actions / lint

'ShiftAttendance' is defined but never used. Allowed unused vars must match /^_/u

import { ACTIONS } from "../middleware/logger.js";

Expand Down Expand Up @@ -347,7 +347,7 @@
}

const updates = {};
const { title, date, startTime, endTime, payRate, urgency, field, location, description, requirements } = req.body;
const { title, date, startTime, endTime, payRate, urgency, field, location, description, requirements, status } = req.body;

if (title !== undefined) {
if (typeof title !== 'string' || title.trim().length < 3) {
Expand Down Expand Up @@ -433,11 +433,11 @@
updates.location = loc;
}
if (status !== undefined) {
const allowedStatuses = ['draft', 'open'];
const allowedStatuses = ['draft', 'open', 'applied', 'assigned', 'completed'];

if (!allowedStatuses.includes(status)) {
return res.status(400).json({
message: 'Invalid status. Allowed: draft, open'
message: 'Invalid status. Allowed: draft, open, applied, assigned, completed'
});
}

Expand All @@ -451,7 +451,10 @@
// allowed transitions
const allowedTransitions = {
draft: ['open'],
open: ['draft'],
open: ['draft', 'applied', 'assigned'],
applied: ['open', 'assigned'],
assigned: ['completed', 'open'],
completed: [],
};

if (!allowedTransitions[current]?.includes(status)) {
Expand Down
19 changes: 9 additions & 10 deletions app-frontend/employer-panel/src/pages/ManageShift.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const statusDisplayMap = {
open: 'Open',
};

// Map display status back to backend status
const displayToBackendStatusMap = {
'Completed': 'completed',
'In Progress': 'assigned',
'Pending': 'applied',
'Open': 'open',
};

const Filter = Object.freeze({
All: 'All',
Completed: 'Completed',
Expand Down Expand Up @@ -63,7 +71,6 @@ const ManageShift = () => {
const [saving, setSaving] = useState(false);
const [feedback, setFeedback] = useState('');
const [formErrors, setFormErrors] = useState({});
const [optimisticSnapshot, setOptimisticSnapshot] = useState(null);
const [activeTab, setActiveTab] = useState(TABS.DETAILS);
const [applicantAction, setApplicantAction] = useState({});
const itemsPerPage = 9;
Expand Down Expand Up @@ -316,12 +323,8 @@ const ManageShift = () => {
...(detailForm.field?.trim() ? { field: detailForm.field.trim() } : {}),
urgency: detailForm.urgency,
...(hasLocation ? { location: cleanedLocation } : {}),
status: displayToBackendStatusMap[detailForm.status] || detailForm.status,
};
setOptimisticSnapshot({ shifts, selectedShift });
const optimistic = { ...selectedShift, ...payload, status: detailForm.status };
setShifts((prev) =>
prev.map((s) => (s.id === selectedShift.id ? { ...s, ...optimistic } : s))
);
const { data } = await http.patch(`/shifts/${selectedShift.id}`, payload);
const updated = normalizeShift(data.shift || { ...selectedShift, ...payload });
const updatedWithUiStatus = { ...updated, status: detailForm.status };
Expand All @@ -348,10 +351,6 @@ const ManageShift = () => {
} catch (err) {
const message = err?.response?.data?.message || 'Failed to update shift';
setFeedback(message);
if (optimisticSnapshot) {
setShifts(optimisticSnapshot.shifts);
setSelectedShift(optimisticSnapshot.selectedShift);
}
} finally {
setSaving(false);
}
Expand Down
Loading