41 lines
2.4 KiB
Markdown
41 lines
2.4 KiB
Markdown
# 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)
|
|
1. **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.
|
|
|
|
2. **Handle Branch Assignment in Store & Update:**
|
|
- In `ShiftController@store`, modify the logic for Admins:
|
|
```php
|
|
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 accept `branch_id` as `nullable|exists:branches,id`.
|
|
|
|
### Phase 2: Frontend Updates (Shift Management UI)
|
|
1. **Update Shift Form Configuration:**
|
|
- In `resources/js/pages/shifts/index.tsx` (or wherever the `CrudFormModal` for shifts is), extract the `branches` and `permissions` from `usePage().props`.
|
|
- Add a conditional field for `branch_id` in the `formConfig` of `CrudFormModal`.
|
|
- The field should be a `select` type containing options mapped from `branches`.
|
|
- Ensure the field is ONLY shown if the user has the `manage-any-shifts` permission.
|
|
- Include an empty option like "All Branches (Company-wide)".
|
|
|
|
### 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_id` is set).
|
|
- [ ] Admin can create a company-wide shift (DB `branch_id` is null).
|
|
- [ ] HR (without `manage-any-shifts`) does NOT see the dropdown.
|
|
- [ ] HR created shifts are still automatically tied to their branch.
|