2.4 KiB
2.4 KiB
Project Plan: Admin Shift Branch Selection
Goal
Allow users with the manage-any-shifts permission (Admins) to select a specific Branch (or keep it company-wide) when creating or editing a Shift. HR users should continue to have the shift automatically assigned to their branch.
Context
When an Admin creates a Shift template, they might want that shift to only be available for a specific branch rather than the entire company. Currently, the backend forces branch_id = null (company-wide) for Admins. We need to allow them to explicitly pick a branch.
Task Breakdown
Phase 1: Backend Updates (ShiftController)
-
Pass Branches to Frontend:
- In
ShiftController@index, fetch all branches (Branch::whereIn('created_by', getCompanyAndUsersId())->get(['id', 'name'])) and pass them to the Inertia page (Inertia::render('shifts/index', ['branches' => $branches])) so they are available in the dropdown.
- In
-
Handle Branch Assignment in Store & Update:
- In
ShiftController@store, modify the logic for Admins:if (!Auth::user()->can('manage-any-shifts')) { $validated['branch_id'] = Auth::user()->branch_id ?? Auth::user()->employee->branch_id ?? null; } else { $validated['branch_id'] = $request->input('branch_id') ?: null; } - Do the same for
ShiftController@update. - Update
ShiftRequest(or the inline validation array) to acceptbranch_idasnullable|exists:branches,id.
- In
Phase 2: Frontend Updates (Shift Management UI)
- Update Shift Form Configuration:
- In
resources/js/pages/shifts/index.tsx(or wherever theCrudFormModalfor shifts is), extract thebranchesandpermissionsfromusePage().props. - Add a conditional field for
branch_idin theformConfigofCrudFormModal. - The field should be a
selecttype containing options mapped frombranches. - Ensure the field is ONLY shown if the user has the
manage-any-shiftspermission. - Include an empty option like "All Branches (Company-wide)".
- In
Phase 3: Verification Checklist
- Admin can see the Branch dropdown when creating a shift.
- Admin can create a shift assigned to a specific branch (DB
branch_idis set). - Admin can create a company-wide shift (DB
branch_idis null). - HR (without
manage-any-shifts) does NOT see the dropdown. - HR created shifts are still automatically tied to their branch.